|
发表于 2004-6-30 17:05:00
|
显示全部楼层
Re:求射线和面的交点
bool InterSection(XRay& ray,XPlan& plan,XPoint& point,float & t)
{
t = 0;
/***
-D - P0 * N(A,B,C)
t = --------------------
d * N(A,B,C)
其中D 为平面方程中的D,
P0为射线的起点。而 d 为射线的方向
**/
t= -(plan.D + ray.m_Point.x * plan.A + ray.m_Point.y * plan.B + ray.m_Point.z * plan.C);
float t2 = (ray.m_Dir.x * plan.A + ray.m_Dir.y * plan.B + ray.m_Dir.z * plan.C) ;
if(t2 == 0.00)
return false;
t /= t2;
//求出交点
point = ray.m_Point + ray.m_Dir * t;
if( t < 0)
return false;
return true;
} |
|