Q
Q
Qubert2014-10-29 12:17:27
JavaScript
Qubert, 2014-10-29 12:17:27

What is the correct way to find the nearest coordinate points of other elements for the draggable element?

Hello!

The question is: how to correctly search for the nearest coordinate points of other elements for the dragged element?

for example, we have a circle, a square and a triangle, I move the triangle, bring it closer to the circle and it tells me that it is next to the circle, but does not say that it is next to the square ... I thought every time the coordinates of the dragged element changed loop through the coordinates of each element. But it's terrible. Tell me, how can this be solved?

Thanks a lot!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eddy_Em, 2014-10-29
@Eddy_Em

We build a selection buffer, perform analysis in a window of a given size M (the minimum distance to the object that can be considered "close"). We get N objects, the distance to which is not more than M. And then we either reduce the size of the window until there is only one object left (the closest one), or, sorting through the points in a spiral, we find the nearest object like this.
In my opinion, the window size dichotomy method is simpler.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question