两平面的交线 [英] Line of intersection between two planes

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

问题描述

如何求两个平面的交线?

我知道数学思想,我做了平面法向量之间的叉积

但是如何以编程方式从结果向量中获取行

解决方案

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

虽然这里的其他答案已经涵盖了原则.

<小时>

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

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

虽然这适用于 2 个平面(其中第 3 个平面可以使用前两个平面的叉积计算),但对于 2 个平面版本,问题可以进一步减少.>

  • 不需要使用 3x3 矩阵行列式,
    我们可以使用第一个和第二个平面之间的叉积的平方长度(这是第三个平面的方向).
  • 不需要包括第三个平面的距离,
    (计算最终位置).
  • 无需否定距离.
    通过交换叉积顺序来节省一些 CPU 周期.

包括这个代码示例,因为它可能不是很明显.

//2-planes 的交集:基于 3-plane 版本的变体.//参见:图形宝石 1 页 305////请注意,平面的法线"分量不必是单位长度bool isect_plane_plane_to_normal_ray(const 平面&p1,const 平面&p2,//输出参数Vector3f&r_point, Vector3f&r_normal){//逻辑上是第三个平面,但我们只使用法线组件.const Vector3f p3_normal = p1.normal.cross(p2.normal);const float det = p3_normal.length_squared();//如果行列式为 0,则表示平行平面,没有交集.//注意:您可能想在此处检查 epsilon 值.如果(确定!= 0.0){//计算最终(点,法线)r_point = ((p3_normal.cross(p2.normal) * p1.d) +(p1.normal.cross(p3_normal) * p2.d))/det;r_normal = p3_normal;返回真;}别的 {返回假;}}

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

解决方案

Adding this answer for completeness, since at time of writing, none of the answers here contain a working code-example which directly addresses the question.

Though other answers here already covered the principles.


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

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

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.

  • 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天全站免登陆