• Advertisement

Archived

This topic is now archived and is closed to further replies.

Distance between a point and a polygon :(

This topic is 5064 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

Is there a way that would find the distance between a point and a polygon? I''m trying to use a binary tree to cut down on collision detection between the player and the playing area, but I need to find the closest point to a polygon to draw the lines to cut up the 2D playing area. I''ve looked around, but I can''t seem to find any help.

Share this post


Link to post
Share on other sites
Advertisement
I suppose you could do a quick pass to check which of the points of a polygon is closest to the point (quick as in without the final sqrt), then apply the sqrt to the closest point to find the distance...

Share this post


Link to post
Share on other sites
How accurate do you need it to be?

If speed is your concern and a margin of error is ok, you could just check the distance to one of the vertices of the polygon. The center of the polygon will give slightly better results, but unless you have it stored it is also a little slower.

Unfortunatly, the larger your polygons get the more accuracy problems this will have.

For a better results check all the vertex points and use the smallest, as falkone suggested, just be aware that it still isn''t perfectly accurate.



Drakonite

Shoot Pixels Not People

Share this post


Link to post
Share on other sites
The most accurate solution would be to find the distance between the point and each line segment comprising the polygon, and take the minimum distance.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites

  • Advertisement