M
M
marenco_victor2017-01-10 22:46:09
Algorithms
marenco_victor, 2017-01-10 22:46:09

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

3 answer(s)
@
@smple, 2017-01-10
_

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.

V
Vlad_Fedorenko, 2017-01-10
@Vlad_Fedorenko

Look this way https://ru.m.wikipedia.org/wiki/K-tree

N
Nicholas, 2017-01-10
@healqq

If you need to do it once: sort by distance to the object.
If there are many, i.e. for each object coming - look towards clustering algorithms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question