question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: Add to numpy simple functions for transform coordinate systems

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:38
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

14reactions
espdevcommented, Oct 24, 2014

I understand what you are talking about. However, these functions are used very often while working with the coordinate systems in geometric algorithms, computer graphics software, etc. Generalization on n-dimensions is required infrequently. In MATLAB these functions exist and, I should say, they are rather convenient. I consider these functions as simple mathematical routines, for example, functions rad2deg and deg2rad. These functions, as you know, are frequently used functions and exist in numpy.

7reactions
juliantaylorcommented, Oct 24, 2014

I’m not sure this is something that needs to be in numpy, the functions are simple enough to implement yourself optimally. If we add them were do we draw the line on which transformations to add? there are an infinite amount of them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.fromfunction — NumPy v1.24 Manual
Construct an array by executing a function over each coordinate. The resulting array therefore has a value fn(x, y, z) at coordinate (x,...
Read more >
Transforming the coordinate system and calculating the area ...
Now, the objective is to know how much area is occupied by each country. However, the coordinates of country borders are expressed in...
Read more >
transformations — tf 0.1.0 documentation
A library for calculating 4x4 matrices for translating, rotating, reflecting, scaling, shearing, projecting, orthogonalizing, and superimposing arrays of 3D ...
Read more >
Numpy - Transformations between coordinate systems
I'd recommend reading this and this. For the first one, look at the concept of homogenous coordinates, as for spatial transforms with ...
Read more >
transformations - PyPI
Matrices (M) can be inverted using numpy.linalg.inv(M), be concatenated using numpy.dot(M0, M1), or transform homogeneous coordinate arrays (v) using numpy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found