Instead of (x, y), polar coordinates describe a point with:
r — the "radius" or radial distance from the origin (the "pole")
θ — the angle, measured counter-clockwise from the positive X axis (the "polar axis"). Positive is counter-clockwise.
Point: (r, θ)
Polar coordinates are natural when you care about distance and direction rather than x/y offsets — radar sweeps, orbit paths, and circular spawn patterns are all more cleanly expressed in polar form.
2
Aliasing & Canonical Coordinates
For any given point there are infinitely many polar coordinate pairs that describe it. This is known as aliasing:
For any integer k, all aliases of (r, θ) are given by:
(-1)ᵏ · r, θ + k·180°
Canonical Coordinates
Canonical coordinates are the "preferred" unique alias. They follow these rules:
r ≥ 0
-180° < θ ≤ 180°
If r = 0, then θ = 0
3
2D Coordinate Conversion
Polar → Cartesian
x = r · cos θ
y = r · sin θ
Cartesian → Polar
r = √(x² + y²)
θ = atan2(y, x)
What is atan2?
Basic trig gives θ = arctan(y/x), but this has two problems: division by zero when x = 0, and the result is locked to [−90°, 90°]. atan2(y, x) solves both by branching on the signs of x and y:
atan2(y, x) = {
0 if x = 0, y = 0
90° if x = 0, y > 0
-90° if x = 0, y < 0
arctan(y/x) if x > 0
arctan(y/x) + 180° if x < 0, y ≥ 0
arctan(y/x) - 180° if x < 0, y < 0
}
In C++ / game engines: std::atan2(y, x) returns radians in the range (−π, π]. This is the standard function for converting a 2D direction vector to an angle. Note the argument order: y first, x second.
4
3D Polar: Cylindrical Coordinates
Extend 2D polar into 3D by adding a linear Z axis. A point in cylindrical space is (r, θ, z):
r — same as 2D polar radial distance (from the Z axis)
θ — same as 2D polar angle (around the Z axis)
z — how far "up" or "down" along the cylinder's axis
Think of it as choosing which horizontal "slice" of the cylinder you're on (z), then using 2D polar within that slice (r, θ).
Cylindrical → Cartesian:
x = r·cos θ
y = r·sin θ
z = z
Cartesian → Cylindrical:
r = √(x² + y²)
θ = atan2(y, x)
z = z
5
3D Polar: Spherical Coordinates
The most common 3D polar form. Uses two angles to specify direction and one value for distance:
r — same as 2D polar
θ — same as 2D polar (azimuthal angle, around the vertical axis)
φ — the polar angle (elevation). Starts pointing straight up (+Y) and measures the angle downward. In math convention, φ = 0 is straight up.
Point: (r, θ, φ)
Spherical → Cartesian:
x = r·sin φ·cos θ
y = r·cos φ
z = r·sin φ·sin θ
Cartesian → Spherical:
r = √(x² + y² + z²)
θ = atan2(x, z)
φ = arcsin(-y / r) (works with canonical conversions)
6
Spherical Coordinates for Games
Standard math spherical coordinates aren't ideal for games because:
The default direction is +X, not +Z (forward)
2D and 3D don't transfer cleanly ((r,θ) → (r,θ,90°) doesn't map naturally)
The θ/φ symbol names are non-intuitive
Math convention assumes a right-handed system; games often use left-handed
Game engines remap the angles into more intuitive terms:
Heading (h)
Renamed from θ
Starts facing forward (+Z in most game engines)
Positive rotation is clockwise (left-handed)
Pitch (p)
Renamed from φ
Starts at the origin; measures how much we look up or down
Positive rotation is downward (left-handed)
Canonical Spherical Coordinates for Games
r ≥ 0
-180° < h ≤ 180°
-90° ≤ p ≤ 90°
Special case: if |p| = 90° → h = 0 (dealing with aliasing at poles)
Heading and pitch appear constantly in game dev: camera rotation, character look direction, AI facing, turret elevation. They're also the basis for Euler angles (heading = yaw, pitch = pitch, bank = roll).
7
3D Coordinate Conversion
Spherical (Game Convention) → Cartesian
x = r·cos p·sin h
y = -r·sin p
z = r·cos p·cos h
Cartesian → Spherical (Game Convention)
r = √(x² + y² + z²)
h = atan2(x, z)
p = arcsin(-y / r)
The negative sign on y in the pitch formulas accounts for the left-handed convention where positive pitch looks downward.
8
Exercises
1. Polar → Cartesian
Convert (r=5, θ=60°) to Cartesian coordinates.
x = 5·cos 60° = 5·0.5 = 2.5. y = 5·sin 60° = 5·(√3/2) ≈ 4.33. Result: (2.5, 4.33).
A unit vector pointing forward and slightly down: (0, -sin15°, cos15°). Find its heading and pitch.
h = atan2(x, z) = atan2(0, cos15°) = 0° (straight ahead). p = arcsin(-y/r) = arcsin(sin15°) = 15° (pitching down).
Interview Question
What is aliasing in polar coordinates, and how is it resolved?
Multiple polar coordinate pairs can describe the same point: (1, 45°) and (1, 405°) are identical, as are (1, 45°) and (-1, -135°). This creates ambiguity in interpolation and storage. It's resolved by defining canonical coordinates — restricting r ≥ 0 and θ to (−180°, 180°] — so each point has exactly one representation.
Interview Question
Why do game engines use heading/pitch instead of standard θ/φ for representing 3D directions?
Standard spherical coordinates use a right-handed system with +Y as the pole and measure angles from the top down, which doesn't match how artists think or how typical game coordinate systems work. Heading/pitch maps naturally to "look left/right" and "look up/down," uses the engine's native handedness, and transfers cleanly from the 2D case (heading is just the 2D polar angle on the ground plane).