Advertisement

sorting vertices in a polygon (clockwise/counterclockwise)

Started by July 25, 2003 06:58 AM
1 comment, last by Hybrid666 21 years, 6 months ago
hi, im looking to sort the vertices in a convex polygon, so that they have a clockwise order, when the normal is pointing out of the front of the polygon. i have some code, but it does not take into account the normal of the polygon, making it unusable. i have all the points stored in random order, and the normal of the polygon stored, and i can compute the center by adding up all the points and dividing them by the number of points. any ideas on where i go from there? cheers in advance, Hybrid
Why not use the code you have now, and just check if it''s ordered the correct way when done. If not, reverse the order.
Advertisement
grap pen and pencil (wonder how many times I wrote that by now), draw a polygon. I think the correct neighbour or a vertex (the correct one out of the two choices you have) can be determined by the dot product (either the sign or by determining which one is bigger/smaller) of the vector connecting the vertex with it´s neighbour and the cross product of the normal and the vector from the center to the vertex.
Not sure about this and defenitely 2 lazy to check it out myself but I think this should work.

EDIT: On 2nd thought: In a convex polygon the sign should do (positive/negative depending on the order you want).

[edited by - Atheist on July 25, 2003 11:43:56 AM]

This topic is closed to new replies.

Advertisement