【问题标题】:How to get the y angle between 2 vectors in Three.js?如何在 Three.js 中获得 2 个向量之间的 y 角?
【发布时间】:2022-01-26 04:33:57
【问题描述】:

在 Three.js 中,我有 2 个 3d 向量,我想找到它们之间的 x 轴和 y 轴角度。

对于 x 轴我找到了这个

toDegrees(atan2(A.z, A.y) - atan2(B.z, B.y))

来自 The X angle between two 3D vectors?

这可行,但对于 y 轴,我正在尝试

toDegrees(atan2(A.z, A.x) - atan2(B.z, B.x))

但它给了我错误的价值。我该如何解决这个问题?

谢谢

【问题讨论】:

  • 哪里错了?震级?符号?你能举两个向量的例子,你期望的结果,你收到的结果吗?

标签: javascript three.js linear-algebra angle euler-angles


【解决方案1】:

你可以直接使用Vector3.angleTo,它会给你以弧度为单位的角度,就像数学函数一样,这里我以度为单位打印(乘以180 degrees/pi rad= 1

// notice that v1 is pointing to the x-axis direction.
const v1 = new THREE.Vector3(10,0,0);
const v2 = new THREE.Vector3(3,3,0);
const v3 = new THREE.Vector3(0, 50, 23);
// Alngle between v1 and v2
console.log(v1.angleTo(v2)*180/Math.PI)
// The operation is comutative
console.log(v2.angleTo(v1)*180/Math.PI)
// An example at 90 degree
console.log(v1.angleTo(v3)*180/Math.PI)
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>

这使得找到任何方向的角度成为可能,例如,如果您想要与平面的角度,它由 ans(a - 90) 给出,其中 a 是与平面法向量的角度。

【讨论】:

    猜你喜欢
    • 2011-03-14
    • 1970-01-01
    • 2022-11-03
    • 2011-01-30
    • 2017-03-22
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 2014-10-01
    相关资源
    最近更新 更多