vec2ang#

torchspin.vec2ang(v)[source]#

Convert a Cartesian 3-vector to polar angles (phi, theta).

Parameters:

v (array_like, shape (3,) or (3, N)) – Unit or non-unit Cartesian vector(s). Non-unit vectors are normalized internally.

Returns:

  • phi (float or ndarray) – Azimuthal angle(s) in radians, in [0, 2π).

  • theta (float or ndarray) – Polar angle(s) from +z axis, in [0, π].

Return type:

tuple

Notes

Matches EasySpin’s vec2ang.m convention: v = [sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta)].

Examples

>>> vec2ang([0, 0, 1])   # +z axis
(0.0, 0.0)
>>> vec2ang([1, 0, 0])   # +x axis
(0.0, 1.5707963...)