6

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?

nbro
  • 15,395
  • 32
  • 113
  • 196
  • 4
    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. – Blender Feb 28 '12 at 19:33

5 Answers5

9

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.

Simulated light transport

Note how the spray around the lights is glowing with scattered light.

nbro
  • 15,395
  • 32
  • 113
  • 196
sigfpe
  • 7,996
  • 2
  • 27
  • 48
7

I've used them as an efficient way to find the nearest neighbors of a given point for machine learning.

Joel
  • 5,618
  • 1
  • 20
  • 19
4

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.

Blender
  • 289,723
  • 53
  • 439
  • 496
1

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.

nbro
  • 15,395
  • 32
  • 113
  • 196
James Johnston
  • 9,264
  • 9
  • 48
  • 76
1

I used them in a pricing project. The object was to find the best price that matched multiple criteria.

TMN
  • 3,060
  • 21
  • 23