Skip to content

Spherical

[Spherical](/reference/math/spherical) coordinates (radius, phi, theta).

Represents a point in 3D using spherical coordinates:radius is the distance from the origin.phi is the azimuth angle (yaw) in radians.theta is the polar angle (pitch) from the equator in radians.

This is useful for orbital camera rigs, sampling directions on a sphere, and converting to/from Cartesian coordinates.

Properties

phi float

cpp
float phi { 0.0f }

Azimuth angle (yaw) in radians.

radius float

cpp
float radius { 1.0f }

Radial distance from the origin.

theta float

cpp
float theta { 0.0f }

Polar angle (pitch) in radians.

Functions

MakeSafe() auto

cpp
auto vglx::Spherical::MakeSafe()

Clamps theta (polar) away from the poles. Keeps theta within (-π/2 + ε, π/2 − ε) to avoid degeneracy where the azimuth angle becomes undefined and orientation calculations (e.g. cross products for basis vectors) can break down.

Spherical() constexpr

cpp
vglx::Spherical::Spherical(float radius, float phi, float theta)
ParameterDescription
radiusRadial distance from the origin.
phiAzimuth angle (yaw) in radians.
thetaPolar angle (pitch) in radians.

Constructs a spherical coordinate from radius, phi, and theta.

ToVector3() auto

cpp
auto vglx::Spherical::ToVector3() const

Converts spherical to Cartesian coordinates. Convention:phi (azimuth): 0 along +Z, increasing toward +X.theta (polar): 0 on the equator, +π/2 at +Y.

Released under the MIT License.