球形极坐标对笛卡尔坐标转换

时间:2018-01-19 20:21:31

标签: python matplotlib scipy

有没有方法可以将数据集从球面极坐标系转换为python中的笛卡尔坐标系?

---请帮忙

2 个答案:

答案 0 :(得分:1)

查看维基百科https://en.wikipedia.org/wiki/Spherical_coordinate_system标准转换是:

enter image description here

你需要处于径向坐标(theta,phi)。如果不在theta和phi上使用math.radians

import math

def polar2cart(r, theta, phi):
    return [
         r * math.sin(theta) * math.cos(phi),
         r * math.sin(theta) * math.sin(phi),
         r * math.cos(theta)
    ]

答案 1 :(得分:0)

如果您不想编写自己的代码,请查看astropy包:http://docs.astropy.org/en/stable/coordinates/。具体来说,cartesian_to_spherical()spherical_to_cartesian()应该为您提供帮助。

相关问题