在three.js中寻找一束平面的交点(三) [英] Finding the intersection point of a bundle of planes (3) in three.js

查看:61
本文介绍了在three.js中寻找一束平面的交点(三)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此 wolfram 页面底部的公式来实现 3 平面交集:http://mathworld.wolfram.com/Plane-PlaneIntersection.html

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

推荐答案

这是一个随时可用的函数(从下面 robertl 的答案中组合而成):

Here's a ready to use function (assembled from the answer from robertl below):

参数:平面 p1,p2,p3返回:Vector3

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中寻找一束平面的交点(三)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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