Question

If I have the following array structure of polygon vertices (polygons can be both convex and concave):

[ [x = 5, y = 5], [x = 10, y = 10], [x = 3, y = 15], [x = 0, y = 7] ]

I can easily tell if the polygon is clockwise or counter clockwise. But how do I convert it? If I reverse the array, it works for the examples I can think about but does it work for every polygon?

Was it helpful?

Solution

Yes reversing the vertices should work in every case... If the ordered list is a valid polygon (no two edges, defined by adjacent vertices, cross one another, including the edge defined by the last vertex to the first), then reversing the order of the vertices will just change it from clockwise to counter-clockwise, or vice versa.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top