【问题标题】:How to find 3D coordinates of point perpendicular to line's mid point如何找到垂直于线中点的点的 3D 坐标
【发布时间】:2021-03-13 19:24:54
【问题描述】:

(我正在使用 Javascript/Typescript 和 Three.js)

我在两个向量之间有一条直线,比如{x:1, y:3, z:5}{x:7, y:8, z:10}

在那条线的中点上,想象一个与该线垂直的圆盘(比如半径为 1)。

我怎样才能在那个假想圆盘的圆周上得到一个点

我知道有无限的点,但我只是想计算圆盘圆周上的 1(任意)点,并垂直连接到线的中点。

【问题讨论】:

标签: javascript typescript three.js


【解决方案1】:

有很多方法可以做到这一点。一个简单的方法,只需要很少的数学,让 Three.js 处理繁重的工作是使用嵌套在另一个内部的Object3D:子对象是“环”,父对象将环移动到中点和“向下看,使其垂直。

// Create end vectors
var v1 = new THREE.Vector3(1, 3, 5);
var v2 = new THREE.Vector3(7, 8, 10);

// Get midpoint
var mid = new THREE.Vector3();
mid.addVectors(v1, v2);
mid.multiplyScalar(0.5);

// Nest child object inside parent
var parent = new THREE.Object3D();
var child = new THREE.Object3D();
parent.add(child);

// Set child position to any point in the XY plane with radius = 1
// This is a point in your "disc"
child.position.set(0, 1, 0);

// Move parent to midpoint
parent.position.copy(mid);

// Rotate parent to look towards end of the line
// This makes the "disc" perpendicular to the line
parent.lookAt(v1);

// Get world position of child 
var discPoint = new THREE.Vector3();
child.getWorldPosition(discPoint);
console.log(discPoint);

child 的本地位置仍然是[0, 1, 0],但是在平移和旋转父级之后,世界位置就是您要寻找的答案。或者,您可以简单地使用Object3D.localToWorld,但我认为这个父/子示例将更清楚地说明该过程。

【讨论】:

  • 可爱,非常感谢您抽出宝贵的时间来完成这些步骤!
猜你喜欢
  • 2022-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
相关资源
最近更新 更多