计算原点与 x,y,z 坐标之间的 θ 和 ø 角度 [英] Calculate θ and ø angles between origin and x,y,z coordinate

查看:52
本文介绍了计算原点与 x,y,z 坐标之间的 θ 和 ø 角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 three.js 用于一个小型 3D POC 项目.以下代码段计算绕原点 (0,0,0) 轨道上的 3D 对象的新 x,y,z 位置:

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);

在上面的例子中,thetaphi 是已知的,用于计算轨道 3D 对象的新 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.

我如何计算 thetaphi,如果我只有一个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆