如何找到两个平面之间的交线?
我知道数学思想,我做了平面法向量之间的叉积
而是如何以编程方式从结果向量中获取行
发布于 2015-09-05 15:07:20
添加此答案是为了完整性,因为在撰写本文时,此处的答案中没有一个包含可直接解决问题的工作代码示例。
虽然其他答案在这里。
可以使用简化版本的三平面相交算法来计算两个平面之间的直线。
答案中的第二个“更健壮的方法”引用了3平面交点。
虽然这对于两个平面工作得很好(其中第三个平面可以使用前两个平面的叉积来计算),但对于两个平面版本,问题可以进一步减少。
相反,我们可以使用第一和第二个平面之间的叉积的平方长度(这是第三个平面的方向)。
(计算最终位置)。
通过交换交叉产品订单来节省一些cpu周期。
包括这个代码示例,因为它可能不会立即明显。
// Intersection of 2-planes: a variation based on the 3-plane version.
// see: Graphics Gems 1 pg 305
//
// Note that the 'normal' components of the planes need not be unit length
bool isect_plane_plane_to_normal_ray(
const Plane& p1, const Plane& p2,
// output args
Vector3f& r_point, Vector3f& r_normal)
{
// logically the 3rd plane, but we only use the normal component.
const Vector3f p3_normal = p1.normal.cross(p2.normal);
const float det = p3_normal.length_squared();
// If the determinant is 0, that means parallel planes, no intersection.
// note: you may want to check against an epsilon value here.
if (det != 0.0) {
// calculate the final (point, normal)
r_point = ((p3_normal.cross(p2.normal) * p1.d) +
(p1.normal.cross(p3_normal) * p2.d)) / det;
r_normal = p3_normal;
return true;
}
else {
return false;
}
}发布于 2011-06-20 21:40:56
平面的方程是ax + by + cz + d = 0,其中(a,b,c)是平面的法线,d是到原点的距离。这意味着满足该方程的每个点(x,y,z)都是该平面的成员。
给定两个平面:
P1: a1x + b1y + c1z + d1 = 0
P2: a2x + b2y + c2z + d2 = 0这两个方程之间的交集是验证这两个方程的点集。要沿着这条线找到点,您可以简单地为x选择一个值,任何值,然后求解y和z的方程。
y = (-c1z -a1x -d1) / b1
z = ((b2/b1)*(a1x+d1) -a2x -d2)/(c2 - c1*b2/b1)如果使用x=0,就会变得更简单:
y = (-c1z -d1) / b1
z = ((b2/b1)*d1 -d2)/(c2 - c1*b2/b1)发布于 2013-07-13 16:44:29
只要两个平面不平行,此方法就可以避免除以零。
如果这些是平面:
A1*x + B1*y + C1*z + D1 = 0
A2*x + B2*y + C2*z + D2 = 01)找到与交线平行的向量。这也是垂直于其他两个平面的第三个平面的法线:
(A3,B3,C3) = (A1,B1,C1) cross (A2,B2,C2)2)形成一个由3个方程组成的系统。这些描述了在一点相交的3个平面:
A1*x1 + B1*y1 + C1*z1 + D1 = 0
A2*x1 + B2*y1 + C2*z1 + D2 = 0
A3*x1 + B3*y1 + C3*z1 = 03)求解得到x1、y1、z1。这是交线上的一个点。
4)相交线的参数方程为:
x = x1 + A3 * t
y = y1 + B3 * t
z = z1 + C3 * thttps://stackoverflow.com/questions/6408670
复制相似问题