0
votes

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?

1
Can you add a definition of what you mean by a clockwise polygon? - ely
A polygon that has is vertices ordered clockwise. - btatarov
Oh, so not the same as here: (link) (e.g. you're not worried about the sign of adjacent edge cross-products?) - ely
clockwise means that the "inside" of the polygon is always to the right, and the "outside" is to the left. - counterclockwise, the "inside" is to the left. - Charles Bretana

1 Answers

2
votes

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.