forked from MaterialesProgramacion/ProblemasProgramacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analizarConvexos.c
105 lines (100 loc) · 1.67 KB
/
analizarConvexos.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* @authors Equipo docente programacion grado de ingenieria
* @university UAL
* @date 2019-02-06
* */
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <math.h>
int main(){
char c;
float e1x,e1y,ex,ey,eantx,eanty;
float x1,y1,x,y,xant,yant;
float z;
int pos,neg;
int n,i;
do{ system("cls");
printf("CONCAVIDAD/CONVEXIDAD POLIGONO\n");
printf("==============================\n\n");
do{ printf("Num. de vertices: ");
scanf(" %d",&n);
}while(n<3);
i=1;
pos=0;
neg=0;
printf("Coordenadas vertice %d:\n",i);
printf("\tx: ");
scanf(" %f",&x1);
printf("\ty: ");
scanf(" %f",&y1);
i=2;
printf("Coordenadas vertice %d:\n",i);
printf("\tx: ");
scanf(" %f",&xant);
printf("\ty: ");
scanf(" %f",&yant);
e1x=xant-x1;
e1y=yant-y1;
eantx=e1x;
eanty=e1y;
i=3;
while(i<=n){
printf("Coordenadas vertice %d:\n",i);
printf("\tx: ");
scanf(" %f",&x);
printf("\ty: ");
scanf(" %f",&y);
ex=x-xant;
ey=y-yant;
z=eantx*ey-eanty*ex;
if(z>0){
pos++;
}else{
if(z<0){
neg++;
}
}
xant=x;
yant=y;
eantx=ex;
eanty=ey;
++i;
}
ex=x1-xant;
ey=y1-yant;
z=eantx*ey-eanty*ex;
if(z>0){
pos++;
}else{
if(z<0){
neg++;
}
}
z=ex*e1y-ey*e1x;
if(z>0){
pos++;
}else{
if(z<0){
neg++;
}
}
if(pos){
if(neg){
printf("\nPoligono concavo");
}else{
printf("\nPoligono convexo");
}
}else{
if(neg){
printf("\nPoligono convexo");
}else{
printf("\nPoligono degenerado en una linea");
}
}
printf("\n\nDesea efectuar una nueva operacion (s/n)? ");
c=toupper(getch());
}while (c!='N');
return 0;
}