The other day, I was reading about kd-trees. I was looking for a concrete and simple situation where such a data structure could be useful. Does anybody have such an example?
-
4They are used in raytacing to break a scene down into a couple of boxes. It speeds up collisions because if a ray doesn't collide with the bounding box, it surely doesn't collide with its contents. – Blender Feb 28 '12 at 19:33
5 Answers
I used a kd-tree to simulate light transport through spray generated by a wave. This made it possible to render droplets of spray that weren't just illuminated by lamps, but also indirect lighting coming from other droplets.
I stored points of spray in a kd-tree and then used the kd-tree to quickly find which points were near each other, and hence which droplets of water were illuminated by each other. (Actually, it was a little more sophisticated, but the structure was still a kd-tree.) This made it possible to render a nice glow through the spray.
Here's a picture of the method in use.
Note how the spray around the lights is glowing with scattered light.
I've used them as an efficient way to find the nearest neighbors of a given point for machine learning.

- 5,618
- 1
- 20
- 19
They are used in raytacing to break a scene down into a couple of boxes. It speeds up collisions because if a ray doesn't collide with the bounding box, it surely doesn't collide with its contents.

- 289,723
- 53
- 439
- 496
VTK has one: http://www.vtk.org/doc/nightly/html/classvtkKdTree.html for an example.
Take a look at functions like FindClosestPoint
. The class takes a comparatively long time to build given a large set of input points. But after the tree is built, functions like this one run very fast.

- 15,395
- 32
- 113
- 196

- 9,264
- 9
- 48
- 76
I used them in a pricing project. The object was to find the best price that matched multiple criteria.

- 3,060
- 21
- 23