我发现一段代码在做 OBB 交集测试,这让我很困惑。
struct OBB
{
Point c;// centre
Vector u[3];// local x-,y-, and z-axes
Vector e;//Positive halfwidth extents of OBB along each axis
}
int TestOBBOBB(OBB &a, OBB& b)
{
float ra,rb;
Matrix33 R,AbsR;
//compute rotation matrix expressing b in a's coordinate frame
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
R[i][j] = Dot(a.u[i],b.u[j]);
//compute translation vector
Vector t = b.c - a.c;
t = Vector(Dot(t,a.u[0]),Dot(t,a.u[1]),Dot(t,a.u[2]));
//Compute common subexpressions. Add in an epsilon term to counteract arithmetic errors when two edges are parallel
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
AbsR[i][j] = Abs(R[i][j]) + EPSILON;
//Test on axis a.u[0],a.u[1],a.u[2]
for(int i=0;i<3;i++)
{
ra = a.e[0];
rb = b.e[0] * AbsR[i][0] + b.e[1]*AbsR[i][1] + b.e[2]*AbsR[i][2];//(*)
if((Abs(t[i]) > ra + rb) return 0;
}
//....
}
(*)那一行,我实在不明白为什么要这样得到b在a.u[0]上的半径投影长度。我首先是这样做的:
rb = Abs(dot((R*b.e),a.u[0]));
但是我发现b的半径向量e已经变换到a的坐标系中a.u[0]是(1,0,0),那么从b的角度来看,它应该是这样的:
//for test on a.u[0]
rb = Abs((R*b.e).x) = Abs(b.e[0]*R[0][0], b.e[1]*R[0][1],b.e[2]*R[0][2]);
但是在代码片段中,它只将 Abs 放在 R 的元素上。有人可以解释一下吗?