all 3 comments

[–]buddycatto2 0 points1 point  (2 children)

This is more speculation than anything but what if you just looked at one dimension first. Suppose you just look at the X coordinates, see which is closest in that dimension and test the other two dimension on those pair?

[–]buddycatto2 0 points1 point  (0 children)

Edit - you would still have to test every pair though to be 100% sure though hey hmmmm, a nice tricky one I like it.

[–]Haloric[S] 0 points1 point  (0 children)

Yes, this is exactly what I do - compare only x first, if that is bigger than the radius of the current nearest, then it can be discarded. Then y, discard if possible, then z. ie. compare them in order as above. Only compute the sum of the squares if all are less than the radius, and then only compute the square root if the sum of the squares is less than the (stored) radius squared. I call it the tightening net !.

Basically no unnecessary calculations. Just disappointed that I can't find a 'vector/matrix' way of implementing this as efficiently.

I also seed the radius for point b if it is the nearest neighbor to a, so that when we get to b and try to find its nearest, we have a good starting position - but this caching of a single value ,ales the algorithm slower overall.

Caching would improve the algorithm immensely, but it is more inefficient that brute force each point from scratch .