-
June 24th, 2013, 04:08 AM
#1
Orientation of a polygon
Hi,
Is there any way to check the orientation of polygon with the help of boost library? If so, can someone help or guide me with a small example?
Thanks
-
June 24th, 2013, 05:20 AM
#2
Re: Orientation of a polygon
Hi.
http://debian.fmi.uni-sofia.bg/~serg.../clockwise.htm
Code:
int ClockWise(CPoint2D *p,int n)
{
int i,j,k;
int count = 0;
double z;
if (n < 3)
return(0);
for (i=0;i<n;i++) {
j = (i + 1) % n;
k = (i + 2) % n;
z = (p[j].x - p[i].x) * (p[k].y - p[j].y);
z -= (p[j].y - p[i].y) * (p[k].x - p[j].x);
if (z < 0)
count--;
else if (z > 0)
count++;
}
if (count > 0)
return(COUNTERCLOCKWISE);
else if (count < 0)
return(CLOCKWISE);
else
return(0);
}
You must define CLOCKWISE, COUNTERCLOCKWISE and CPoint2D class.
Best regars.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|