Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for Octree for nearest neighbor search

Problem Statement: To find the nearest GRID ID of each of the particles using Octree.

Fig[1]: enter image description here

Fig[2]: enter image description here

I have a system of particles(~6k, movable) for which I need to check which grid point (rigid; in picture) is nearest to. Somebody have suggested me to go for Octree as it is fast(est) for 3D Grids.

Is this the correct Algorithm for recursive Octree to get the nearest grid point of the grid?

  1. Get a input as point P Start coordinate C (first time it [0,0,0])
  2. Start Size = [Sx, Sy, Sz]
  3. Get all 8 mid point Mi = {M1,..,M8} get minimum distance of Mi and P
  4. Say M get start position of M as Cn set size Sn = [Sx/8, Sy/8, Sz/8]

  5. if distance of M and P is less than 2 * (Grid Space G):

    5.1. Iterate all the grid points from Cn to Sn

    5.2. Print least as result

  6. else

    6.1. set Start coordinate as Cn

    6.2. set Size as Sn

    6.3. Goto 1

Problem: The last iteration eat all speed if the particle is out or nearly on the border as it checks all A x B x C.

Please suggest if you have a better way to solve this problem.

like image 814
Devashish Das Avatar asked Jul 02 '14 11:07

Devashish Das


People also ask

Is KD tree a neighborhood search algorithm?

The nearest neighbour search (NN) algorithm aims to find the point in the tree that is nearest to a given input point. This search can be done efficiently by using the tree properties to quickly eliminate large portions of the search space.

What is the nearest neighbor algorithm graph theory?

The k-nearest neighbor graph (k-NNG) is a graph in which two vertices p and q are connected by an edge, if the distance between p and q is among the k-th smallest distances from p to other objects from P.

Is octree a tree kd?

Like Octrees, k-d trees partition space and enable efficient queries on points. The key difference is that each node in a k-d tree partitons space across one plane per level of depth, leading to a binary tree. Each level generates two half spaces that contain its child nodes, which are recursively subdivided.


1 Answers

There is no need to use an octree here. Octree is useful for the reverse problem (given a grid point, find the nearest particule) but completely useless here.

Assuming the size of a grid cell is (a, b, c), then the nearest grid point from (x, y, z) is (a*floor(x/a+0.5), b*floor(y/b+0.5), c*floor(z/c+0.5)).

like image 197
Thomash Avatar answered Sep 26 '22 02:09

Thomash