geoana.spatial.cylindrical_to_cartesian#

geoana.spatial.cylindrical_to_cartesian(grid, vec=None)#

Transform gridded locations or a set of vectors from cylindrical coordinates \((r, \phi, z)\) to Cartesian coordinates \((x, y, z)\). The azimuthal angle \(\phi\) is given in radians.

Parameters
grid(n, 3) array_like

Location points defined in cylindrical coordinates \((r, \phi, z)\).

vec(n, 3) array_like, optional

Vectors defined in cylindrical coordinates \((v_r, v_\phi, v_z)\) at the gridded locations. Will also except a flattend array in column major order with the same number of elements.

Returns
(n, 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 cylindrical coordinates to Cartesian coordinates.

>>> from geoana.spatial import cylindrical_to_cartesian
>>> import numpy as np

Construct original set of vectors in cylindrical coordinates

>>> r = np.ones(9)
>>> phi = np.linspace(0, 2*np.pi, 9)
>>> z = np.linspace(-4., 4., 9)
>>> u = np.c_[r, phi, z]
>>> u
array([[ 1.        ,  0.        , -4.        ],
       [ 1.        ,  0.78539816, -3.        ],
       [ 1.        ,  1.57079633, -2.        ],
       [ 1.        ,  2.35619449, -1.        ],
       [ 1.        ,  3.14159265,  0.        ],
       [ 1.        ,  3.92699082,  1.        ],
       [ 1.        ,  4.71238898,  2.        ],
       [ 1.        ,  5.49778714,  3.        ],
       [ 1.        ,  6.28318531,  4.        ]])

Create equivalent set of vectors in Cartesian coordinates

>>> v = cylindrical_to_cartesian(u)
>>> v
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]])