# Nearest neighbour in 3d Kd-Tree

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

## Recommended Posts

Can someone guide me in this problem?

##### Share on other sites
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 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:

ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/75/482/CS-TR-75-482.pdf

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

Thanx!
/p

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633390
• Total Posts
3011631
• ### Who's Online (See full list)

There are no registered users currently online

×