问题
I translated the MATLAB cart2sph and sph2cart functions to python in this way.
import numpy as np
def cart2sph(x,y,z):
azimuth = np.arctan2(y,x)
elevation = np.arctan2(z,np.sqrt(x**2 + y**2))
r = np.sqrt(x**2 + y**2 + z**2)
return azimuth, elevation, r
def sph2cart(azimuth,elevation,r):
x = r * np.cos(elevation) * np.cos(azimuth)
y = r * np.cos(elevation) * np.sin(azimuth)
z = r * np.sin(elevation)
return x, y, z
I didn't find any library in numpy that translate the MATLAB change of coordinates so I write them for my self. Is there in numpy a more efficient way in terms of execution time to write this fuctions?
来源:https://stackoverflow.com/questions/30084174/efficient-matlab-cart2sph-and-sph2cart-functions-in-python