我正在尝试使用此wolfram页面底部的公式实现3平面交点:http://mathworld.wolfram.com/Plane-PlaneIntersection.html
If the three planes are each specified by a point xk and a unit normal vector
nk, then the unique point of intersection x is given by
x = (|n1 n2 n3|)^(-1) [(x1 · n1)(n2 x n3)+(x2 · n2)(n3 x n1)+(x3 · n3)(n3 x n2)],
where |n1 n2 n3| is the determinant of the matrix formed by writing the
vectors ni side-by-side. If two of the planes are parallel, then
|n1 n2 n3| = 0,
但这是我能得到的,我的矩阵数学很糟糕,而且我对three.js矩阵不太好
var x1, x2, x3; // all clones
var n1, n2, n3; // all clones, normalized
var f1 = (x1.dot(n1)).something(n2.cross(n3));
var f2 = (x2.dot(n2)).something(n3.cross(n1));
var f3 = (x3.dot(n3)).something(n1.cross(n2));
var full = f1.add(f2).add(f3);
首先,'(x1·n1)(n2 x n3)'应该是什么意思?我知道第一个是点积,该部分是交叉产品,我该怎么做才能将它们组合起来
其次,如何在three.js中编写矩阵部分
答案 0 :(得分:1)
首先:
(x1·n1)(n2 x n3)是什么意思?
点积(x1·n1)产生一个标量值,即x1与n1平行的分量。
叉积(n2 x n3)产生垂直于n2和n3的矢量。
因此,表达式(x1·n1)(n2 x n3)是矢量(n2 x n3),由标量(x1·n1)缩放/拉伸/拉长。
因此,在three.js中,计算变量f1,
var cross23 = new THREE.Vector3();
cross23.crossVectors(n2, n3); // stores the cross product (n2 x n3) in cross23
var scalar = x1.dot(n1);
var f1 = cross23;
f1.multiplyScalar(scalar);
第二
要计算行列式| n1 n2 n3 |,首先创建矩阵,我们称之为M.
var M = THREE.Matrix3();
现在,我们将设置M的组件作为文档规定(http://threejs.org/docs/#Reference/Math/Matrix3)。
M.set(n1.x, n1.y, n1.z, n2.x, n2.y, n2.z, n3.x, n3.y, n3.z);
最后,我们将计算矩阵的行列式。
var det = M.determinant();
第三
上面,我们展示了如何计算det,f1,f2和f3。现在,为了计算平面的交集,我们现在必须计算表达式det ^ -1 *(f1 + f2 + f3)。我们首先计算向量和f1 + f2 + f3,如下所示。
var vectorSum = new THREE.Vector3(0, 0, 0);
vectorSum.add(f1);
vectorSum.add(f2);
vectorSum.add(f3);
现在,通过行列式和矢量和,我们可以计算最终答案,特别是平面的交点。
var planeIntersection = new THREE.Vector3(vectorSum.x/det, vectorSum.y/det, vectorSum.z/det);
答案 1 :(得分:1)
这是一个随时可用的功能:
参数:平面p1,p2,p3
返回:Vector3
function vertIntersectPlanes(p1, p2, p3)
{
let n1 = p1.normal, n2 = p2.normal, n3 = p3.normal;
let x1 = p1.coplanarPoint(new THREE.Vector3());
let x2 = p2.coplanarPoint(new THREE.Vector3());
let x3 = p3.coplanarPoint(new THREE.Vector3());
let f1 = new THREE.Vector3().crossVectors(n2, n3).multiplyScalar(x1.dot(n1));
let f2 = new THREE.Vector3().crossVectors(n3, n1).multiplyScalar(x2.dot(n2));
let f3 = new THREE.Vector3().crossVectors(n1, n2).multiplyScalar(x3.dot(n3));
let det = new THREE.Matrix3().set(n1.x, n1.y, n1.z, n2.x, n2.y, n2.z, n3.x, n3.y, n3.z).determinant();
let vectorSum = new THREE.Vector3().add(f1).add(f2).add(f3);
let planeIntersection = new THREE.Vector3(vectorSum.x / det, vectorSum.y / det, vectorSum.z / det);
return planeIntersection;
}