D
D
dyrtage2021-09-30 20:11:47
Python
dyrtage, 2021-09-30 20:11:47

How to find the nearest points on the coordinate plane?

There is a coordinate plane 10 by 10. Points are randomly located on it. Their coordinates can be: (1, 3); (4, 2) etc. Let's say there is a point with coordinates (4, 5). How to find the closest 3 points to it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-09-30
@dyrtage

Are the coordinates strictly integer?
Then bypass the points using the floodfill algorithm, centered on the starting point.
For example, for a small area, the order would be:

5 4 3 4 5
4 2 1 2 4
3 1 X 1 3
4 2 1 2 4
5 4 3 4 5

Digit - at what iteration these positions are checked.
Those. first you check the neighbors with the original one, then the neighbors with them, then the neighbors with those, and so on.
If there is a point in the position, you add it to the list of found ones. When there are 3 points in the list of found ones, you stop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question