how to get nearest point to a given point in points of polygon?
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 ?
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.
精彩评论