geoana.spatial.cartesian_to_cylindrical#
- geoana.spatial.cartesian_to_cylindrical(grid, vec=None)#
Transform gridded locations or a set of vectors from Cartesian coordinates \((x, y, z)\) to cylindrical coordinates \((r, \phi, z)\). Where the azimuthal angle \(\phi \in [-\pi , \pi ]\) will be given output in radians.
- Parameters:
- grid(…, 3) array_like
Gridded locations defined in Cartesian coordinates \((x, y z)\).
- vec(…, 3) array_like, optional
Vectors defined in Cartesian coordinates \((v_x, v_y, v_z)\) at the gridded locations. Also accepts a flattened array with the same total elements in column major order.
- Returns:
- (…, 3) numpy.ndarray
If vec is
None
, this returns the transformed grid array, otherwise this is the transformed vec array.
Examples
Here, we convert a series of vectors in 3D space from Cartesian coordinates to cylindrical coordinates.
>>> from geoana.spatial import cartesian_to_cylindrical >>> import numpy as np
Create set of vectors in Cartesian coordinates
>>> r = np.ones(9) >>> phi = np.linspace(0, 2*np.pi, 9) >>> z = np.linspace(-4., 4., 9) >>> x = r*np.cos(phi) >>> y = r*np.sin(phi) >>> u = np.c_[x, y, z] >>> u array([[ 1.00000000e+00, 0.00000000e+00, -4.00000000e+00], [ 7.07106781e-01, 7.07106781e-01, -3.00000000e+00], [ 6.12323400e-17, 1.00000000e+00, -2.00000000e+00], [-7.07106781e-01, 7.07106781e-01, -1.00000000e+00], [-1.00000000e+00, 1.22464680e-16, 0.00000000e+00], [-7.07106781e-01, -7.07106781e-01, 1.00000000e+00], [-1.83697020e-16, -1.00000000e+00, 2.00000000e+00], [ 7.07106781e-01, -7.07106781e-01, 3.00000000e+00], [ 1.00000000e+00, -2.44929360e-16, 4.00000000e+00]])
Compute equivalent set of vectors in cylindrical coordinates
>>> v = cartesian_to_cylindrical(u) >>> v array([[ 1.00000000e+00, 0.00000000e+00, -4.00000000e+00], [ 1.00000000e+00, 7.85398163e-01, -3.00000000e+00], [ 1.00000000e+00, 1.57079633e+00, -2.00000000e+00], [ 1.00000000e+00, 2.35619449e+00, -1.00000000e+00], [ 1.00000000e+00, 3.14159265e+00, 0.00000000e+00], [ 1.00000000e+00, -2.35619449e+00, 1.00000000e+00], [ 1.00000000e+00, -1.57079633e+00, 2.00000000e+00], [ 1.00000000e+00, -7.85398163e-01, 3.00000000e+00], [ 1.00000000e+00, -2.44929360e-16, 4.00000000e+00]])