wulfric.geometry.get_spherical#

wulfric.geometry.get_spherical(vector, in_degrees=True, polar_axis=[0, 0, 1], radial_line_zero=[1, 0, 0])[source]#

Compute spherical coordinates of a vector.

\((v^x, v^y, v^z) \rightarrow (r, \theta, \phi)\)

Parameters:
vector(3,) array-like

Vector to be converted.

in_degreesbool, default True

Whether to return angles in degrees or radians. If True, then angles are returned in degrees.

polar_axis(3,) array-like

Polar axis (see notes). By default oriented along \(+z\).

radial_line_zero(3,) array-like

Zero of the radial line (see notes). By default oriented along \(+x\).

Returns:
rfloat

Length of the vector.

polar_anglefloat

Polar angle. Returned in degrees if in_degrees = True, in radians otherwise.

azimuthal_anglefloat

Azimuthal angle. Returned in degrees if in_degrees = True, in radians otherwise.

Notes

polar_angle is defined as the angle between the polar axis and the given vector with \(0 \le \alpha_{polar} \le \pi\).

Azimuthal angle is defined as the angle of the rotation of the radial line around the polar axis. This angle is measured from the radial_line_zero in accordance to the right-hand rule. \(0 \le \alpha_{azimuthal} \le 2\pi\).

Radial line is the projection of the vector on the plane perpendicular to the polar_axis.

If azimuthal angle is ill-defined, then wulfric returns

  • \(0\) if polar angle is \(0\).

  • \(\pi\) if polar angle is \(\pi\).

Examples

>>> import wulfric
>>> wulfric.geometry.get_spherical([1, 0, 0])
(1.0, 90.0, 0.0)
>>> wulfric.geometry.get_spherical([-1, 0, 0])
(1.0, 90.0, 180.0)
>>> wulfric.geometry.get_spherical([0, 1, 0])
(1.0, 90.0, 90.0)
>>> wulfric.geometry.get_spherical([0, -1, 0])
(1.0, 90.0, 270.0)
>>> wulfric.geometry.get_spherical([0, 0, 1])
(1.0, 0.0, 0.0)
>>> wulfric.geometry.get_spherical([0, 0, -1])
(1.0, 180.0, 180.0)
>>> wulfric.geometry.get_spherical([1, 0, 0], polar_axis=[1, 0, 0])
(1.0, 0.0, 0.0)