clouddrift.sphere.spherical_to_cartesian

clouddrift.sphere.spherical_to_cartesian#

clouddrift.sphere.spherical_to_cartesian(lon: float | list | ndarray | DataArray, lat: float | list | ndarray | DataArray, radius: float = 6378100.0) tuple[ndarray, ndarray, ndarray][source]#
Converts latitude and longitude on a spherical body to

three-dimensional Cartesian coordinates.

The Cartesian coordinate system is a right-handed system whose origin lies at the center of a sphere. It is oriented with the Z-axis passing through the poles and the X-axis passing through the point lon = 0, lat = 0. This function is inverted by cartesian_to_spherical().

Parameters#

lonarray-like

An N-d array of longitudes in degrees.

latarray-like

An N-d array of latitudes in degrees.

radius: float, optional

The radius of the spherical body in meters. The default assumes the Earth with EARTH_RADIUS_METERS = 6.3781e6.

Returns#

xfloat or array-like

x-coordinates in 3D in meters.

yfloat or array-like

y-coordinates in 3D in meters.

zfloat or array-like

z-coordinates in 3D in meters.

Examples#

>>> spherical_to_cartesian(np.array([0, 45]), np.array([0, 45]))
(array([6378100., 3189050.]),
array([      0., 3189050.]),
array([      0.        , 4509997.76108592]))
>>> spherical_to_cartesian(np.array([0, 45, 90]), np.array([0, 90, 180]), radius=1)
(array([ 1.00000000e+00,  4.32978028e-17, -6.12323400e-17]),
array([ 0.00000000e+00,  4.32978028e-17, -1.00000000e+00]),
array([0.0000000e+00, 1.0000000e+00, 1.2246468e-16]))
>>> x, y, z = spherical_to_cartesian(np.array([0, 5]), np.array([0, 5]))

Raises#

AttributeError

If lon and lat are not NumPy arrays.

See Also#

cartesian_to_spherical()