如何找到射线与移动圆的第一个交点
我已经在一个问题上苦苦挣扎了一段时间,到目前为止还没有找到比天真的解决方案更好的解决方案:
给出了 N 个按照线性定律移动的圆圈。对于每个圆,我们都有其初始(时刻 0.0)半径、初始坐标及其半径和时刻 1.0(结束时刻)坐标。我们还有 k 条射线,给出了它们的原点坐标和沿射线的向量。每条射线仅存在于给定时刻 tk。我需要能够找到射线与任何圆的第一个交点。 k 的预期数量非常大(数百万或数十亿),并且圆的预期数量(数千)。我需要更快的解决方案,然后检查所有圆圈的所有光线。
我已经在互联网上搜索了一段时间,但没有找到好的解决方法。即使是解决圆圈不动的更简单问题的想法也会受到赞赏。
我感觉 kd 树应该适合静态情况,也许动态 kd 树可以解决更难的问题。我仍然不知道如何使用 kd-tree,即使是更简单的一种。
I have been struggling with a problem for a while and so far have not found any solution better then the naive one:
N circles are given that are moving according to a linear law. For each of the circles we have its initial (at moment 0.0) radius, initial coordinates and its radius and coordinates at moment 1.0 (end moment). We also have k rays given with coordinates of their origin and a vector along the ray. Each ray only exists at a given moment tk. I need to be able to find the first intersection of a ray with any of the circles. The expected number of k is quite large (millions or billions) as well as the expected number of circles (thousands). I need solution faster then checking all rays against all circles.
I have been searching round the internet for some time but I have found no good solution approach. Even an idea for the easier problem of the circles not moving will be appreciated.
I have the feeling that a kd-tree should be appropriate for the static case and maybe a kinetic kd-tree will solve the harder one. Still I cannot figure out how to use kd-tree even for the easier one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将其视为 3D 静态情况,并以时间作为附加坐标。带有路径的圆变成截锥体,并且射线在平面上 time=tk。如果平截头体的位置不太密集,那么二元空间分区(kd 树,...)会有所帮助。
要找到射线穿过的所有分区,首先找到原点所在的分区,然后按射线方向上的分区邻居遍历(在树中)。这取决于所使用的分区方法。它与光线穿过的分区数量呈线性关系。
更新:最好将平截头体放置在它所接触的每个分区中。一个平截头体将分为多个分区。
这是一维加时间的示例。一切都一样,圆有起点和终点以及起点和终点半径。
X 方向分区:
该梯形将进入两个分区。
时间方向分区:
X左分区的梯形将进入两个时间分区,而X右分区的梯形将只进入上分区。
为了实现它,需要计算在某个平面部分上直线和轴平面之间是否有交点,以及如果没有交点则平面的哪一侧是直线。计算在二维情况下是相同的,甚至在更高维度下也是如此。
You can look at this as static case in 3D with time as additional coordinate. Circle with path became frustum and ray is in a plane time=tk. If frustums are not positioned too dense than binary space partitioning (k-d tree, ...) can help.
To find all partitions crossed by ray first find partition where is origin and than traverse (in tree) by partition neighbour in ray direction. It depends on partitioning method used. It is linear in number of partitions crossed by ray.
Update: It is idea to put frustum in each partition it is touching. One frustum will be in more partitions.
This is an example in 1 dimension plus time. Everything is same, circles have starting and ending point and starting and ending radius.
Partitioning in X direction:
This trapezoid will go in both partitions.
Partitioning in time direction:
Trapezoid from X left partition will go in both time partitions, while in X right partition it will go only in upper partition.
To implement it it is needed to calculate is there an intersection between line and axis plane on some plane part and if there is no intersection on which side of a plane is a line. Calculation is same in 2D case, or even in higher dimensions.
(大声思考)您可能想要使用八叉树或多分辨率网格与 Bresenham 算法来快速消除大量检查?
(Thinking out loud) You might want to use an octree or multi-resolution grid with Bresenham's algorithm to quickly eliminate a lot of checks?