我有一个大小为 AxBxC 的 3D 网格,网格中的点之间的距离 d 相等。给定多个点,给定以下假设,找到每个网格点到最近点的距离的最佳方法是什么(每个网格点都应该包含到点云中最近点的距离)?
假设 A、B 和 C 相对于 d 相当大,给出一个大概 500x500x500 的网格,大约有 100 万个点。
还假设如果到最近点的距离超过 D 的距离,我们不关心最近点的距离,它可以安全地设置为某个较大的数字(D 可能是 d 的 2 到 10 倍)
由于将有大量的网格点和要搜索的点,因此简单详尽:
for each grid point:
for each point:
if distance between points < minDistance:
minDistance = distance between points
不是一个好的选择。
我正在考虑按照以下方式做一些事情:
create a container of size A*B*C where each element holds a container of points
for each point:
define indexX = round((point position x - grid min position x)/d)
// same for y and z
add the point to the correct index of the container
for each grid point:
search the container of that grid point and find the closest point
if no points in container and D > 0.5d:
search the 26 container indices nearest to the grid point for a closest point
.. continue with next layer until a point is found or the distance to that layer
is greater than D
基本上:将点放入桶中并向外进行径向搜索,直到为每个网格点找到一个点。这是解决问题的好方法,还是有更好/更快的方法?首选有利于并行化的解决方案。