我需要在 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);
Run Code Online (Sandbox Code Playgroud)
我使用球坐标系和笛卡尔到球坐标计算器来计算我的公式。
但是我不确定我是否正确地将它们翻译成代码。