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++...
Second neighbours are at the centers of the nearest adjacent cells. Third neighbours: centers of the next adjacent cells (those which share two corners with your cell). Fourth neighbours: far corners of the nearest adjacent cells.
k-nearest neighbor search identifies the top k nearest neighbors to the query. This technique is commonly used in predictive analytics to estimate or classify a point based on the consensus of its neighbors.
The average nearest neighbor ratio is calculated as the observed average distance divided by the expected average distance (with expected average distance being based on a hypothetical random distribution with the same number of features covering the same total area).
It is an algorithmic primitive for finding all similar pairs, solving clustering problems on large datasets, closest pair problems in computational geometry, and is used in recommendation systems, spell- checkers, and more. d(pi,q) i.e. the closest point to q in the set P. define other distances too.
People have studied this problem. The important keyword is kinetic, when looking for work in this ares.
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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With