|
|
//查找3个平面之间的交叉点
bool CPlane::Intersect(const CPlane &p2, const CPlane &p3, CVector3 *intersectPoint)
{
CVector3 temp;
CVector3 normal(normal_a ,normal_b , normal_c);
CVector3 p2normal( p2.normal_a , p2.normal_b , p2.normal_c);
CVector3 p3normal( p3.normal_a , p3.normal_b , p3.normal_c);
//获得P2,P3交线
temp.CrossProduct(p2normal , p3normal);
//交线与平面1夹角
float dp = normal.DotProduct(temp);
//为90度则交线与平面1法线垂直,与平面1平行,不存在交点
if (dp == 0.0f)
return false;
//找到交点
if (intersectPoint)
{
*intersectPoint = temp * d;
//平面1,3交线
temp.CrossProduct(p3normal , normal);
*intersectPoint = *intersectPoint + (temp * p2.distance);
//平面1,2交线
temp.CrossProduct(normal , p2normal);
*intersectPoint = *intersectPoint + (temp * p3.distance);
*intersectPoint = *intersectPoint / -dp;
}
return true;
}
哪位大哥对这个计算3个平面交点的方式比较熟啊,我自己写的是解方程组,看了这个算法,看的不是很明白
首先对象自身是个平面1,传入平面2,平面3,计算3个平面的交点,其中的normal_a,normal_b,normal_c为平面法线向量的3个值
计算了平面2,3的法线,进行叉乘,得到temp向量,即为p2和p3的交线
用平面1的法线点乘此temp向量,如果结果为0,说明平面1平行于temp向量,则3个平面无交点
不知道上边我理解的对不对,然后接下来如何求交点的地方就看不懂几何意义了
*intersectPoint = temp * d;
。。。。。
*intersectPoint = *intersectPoint + (temp * p2.distance);
。。。。。
*intersectPoint = *intersectPoint + (temp * p3.distance);
。。。。。
*intersectPoint = *intersectPoint / -dp;
关键的疑点在这4句,两平面交线向量点乘上另一个平面到原点的距离,这个是个什么几何意义呢? 是个怎么的过程呢?
我例举了几个简单的平面带入这个算法试了一下,的确求出的是正确交点。 |
|