utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:autolab_core 作者: BerkeleyAutomation 项目源码 文件源码
def cart2sph(x, y, z):
    """ Convert cartesian to spherical coordinates.

    Attributes
    ----------
    x : float
        x-coordinate
    y : float
        y-coordinate
    z : float
        z-coordinate

    Returns
    -------
    float
        radius
    float
        aziumth
    float
        elevation
    """
    r = np.sqrt(x**2 + y**2 + z**2)
    if x > 0 and y > 0:
        az = np.arctan(y / x)
    elif x > 0 and y < 0:
        az = 2*np.pi - np.arctan(-y / x)
    elif x < 0 and y > 0:
        az = np.pi - np.arctan(-y / x)    
    elif x < 0 and y < 0:
        az = np.pi + np.arctan(y / x)    
    elif x == 0 and y > 0:
        az = np.pi / 2
    elif x == 0 and y < 0:
        az = 3 * np.pi / 2
    elif y == 0 and x > 0:
        az = 0
    elif y == 0 and x < 0:
        az = np.pi
    elev = np.arccos(z / r)
    return r, az, elev
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号