两个平面之间的相交线 [英] Line of intersection between two planes

查看:676
本文介绍了两个平面之间的相交线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到两个平面之间的相交线?

How can I find the line of intersection between two planes?

我了解数学思想,并且做了平面法线向量之间的叉积

I know the mathematics idea, and I did the cross product between the the planes normal vectors

但是如何以编程方式从结果向量中获得线段

but how to get the line from the resulted vector programmatically

推荐答案

为完整起见添加了此答案,因为在撰写本文时,此处的答案均未包含直接解决该问题的有效代码示例.

这里的其他答案已经介绍了这些原则.

可以使用3平面相交算法的简化版本来计算找到两个平面之间的线.

Finding the line between two planes can be calculated using a simplified version of the 3-plane intersection algorithm.

bobobobo的答案中的第二个更可靠的方法"引用了3平面交点.

The 2'nd, "more robust method" from bobobobo's answer references the 3-plane intersection.

尽管这对于2个平面(其中第三个平面可以使用前两个的叉积计算)效果很好,但对于2平面版本,该问题可以进一步减少.

While this works well for 2 planes (where the 3rd plane can be calculated using the cross product of the first two), the problem can be further reduced for the 2-plane version.

  • 不需要使用3x3矩阵行列式,
    我们可以使用第一平面和第二平面之间的叉积的平方长度(即第三平面的方向).
  • 不需要包括第三平面的距离,
    (计算最终位置).
  • 无需取消距离.
    通过交换叉积订单来节省一些cpu周期.
  • No need to use a 3x3 matrix determinant,
    instead we can use the squared length of the cross product between the first and second plane (which is the direction of the 3'rd plane).
  • No need to include the 3rd planes distance,
    (calculating the final location).
  • No need to negate the distances.
    Save some cpu-cycles by swapping the cross product order instead.

包括此代码示例,因为它可能不会立即显而易见.

Including this code-example, since it may not be immediately obvious.

// 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;
    }
}

这篇关于两个平面之间的相交线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆