Jump to content
  • Advertisement
Sign in to follow this  
999999999

Sorting coplanar vertices clockwise/counterclockwise

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have just come up with a problem: how can I sort a set of coplanar vertices clockwise. At the moment I don't know if I need clockwise or counterclockwise but I guess there is little difference. Thanks,999999999

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Pick an arbitrary point on the polygon and walk around the edges...

Or if you don't know what the edges are, use a convex hull algorithm to create the convex polygon structure from the points. Convex hull algorithms calculate the edges of the convex hull.

Share this post


Link to post
Share on other sites
There may be a better way, but here's how I'd do it.

1. Find the center as the average of the vertex set.

2. Choose a vertex arbitrarily and make a reference vector as:

ref = vertex[0] - center;

3. For each of the other vertices find the unsigned angle to the reference vector as:

diff = vertex - center;
angle = atan2(length(cross(diff,ref)), dot(diff,ref));

4. Find the sign of the angle by dotting cross(diff,ref) with the plane normal.

5. Sort the vertices by the signed angle.

Let me know is that needs any clarification.

Share this post


Link to post
Share on other sites
Thank you very much guys, now I can't try it but tomorrow I'll see what happens (I am not completely sure that I need that kind of sorting but who knows)

Share this post


Link to post
Share on other sites
I have solved my problem! It was not a matter of vertex order, well it was but not sorted cw / ccw ! Anyway thank you very much.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!