开发者

how to get nearest point to a given point in points of polygon?

开发者 https://www.devze.com 2023-01-30 21:53 出处:网络
Here is image , I want to know how to get nearest point to开发者_开发问答 a given point [can be anywhere] [green one] , for array of points. By seeing we can get, but how to do same in code ?Calcul

Here is image ,

how to get nearest point to a given point in points of polygon?

I want to know how to get nearest point to开发者_开发问答 a given point [can be anywhere] [green one] , for array of points. By seeing we can get, but how to do same in code ?


Calculate the distance to each point:

distance = sqrt((x2-x1)^2 + (y2-y1)^2)

Then take the min of that. There are probably more efficient ways of doing it (e.g. octtrees) for very large # of points.


The distance between between two points can be found by using the distance formula. By implementing this formula, you can iterate through your collection of points and find the closest one to your starting point.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号