def sphericalToXYZ(lat,lon,radius=1):
'''
Convert spherical coordinates to x,y,z
@param lat: Latitude, scalar or array
@param lon: Longitude, scalar or array
@param radius: Sphere's radius
@return Numpy array of x,y,z coordinates
'''
phi = np.deg2rad(90.0 - lat)
theta = np.deg2rad(lon % 360)
x = radius * np.cos(theta)*np.sin(phi)
y = radius * np.sin(theta)*np.sin(phi)
z = radius * np.cos(phi)
if np.isscalar(x) == False:
return np.vstack([x,y,z]).T
else:
return np.array([x,y,z])
评论列表
文章目录