mach.geometry.spherical_to_cartesian#
- mach.geometry.spherical_to_cartesian(
- theta_rad: Real[Array, '*angles'] | float | int,
- phi_rad: Real[Array, '*angles'] | float | int,
- radius_m: Real[Array, '*angles'] | float | int = 1,
Convert standard spherical angle convention to a Cartesian vector.
Uses the physics convention as defined in ISO 80000-2:2019. https://en.wikipedia.org/wiki/Spherical_coordinate_system
- Parameters:
theta_rad – Polar angle in radians - angle between the radial line and a polar axis.
phi_rad – Azimuthal angle in radians - angle of rotation of the radial line around the polar axis.
radius_m – Radial distance from the origin in meters (defaults to 1 for unit vectors).
- Returns:
Wave-direction vectors in xyz-order, with norm=radius_m. For scalar inputs: returns tuple[float, float, float]. For array inputs: returns array with shape (*angles, 3).
- Raises:
ValueError – If any angle has magnitude >= π/2, suggesting possible unit confusion.
Examples
>>> # Convert physics spherical coordinates >>> import numpy as np >>> x, y, z = spherical_to_cartesian(np.pi/4, np.pi/3, 1) >>> print(f"Spherical to Cartesian: ({x:.3f}, {y:.3f}, {z:.3f})")