algorithm - Finding all points in certain radius of another point -


i making simple game , stumbled upon problem. assume several points in 2d space. want make points close each other interact in way.

let me throw picture here better understanding of problem: image of problem

now, problem isn't computing distance. know how that.

at first had around 10 points , check every combination, can assume, extremely inefficient increasing number of points. if had million of points in total, of them distant each other?

i'm trying find suitable data structure or way @ problem, every point can mind surrounding , not whole space. there known algorithms this? don't know how name problem can google want.

if don't know of such known algorighm, ideas welcome.

you're still going have iterate through every point, there 2 optimizations can perform:

1) can eliminate obvious points checking if x1 < radius , if y1 < radius (like brent mentioned in answer).

2) instead of calculating distance, can calculate square of distance , compare square of allowed radius. saves performing expensive square root calculations.

this best performance you're gonna get.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -