Skip to content

ENH: Add to numpy simple functions for transform coordinate systems #5228

@espdev

Description

@espdev

It would be convenient to have these functions as a part of numpy mathematical routines.

cart2pol -- Transform Cartesian to polar coordinates

def cart2pol(x, y):
    theta = np.arctan2(y, x)
    rho = np.hypot(x, y)
    return theta, rho

pol2cart -- Transform polar to Cartesian coordinates

def pol2cart(theta, rho):
    x = rho * np.cos(theta)
    y = rho * np.sin(theta)
    return x, y

cart2sph -- Transform Cartesian to spherical coordinates

def cart2sph(x, y, z):
    hxy = np.hypot(x, y)
    r = np.hypot(hxy, z)
    el = np.arctan2(z, hxy)
    az = np.arctan2(y, x)
    return az, el, r

sph2cart -- Transform spherical to Cartesian coordinates

def sph2cart(az, el, r):
    rcos_theta = r * np.cos(el)
    x = rcos_theta * np.cos(az)
    y = rcos_theta * np.sin(az)
    z = r * np.sin(el)
    return x, y, z

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Completed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions