【发布时间】:2015-05-16 03:59:35
【问题描述】:
我需要在 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);
我使用 Spherical coordinate system 和 Cartesian to Spherical coordinates Calculator 来获取我的公式。
但是我不确定我是否将它们正确地翻译成代码。
【问题讨论】:
-
那么你有没有试过看看你是否得到了正确的结果?
-
代码原样无效,您需要 Math.* 在 sqrt、tan 和 sin 前面。运行代码看结果是否正确?
-
@K3N 我正在使用可汗学院版的 javascript。我的程序工作没有错误,但数学是错误的。在这里查看我的完整程序:khanacademy.org/computer-programming/…
-
@PoplopZord 啊,好的。我正在添加 khan-acedemy 的标签以使其更清晰。
-
@K3N 是的。我想我应该早点指定论坛的新手。
标签: javascript math