Efficient MATLAB cart2sph and sph2cart functions in python

僤鯓⒐⒋嵵緔 提交于 2020-01-04 15:30:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!