def cartesian_to_spherical(x,degrees=True,normalize=False):
'''
Coverts a cartesian vector in R3 to spherical coordinates
'''
r = np.linalg.norm(x)
theta = np.arccos(x[2]/r)
phi = np.arctan2(x[1],x[0])
if degrees:
theta = np.degrees(theta)
phi = np.degrees(phi)
s = [r,theta,phi]
if normalize:
s /= np.linalg.norm(s)
return s
评论列表
文章目录