Skip to content

Spherical

Represents a point in spherical coordinates.

Spherical stores a 3D position using (radius, phi, theta) where radius is the distance from the origin, phi is the azimuth angle around the Y-axis, and theta is the polar angle measured from the equatorial plane. This representation is commonly used for orbital camera rigs, direction sampling, and converting between angular and Cartesian representations.

Construction

Constructors


Spherical() constexpr

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

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

Properties

phi float

Azimuth angle around the Y-axis in radians.

cpp
float phi {0.0f};

radius float

Radial distance from the origin.

cpp
float radius {1.0f};

theta float

Polar angle from the equator in radians.

cpp
float theta {0.0f};

Functions

MakeSafe() void

Clamps the polar angle to avoid degeneracy at the poles.

Ensures theta stays within a safe range so azimuth calculations remain well-defined. If phi drifts outside it is wrapped back into range.

cpp
void Spherical::MakeSafe();

ToVector3() Vector3

Converts this spherical coordinate to a Vector3.

In this convention, phi equals 0 along the +Z axis and increases toward +X. The polar angle theta is 0 on the equator, reaches at +Y, and at -Y.

cpp
Vector3 Spherical::ToVector3() const;

Released under the MIT License.