为了账号安全,请及时绑定邮箱和手机立即绑定

如何找到垂直于线中点的点的 3D 坐标

如何找到垂直于线中点的点的 3D 坐标

qq_遁去的一_1 2023-09-28 09:53:50
(我使用的是 Javascript/Typescript 和 Three.js)我在两个向量之间有一条直线{x:1, y:3, z:5},例如和{x:7, y:8, z:10}。在那条线的中点上,想象一个与该线垂直的圆盘(假设半径为 1)。我怎样才能得到那个假想圆盘的周界上的点?我知道有无限个点,但我只是想计算圆盘圆周上与线中点垂直的 1 个(任意)点。
查看完整描述

1 回答

?
慕桂英546537

TA贡献1848条经验 获得超10个赞

有很多方法可以做到这一点。一种不需要太多数学知识并让 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,但我认为这个父/子示例可以更清楚地说明该过程。



查看完整回答
反对 回复 2023-09-28
  • 1 回答
  • 0 关注
  • 53 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信