Search for all points in a specific radius of another point

I am making a simple game and stumbled upon this problem. Assume that there are several points in a 2D space. I want points close to each other to interact in some way.

Let me take a picture here for a better understanding of the problem: image of the problem

Now the problem is not calculating the distance . I know how to do this.

At first I had about 10 points, and I could just check each combination, but, as you can already assume, this is extremely ineffective with increasing the number of points. What if I had only a million points, but all of them would be very far from each other?

, . ? , , Google , .

, .

+7
6

, :

1) , , x1 < y1 < ( , ).

2) . .

, , , .

+5

. - 2- , .

" " [Aggarwal, Hansen, Leighton, 1990]:

  • : P n E²
  • : P, E² r, q.

" " [Afshani, Chan, 2009]. O (n) , O (log n + k) . , O (n log n). (n - , k - ).

CGAL . . .

+10

x y, ( ?), : x + - r, y + - r, , , , .

+2

, X Y? , .

R, Xmax-Xmin X Ymax-Ymin Y.

2D [X/R, Y/R] . .

, , 8 .

: X Y 100, R 1, 43,2, 77,1 [43,77]. [42,76] [43,76] [44,76] [42,77] [43,77] [44,77] [42,78] [43,78] [44,78] . , (, 43,9,77,9 , 1 ), 8 .

(, ?), ( ) . - O (1). O (n).

, , , ; , - . , R = 1 R R, 2D- . , , 1000 ? , , , : 8 . , R.

, , , - , X? , XR X + R. , , , , X R, / , . X, , R.

You can also go to cells smaller than R. You will have fewer candidates who cannot be close enough. For example, with R / 2, you should check 25 link lists instead of 9, but have on average (if randomly distributed) the 25/36th as many points to check. This may be a minor gain.

0
source

All Articles