沿两个平面的交点求直线 [英] Finding the line along the intersection of two planes

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

问题描述

我试图在 3D 中绘制由两个平面相交形成的线,但我在理解数学时遇到了麻烦,这已经解释过了 问题,但它与原始解释有一个死链,这个方程对我不起作用(它有不平衡的括号,我试图在下面更正).

var planeA = new THREE.Plane((new THREE.Vector3(0, 0, 1)).normalize(), 100);var planeB = new THREE.Plane((new THREE.Vector3(1, 1, 1)).normalize(), -100);var x1 = planeA.normal.x,y1 = planeA.normal.y,z1 = planeA.normal.z,d1 = planeA.constant;var x2 = planeB.normal.x,y2 = planeB.normal.y,z2 = planeB.normal.z,d2 = planeB.constant;var point1 = new THREE.Vector3();点1.x = 0;point1.z = (y2/y1) * (d1 - d2)/(z2 - z1 * y2/y1);point1.y = (-z1 * point1.z - d1)/y1;var point2 = new THREE.Vector3();点2.x = 1;point2.z = (y2/y1) * (x1 * point2.x + d1) - (x2 * point2.x - d2)/(z2 - z1 * y2/y1);point2.y = (-z1 * point2.z - x1 * point2.x - d1)/y1;控制台日志(点1,点2);

输出:

THREE.Vector3 {x: -1, y: NaN, z: NaN, ...}三.Vector3 {x: 1, y: Infinity, z: -Infinity, ...}

预期输出:

  • 沿交点的点,其中 x = 0,并且
  • 同一条线上的另一个点,其中 x = 1

如果有人能向我指出这是如何工作的一个很好的解释,或者一个平面-平面相交算法的例子,我将不胜感激.

解决方案

很容易让three.js为你解决这个问题.

如果你用矩阵表示法来表达你的问题

m * x = v

那么 x 的解是

x = inverse( m ) * v

我们将对 m 使用 4x4 矩阵,因为 Three.js 有一个用于 Matrix4 类的 inverse() 方法.

var x1 = 0,y1 = 0,z1 = 1,d1 = 100;无功x2 = 1,y2 = 1,z2 = 1,d2 = -100;无功c = 0;//x 坐标的期望值var v = new THREE.Vector4( d1, d2, c, 1 );var m = new THREE.Matrix4( x1, y1, z1, 0,x2, y2, z2, 0,1, 0, 0, 0,0, 0, 0, 1);var minv = new THREE.Matrix4().getInverse(m);v.applyMatrix4(minv);控制台日志( v );

v 的 x 分量将根据需要等于 c,并且 y 和 z 分量将包含您要查找的值.w 分量无关紧要.

现在,重复 c 的下一个值,c = 1.

three.js r.58

I am trying to draw the line formed by the intersections of two planes in 3D, but I am having trouble understanding the math, which has been explained here and here.

I tried to figure it out myself, but the closest that I got to a solution was a vector pointing along the same direction as the intersection line, by using the cross product of the normals of the planes. I have no idea how to find a point on the intersection line, any point would do. I think that this method is a dead end. Here is a screenshot of this attempt:

I tried to use the solution mentioned in this question, but it has a dead link to the original explanation, and the equation didn't work for me (it has unbalanced parentheses, which I tried to correct below).

var planeA = new THREE.Plane((new THREE.Vector3(0, 0, 1)).normalize(), 100);
var planeB = new THREE.Plane((new THREE.Vector3(1, 1, 1)).normalize(), -100);

var x1 = planeA.normal.x,
    y1 = planeA.normal.y,
    z1 = planeA.normal.z,
    d1 = planeA.constant;

var x2 = planeB.normal.x,
    y2 = planeB.normal.y,
    z2 = planeB.normal.z,
    d2 = planeB.constant;

var point1 = new THREE.Vector3();
point1.x = 0;
point1.z = (y2 / y1) * (d1 - d2) / (z2 - z1 * y2 / y1);
point1.y = (-z1 * point1.z - d1) / y1;

var point2 = new THREE.Vector3();
point2.x = 1;
point2.z = (y2 / y1) * (x1 * point2.x + d1) - (x2 * point2.x - d2) / (z2 - z1 * y2 / y1);
point2.y = (-z1 * point2.z - x1 * point2.x - d1) / y1;

console.log(point1, point2);

output:

THREE.Vector3 {x: -1, y: NaN, z: NaN, …}
THREE.Vector3 {x: 1, y: Infinity, z: -Infinity, …}

expected output:

  • A point along the intersection where x = 0, and
  • Another point on the same line where x = 1

If someone could point me to a good explanation of how this is supposed to work, or an example of a plane-plane intersection algorithm, I would be grateful.

解决方案

It is easy to let three.js solve this for you.

If you were to express your problem in matrix notation

m * x = v

Then the solution for x is

x = inverse( m ) * v

We'll use a 4x4 matrix for m, because three.js has an inverse() method for the Matrix4 class.

var x1 = 0,
    y1 = 0,
    z1 = 1,
    d1 = 100;

var x2 = 1,
    y2 = 1,
    z2 = 1,
    d2 = -100;

var c = 0; // the desired value for the x-coordinate

var v = new THREE.Vector4( d1, d2, c, 1 );

var m = new THREE.Matrix4( x1, y1, z1, 0, 
                           x2, y2, z2, 0,
                           1,  0,  0,  0,
                           0,  0,  0,  1
                         );

var minv = new THREE.Matrix4().getInverse( m );

v.applyMatrix4( minv );

console.log( v );

The x-component of v will be equal to c, as desired, and the y- and z-components will contain the values you are looking for. The w-component is irrelevalent.

Now, repeat for the next value of c, c = 1.

three.js r.58

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

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