测试一个线段是否相交的球体线段、球体、测试

2023-09-10 23:36:45 作者:人丑任性

我试图确定一个线段(即两点之间)是否相交的球体。我不感兴趣的交叉点的位置时,段只是是否相交球体表面。有没有人有任何建议,什么是最有效的算法,这会是什么? (我不知道是否有一些比平常射线球交集算法简单任何算法,因为我不感兴趣,交叉位置)

I am trying to determine whether a line segment (i.e. between two points) intersects a sphere. I am not interested in the position of the intersection, just whether or not the segment intersects the sphere surface. Does anyone have any suggestions as to what the most efficient algorithm for this would be? (I'm wondering if there are any algorithms that are simpler than the usual ray-sphere intersection algorithms, since I'm not interested in the intersection position)

推荐答案

我不知道该怎么做它的标准方式是,但如果你只是想知道,如果它相交,这里是我会做什么。

I don't know what the standard way of doing it is, but if you only want to know IF it intersects, here is what I would do.

一般规则......避免这样做的sqrt()或其它昂贵的操作。如果可能的话,应对半径的平方。

General rule ... avoid doing sqrt() or other costly operations. When possible, deal with the square of the radius.

确定是否出发点是球体的半径内。如果你知道这是从来没有的话,那么跳过此步骤。如果你在里面,你的射线相交的领域。

从现在起,你的出发点是在范围之外。

From here on, your starting point is outside the sphere.

现在,想象的小盒子,将适合的球体。如果要在该框,检查射线的x方向,y方向和z方向,以看它是否会相交,你的射线开始于框的侧面。这应该是一个简单的标志检查,或比较反对零。如果你是外面和远离它,你将永远不会相交的。

从现在起,你是在更复杂的阶段。你的出发点是虚框和球体之间。您可以使用微积分和几何形状得到简化EX pression。

From here on, you are in the more complicated phase. Your starting point is between the imaginary box and the sphere. You can get a simplified expression using calculus and geometry.

你想要做什么的主旨在于确定是否您的射线与球体之间的最短距离小于所述球体的半径。

The gist of what you want to do is determine if the shortest distance between your ray and the sphere is less than radius of the sphere.

让你的光重新通过psented $ P $(X0 +​​ I * T,Y0 + J * T,Z0 + K * T),以及您的球心处于(XS,YS,ZS)。所以,我们要找出T,使得它会给最短的(XS - X0 - 我* T,伊苏 - Y0 - J * T,ZS - Z0 - K * T)。

Let your ray be represented by (x0 + i*t, y0 + j*t, z0 + k*t), and the centre of your sphere be at (xS, yS, zS). So, we want to find t such that it would give the shortest of (xS - x0 - i*t, yS - y0 - j*t, zS - z0 - k*t).

让X = XS - X0,Y = YX - Y0,Z = ZS - Z0,D =幅度矢量的平方

Let x = xS - x0, y = yX - y0, z = zS - z0, D = magnitude of the vector squared

D = X ^ 2 -2 * X * I * T +(I * T)^ 2 + Y ^ 2 - 2 * Y *Ĵ* T +(j * T)^ 2 + Z ^ 2 - 2 * Z * K * T +(K * T)^ 2

D = x^2 -2*x*i*t + (i*t)^2 + y^2 - 2*y*j*t + (j*t)^2 + z^2 - 2*z*k*t + (k*t)^2

D =(I ^ 2 + J ^ 2 + K ^ 2)* T ^ 2 - (X * I + Y * J + Z * K)* 2 * T +(X ^ 2 + Y ^ 2 + ž^ 2)

D = (i^2 + j^2 + k^2)*t^2 - (x*i + y*j + z*k)*2*t + (x^2 + y^2 + z^2)

DD / DT = 0 = 2 * T *(I ^ 2 + J ^ 2 + K ^ 2) - 2 *(X * I + Y * J + Z * K)

dD/dt = 0 = 2*t*(i^2 + j^2 + k^2) - 2*(x*i + y*j + z*k)

T =(X * I + Y * J + Z * K)/(I ^ 2 + J ^ 2 + K ^ 2)

t = (x*i + y*j + z*k) / (i^2 + j^2 + k^2)

插入吨放回方程D = ....如果结果是小于或等于球体的半径的平方,则具有交点。如果是的,那么没有交集。

Plug t back into the equation for D = .... If the result is less than or equal the square of the sphere's radius, you have an intersection. If it is greater, then there is no intersection.