Jump to content
  • Advertisement
Sign in to follow this  
r_bewick

Fast way to order points

This topic is 2610 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 a huge list of unordered points which make up a polygon.
To order the polygon (anticlockwise or clockwise doesn't matter),

1. I select a starting point (from the unordered list) and remove it from the unordered list and add to an ordered list.,
2. I then find the closest point(in the unordered list) to the 1st point, and add that to the ordered list and remove it from the unordered list.
3. I then find the closest point(in the unordered list) to the 2nd point, and add that to the ordered list and remove it from the unordered list.
4. I keep going until the unordered list has no points left in it.

Unfortunately, this is order n^2 or O(n^2) - Is there a better way to do it?

Thanks,
r_bewick

Share this post


Link to post
Share on other sites
Advertisement
The first option that springs to mind is to put the points in a kd-tree which would significantly speed up finding of the closest point.

Share this post


Link to post
Share on other sites

The first option that springs to mind is to put the points in a kd-tree which would significantly speed up finding of the closest point.


Thanks :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!