polygon vertices - clockwise or counterclockwise

依然范特西╮ 提交于 2019-12-31 03:32:05

问题


I came across this link http://www.mathopenref.com/coordpolygonarea2.html

It explains how to calculate the area of a polygon and helps to identify whether the polygon vertices we entered is clockwise or counter clockwise.

If area value is +ve, it is clockwise, if it is -nv then it is in counterclockwise.

My requirement is to identify only whether it is clockwise or counterclockwise. Is this rule will work correctly (though there are limitations as mentioned in the link). I have only regular polygons (not complicated, no self intersections) but the vertices are more.

I am not interested in the area value accuracy, just to know the ring rotation.

Any other thought on this.


回答1:


For convex polygons:

Select two edges with a common vertex. 
Lets say, edge1 is between vertex A and B. Edge2 is between vertex B and C.
Define to vectors: vect1: A----->B
                   vect2: B----->C
Cross product vect1 and vect2. 
If the result is positive, the sequence A-->B-->C is Counter-clockwise. 
If the result is negative, the sequence A-->B-->C is clockwise. 



回答2:


If you have only convex polygons (and all regular polygons are convex), and if your points are all organized consistently--either all counterclockwise or all clockwise--then you can determine which by just computing the (signed) area of one triangle determined by any three consecutive points. This is essentially computing the cross product of the two vectors along the two edges.



来源:https://stackoverflow.com/questions/9473570/polygon-vertices-clockwise-or-counterclockwise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!