• Advertisement
Sign in to follow this  

Nearest neighbour in 3d Kd-Tree

This topic is 4683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I found this, which may or may not be helpful. Doesn't look like it is very detailed, but you might find something:

Nearest Neighbor Searching With KD Trees

This may be more useful:

Optimizing Search Strategies in k-d Trees

Beyond that, well, I'm sure your google skills are as good as mine, and that's where these popped up.

Share this post

Link to post
Share on other sites
There has just been a thread about nearest neighbor queries on gdalgorithms. This is what I posted there:

--- snip ---
K-d trees is the standard solution for (k-)nearest neighbor queries.
I would not try to mess around with anything else.

In short, you do the following:

You search the space with a shrinking sphere query, the radius being
determined by the (k-th) closest neighbor found so far. Each node of
the tree is conceptually associated with an n-dimensional box. You
search the tree recursively near to far (where near corresponds to
the node box in which the sphere center lies). You cull far nodes
for which the closest point on the n-dimensional box lies outside
the query sphere. When you reach a leaf, you search all points
inside the leaf.

Code for this is given on pages 320-321 of my book (less the shrinking
sphere bit, which is trivial to add). It's only about 10 lines of code.
--- end snip ---

The nearest neighbor algorithm for k-d trees is also described in the original paper by Friedman et al. as available for download here:


Unfortunately, it's not the most readable of explanations, but its still worth a look.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement