【发布时间】:2021-09-07 11:08:07
【问题描述】:
我试图了解计算点和 3D 截锥之间的最短向量的某种实现。最初的想法在this paper中介绍。
因此,如果我们有两个球形物体:物体 A 的半径为 rA,位置 pA 和速度 vA,物体 B 的半径为 rB,位置 pB 和速度 vB,那么我们可以用更简单的方式表示,计算相对位置和相对速度,假设物体 A 是一个点,物体 B 的半径是 rA + rB。
在 2D 中,这看起来像是从图 (a) 到图 (b) 的转换,其中 tau 只是一个标量因子: 一个
3D 图形很相似,但不是圆形,而是球体。
现在,如果相对速度矢量位于灰色的截锥中,我们应该找到相对速度V变化最小的矢量u来移动它到圆锥的圆周如下图所示(注意:P为相对位置):
这有两种情况:
-
如果相对速度低于截止圆的中心(低于蓝色虚线)。在这种情况下,u 将位于截止圆(较小的圆)上。
-
第二种情况,我不明白是怎么计算出来的,是相对速度在小圆(球体)的中心以上时,在这种情况下u会投影在圆锥的切线。 P 和 V 向量表示的平面与大球体的交点是一个u 所在的圆。
const Vector3 relativePosition = other->position_ - position_; const Vector3 relativeVelocity = velocity_ - other->velocity_; const float distSq = absSq(relativePosition); const float combinedRadius = radius_ + other->radius_; const float combinedRadiusSq = sqr(combinedRadius); Plane plane; Vector3 u; if (distSq > combinedRadiusSq) { /* No collision. */ const Vector3 w = relativeVelocity - tau * relativePosition; /* Vector from cutoff center to relative velocity. */ const float wLengthSq = absSq(w); const float dotProduct = w * relativePosition; if (dotProduct < 0.0f && sqr(dotProduct) > combinedRadiusSq * wLengthSq) { /* Project on cut-off circle. */ const float wLength = std::sqrt(wLengthSq); const Vector3 unitW = w / wLength; plane.normal = unitW; u = (combinedRadius * tau - wLength) * unitW; } else { **/* Project on cone. I Don't understand this! */ const float a = distSq; const float b = relativePosition * relativeVelocity; const float c = absSq(relativeVelocity) - absSq(cross(relativePosition, relativeVelocity)) / (distSq - combinedRadiusSq); const float t = (b + std::sqrt(sqr(b) - a * c)) / a; const Vector3 ww = relativeVelocity - t * relativePosition; const float wwLength = abs(ww); const Vector3 unitWW = ww / wwLength; plane.normal = unitWW; u = (combinedRadius * t - wwLength) * unitWW;** } }
我知道最终我们需要找到 t(如代码中所示)来缩放 P。但是,我不明白这里如何使用叉积以及我们试图求解的二次方程代表什么。
这个功能可以在here找到。
【问题讨论】:
-
点积通常在 3D 中用于测试对齐。我相信
1 = colinear、0 = perpendicular和-1 is colinear在另一个方向。叉积会在 90 度角处找到反射光线的法线。
标签: linear-algebra computational-geometry game-development