亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何找到垂直于線中點的點的 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 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號