2
$\begingroup$

When using land information data such as polygons presented as arrays of points, sometimes I need to know whether a polygon's points turn clockwise or counter-clockwise. Please tell me what kind of algorithm could help with this

$\endgroup$
3
  • 1
    $\begingroup$ If the polygon is convex it is enough to check the cross product of any two given consecutive edges, treated as vectors with the same origin. For polygon $ABCDE$ it would be $CB \times CD$ $\endgroup$
    – Golob
    Nov 25, 2014 at 11:07
  • 2
    $\begingroup$ Assuming your polygons are simple ("land information data" indicates this might be the case), you can calculate their signed area and check its sign, e.g. see here. $\endgroup$
    – dtldarek
    Nov 25, 2014 at 11:15
  • $\begingroup$ dtldarek thank you! Why do you put a comment instead of answering? I'd mark your answer as best one $\endgroup$ Dec 2, 2014 at 16:31

1 Answer 1

2
$\begingroup$

Assuming your polygons are simple ("land information data" indicates this might be the case), you can calculate their signed area as $$A = \frac12 (x_1y_2-x_2y_1+x_2y_3-x_2y_2 + \dots + x_ny_1-x_1y_n)$$ and check its sign (positive means counterclockwise). The formula is found on Wolfram MathWorld. -- dtldarek

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .