Search code examples
c++data-structures2dpointsnearest-neighbor

2D nearest neighbour search for moving points


I want do do some flocking simulation, as described here.

For this I need to search for the nearest neighbours of each of my 2D points. However, I cannot use a static data structure like a k-d tree because the points are always moving...

What's a good (easy) datastructure/library that is able to achieve this? I'm working with C++...


Solution

  • Maybe you want to try a quadtree or a spatial index? What's the problem with a k-d tree? Basically when have the edge the flock/points you can skip checking collision with edges far away. A spatial index can be a quadtree, r-tree, kd-tree or hilbert r-tree. A better answer can be read here: Approximate, incremental nearest-neighbour algorithm for moving bodies

    "That is, recursively partition the "world" into a graph with four subnodes each. The tree can then quickly check which objects are inside a particular square of the world and discard the rest. A very effective culling technique often used for improving performance of collision detection in games."