在three.js中找到一捆平面(3)的交点 [英] Finding the intersection point of a bundle of planes (3) in three.js
问题描述
我正在尝试使用此Wolfram页面底部的公式来实现3平面相交:
I'm Trying to implement 3-plane intersection using the formula at the bottom of this wolfram page here: 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矩阵我不太满意
But this is as far as I can get, my matrix math is awful and I'm not that good with three.js matrices
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)"应该是什么意思?我知道第一个是点积,本节是叉积,我该怎么做才能将它们结合起来
First off, what is '(x1 · n1)(n2 x n3)' supposed to mean? I know the first one is dot product and the section is cross product, what do I do to combine them
第二,如何在Three.js中编写矩阵部分
Second, how do I write the matrix portion in three.js
推荐答案
以下是随时可用的功能:
参数:平面p1,p2,p3返回:Vector3
Here's a ready to use function:
arguments: Planes p1,p2,p3
return: 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;
}
这篇关于在three.js中找到一捆平面(3)的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!