-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolygon.cpp
More file actions
78 lines (60 loc) · 2.19 KB
/
polygon.cpp
File metadata and controls
78 lines (60 loc) · 2.19 KB
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
/* Polygon :
* Takes input points from inpoints.txt ( clokwise direction )
* and calculates if the points form a polygon or not
* Author:Mahendra Chouhan(14CS60R12)
* */
#include <iostream>
#include "src/Point3D.h"
#include "src/graphics.h"
using namespace std;
int main(int argc,char *argv[])
{
PointList2D list;
ifstream in("inpoints.txt");
ofstream out("polygon.svg");
out<<"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"1000\" width=\"1500\">\n";
Point3D P(100,0,0),orig(500,500,0);
while(in>>P)
{
P = P + orig;
list.push_back(P);
cout<<P<<endl;
}
int sz = list.size();
float sum = 0,sumR = 0,target = (sz-2)*180;
for(int i = 0;i<sz;++i)
{
int two = (i+1) % sz,three = (i+2) % sz;
Vector2D front = list[three] - list[two];
Vector2D back = list[two] - list[i];
Vector2D backrev = back*-1;
float f = Deg(front.angleX());
float b = Deg(back.angleX());
float turn = front.angleX() - back.angleX();//normR(v2.angleX()) - normR(v1.angleX());
float angle = front^(backrev);
if (angle == 0) angle = PI;
if(turn > 0 )
{
if( f>= 0 && b<= -90) ;
else angle = 2*PI - angle;//take larger angle
}
if(turn < 0)
{
//@float f = Deg(front.angleX());
//@float b = Deg(back.angleX());
if( b>= 90 && f<= -90) angle = 2*PI - angle;
}
sumR += angle;
sum = Deg(sumR);
cout<<"["<<two<<","<<Deg(angle)<<"]\t";
}
cout<<endl<<"target:"<<target<<":"<<sz<<":sum="<<sum<<":"<<endl;
if( (sum < target+2) && (sum > target-2) )
cout<<"\nSimple Polygon Found\n";
//cout<<endl<<sum<<endl;
writePoly(list,out,BLUE);
writePoints(list,out);
out<<"</svg>\n";
out.close();
return 0;
}