DEV Community

Discussion on: Radial Search

Collapse
 
davidedelpapa profile image
Davide Del Papa

The perfect method to compare distance between points is to calculate the euclidean distance between all of them, that is the square root of the sum squared differences between their X and Y components. However, if you just need to know which one is the nearest, you do not need to calculate the exact distance, but you could just compare the squared sums. However, I think you really should calculate at least this to be certain about the results.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

I'd say this is the most inefficient way to do this, but a way none the less, the goal would be to reduce the scope down to a few points, then use euclidian dist. The trouble with checking 10000 points is without scoping, that would be 10000 x 10000 checks. A KDTree helps solve this.

Collapse
 
davidedelpapa profile image
Davide Del Papa • Edited

Ok, in that case you'd better calculate the taxicab distance, which is never lower than the euclidean distance to calculate the bounding box you need, and then compare distances of the points within that box

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

Thank you sir :)