我需要在JavaScript中转换笛卡尔坐标系和球坐标系。
我浏览了一下论坛,但没有找到我需要的内容。
现在我有这个:
现在我有这个:
this.rho = sqrt((x*x) + (y*y) + (z*z));
this.phi = tan(-1 * (y/x));
this.theta = tan(-1 * ((sqrt((x * x) + (y * y)) / z)));
this.x = this.rho * sin(this.phi) * cos(this.theta);
this.y = this.rho * sin(this.phi) * sin(this.theta);
this.z = this.rho * cos(this.phi);
我使用了球坐标系和直角坐标系转球坐标系计算器来获取我的公式。
但是我不确定我是否正确地将它们翻译成了代码。