参数情势的射线与平面相交公式可以参考3D数学基本:图形与游戏开发 p269
inline int cIntersectionSegmentPlane(const cVector3d& a_segmentPointA,
const cVector3d& a_segmentPointB,
const cVector3d& a_planePos,
const cVector3d& a_planeNormal,
cVector3d& a_collisionPoint,
cVector3d& a_collisionNormal)
{
cVector3d d = a_segmentPointB - a_segmentPointA;
cVector3d p = a_segmentPointA;
double length = d.length();
// sanity check
if (cZero(length))
{
return (0);
}
// normalize d
d.mul(1.0 / length);
// compute intersection between segment and disk plane
double c[2];
double s[1];
c[0] = a_planeNormal(0)*p(0) - a_planeNormal(0)*a_planePos(0) +
a_planeNormal(1)*p(1) - a_planeNormal(1)*a_planePos(1) +
a_planeNormal(2)*p(2) - a_planeNormal(2)*a_planePos(2);
c[1] = a_planeNormal(0)*d(0) + a_planeNormal(1)*d(1) + a_planeNormal(2)*d(2);
int num = cSolveLinear(c, s);
if (num == 0)
{
return (0);
}
else
{
if ((s[0] >= 0.0) && (s[0] <= length))
{
a_collisionPoint = p + s[0] * d;
if (cDot(a_planeNormal, cSub(a_segmentPointA, a_collisionPoint)) >= 0.0)
{
a_collisionNormal = a_planeNormal;
}
else
{
a_collisionNormal =-a_planeNormal;
}
return (1);
}
else
{
return (0);
}
}
}
inline int