ENH: Add to numpy simple functions for transform coordinate systems
See original GitHub issueIt 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:
- Created 9 years ago
- Reactions:38
- Comments:17 (14 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.