计算的起源和X,Y之间的θ和Ø角度,Z坐标 [英] Calculate θ and ø angles between origin and x,y,z coordinate
问题描述
我使用 three.js 一个小的3D POC项目。下面的代码片段计算出新的X,Y,在轨道上绕原点的3D对象z位置(0,0,0):
I'm using three.js for a small 3D POC project. The following snippet calculates the new x,y,z position for a 3D object in orbit around the origin (0,0,0):
x = rho * Math.cos(theta) * Math.sin(phi);
y = rho * Math.sin(theta) * Math.sin(phi);
z = rho * Math.cos(phi);
在上面的例子中,的 THETA 的和的披的是已知的,用于计算新的x,y,z坐标轨道三维主体。
In the above example, theta and phi are known and used to calculate the new x,y,z coordinate for the orbiting 3D subject.
以上的作品很好,但我也希望做相反的。
The above works well, but I also want to do the inverse.
我如何去计算的 THETA 和披的,如果我只有一个X,Y,Z点,所有这一切相对于原点(0, 0,0)?
How do I go about calculating theta and phi, if I only have an x,y,z point, this all in relation to the origin point (0,0,0)?
推荐答案
IIRC
r = Math.sqrt(x*x + y*y + z*z);
θ = Math.acos(z/r);
φ = Math.atan2(y, x);
x = r * Math.sin(θ) * Math.cos(φ);
y = r * Math.sin(θ) * Math.sin(φ);
z = r * Math.cos(θ);
您似乎有你的θ
和φ
各地交换的其他方式(这仅仅是一个符号选择)
You seem to have your θ
and φ
swapped the other way around (which is just a notation choice)
这篇关于计算的起源和X,Y之间的θ和Ø角度,Z坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!