简体   繁体   English

最近邻搜索的八叉树算法

[英]Algorithm for Octree for nearest neighbor search

Problem Statement : To find the nearest GRID ID of each of the particles using Octree.问题陈述:使用八叉树找到每个粒子的最近 GRID ID。

Fig[1]:图。1]:在此处输入图片说明

Fig[2]:图[2]:在此处输入图片说明

I have a system of particles(~6k, movable) for which I need to check which grid point (rigid; in picture) is nearest to.我有一个粒子系统(~6k,可移动),我需要检查哪个网格点(刚性;在图片中)最接近。 Somebody have suggested me to go for Octree as it is fast(est) for 3D Grids.有人建议我使用 Octree,因为它对于 3D 网格来说速度很快(est)。

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])获取输入作为点 P 开始坐标 C(第一次是 [0,0,0])
  2. Start Size = [Sx, Sy, Sz]起始尺寸 = [Sx, Sy, Sz]
  3. Get all 8 mid point Mi = {M1,..,M8} get minimum distance of Mi and P得到所有 8 个中点 Mi = {M1,..,M8} 得到 Mi 和 P 的最小距离
  4. Say M get start position of M as Cn set size Sn = [Sx/8, Sy/8, Sz/8]假设 M 得到 M 的起始位置作为 Cn 设置大小 Sn = [Sx/8, Sy/8, Sz/8]

  5. if distance of M and P is less than 2 * (Grid Space G):如果 M 和 P 的距离小于 2 *(网格空间 G):

    5.1. 5.1. Iterate all the grid points from Cn to Sn迭代所有网格点从 Cn 到 Sn

    5.2. 5.2. Print least as result结果打印最少

  6. else别的

    6.1. 6.1. set Start coordinate as Cn设置起始坐标为 Cn

    6.2. 6.2. set Size as Sn将大小设置为 Sn

    6.3. 6.3. Goto 1转到 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.问题:如果粒子在边界外或几乎在边界上,最后一次迭代会消耗所有速度,因为它检查所有 A x B x C。

Please suggest if you have a better way to solve this problem.请建议您是否有更好的方法来解决此问题。

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)) .假设一个网格单元的大小是(a, b, c) ,那么离(x, y, z)最近的网格点是(a*floor(x/a+0.5), b*floor(y/b+0.5), c*floor(z/c+0.5))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM