Answer the question
In order to leave comments, you need to log in
How to find neighboring objects knowing x and y?
Good day!
Faced the following problem: there is a set of objects with a set of coordinates (x, y) and there is an object with respect to which you need to find the closest 5 objects from this set, for example.
How or what algorithm is better to solve this problem?
Answer the question
In order to leave comments, you need to log in
You need to find the distance between each object and the target.
The distance is determined by the formula (easy to google) sqrt(sqr(x2 - x1) + sqr(y2 - y1))
Where sqrt is the square root, sqr squared power (2), x1,y1 coordinates of the point (target object) x2,y2 coordinates the rest of the points.
Next, sort the results in ascending order and the result will be in the array in order from the beginning.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question