Polar Coordinates
Polar coordinates locate a point by its distance from the origin and its angle, instead of by and . Circles centred at the origin, spirals, roses and orbits all have far simpler equations in polar form. This lesson covers conversion (including the atan2 detail that trips up programmers), graphing and symmetry, and tangent lines to polar curves.
Definition
Choose a point (the pole) and a ray from it (the polar axis, usually the positive -axis). A point has polar coordinates when it is at distance from along the ray that makes angle with the polar axis, measured anticlockwise. Two conventions make every pair meaningful:
- and are the same point, for every integer ;
- a negative means "go in the opposite direction": .
So, unlike Cartesian coordinates, every point has infinitely many polar representations, and the pole is for any . This non-uniqueness is the source of most polar pitfalls, such as missing intersection points of two curves.
Converting
The second column does not determine by itself: gives the same value for and . only returns angles in , so you must pick the quadrant from the signs of and . Every programming language provides this as atan2(y, x), which returns the correct angle in (see atan2).
import math
points = [(1, 1), (-1, -1), (-3, 4), (0, -2)]
for x, y in points:
naive = math.atan(y / x) if x != 0 else float("nan")
th = math.atan2(y, x)
r = math.hypot(x, y)
back = (round(r * math.cos(th), 12) + 0.0, round(r * math.sin(th), 12) + 0.0)
print(f"({x:2}, {y:2}): r = {r:.4f}, atan2 = {math.degrees(th):8.3f}°, "
f"atan(y/x) = {math.degrees(naive):8.3f}°, back to {back}")( 1, 1): r = 1.4142, atan2 = 45.000°, atan(y/x) = 45.000°, back to (1.0, 1.0)
(-1, -1): r = 1.4142, atan2 = -135.000°, atan(y/x) = 45.000°, back to (-1.0, -1.0)
(-3, 4): r = 5.0000, atan2 = 126.870°, atan(y/x) = -53.130°, back to (-3.0, 4.0)
( 0, -2): r = 2.0000, atan2 = -90.000°, atan(y/x) = nan°, back to (0.0, -2.0)
For the naive formula returns 45°, a point in the first quadrant, while atan2 correctly returns −135°.
Polar curves
A polar curve is the set of points whose polar coordinates satisfy an equation, usually . Converting is often the quickest way to recognise one:
| Polar | Cartesian | Curve |
|---|---|---|
| circle, centre | ||
| line through | ||
| circle through (multiply by : ) | ||
| vertical line | ||
| cardioid | ||
| — | rose with petals ( odd) or petals ( even) | |
| — | Archimedean spiral: equally spaced turns | |
| — | logarithmic spiral: crosses every ray at the same angle |
Symmetry tests (sufficient, not necessary):
- unchanged when : symmetric about the polar axis (-axis);
- unchanged when , or when : symmetric about the pole;
- unchanged when : symmetric about the line (-axis).
Why the rose has or petals. For with odd, , so the second half-turn retraces the first half: only petals appear. For even, while the point is opposite , so the second half draws new petals: in total.
import numpy as np
import matplotlib.pyplot as plt
def polar_xy(th, r): # apply the (−r, θ) = (r, θ + π) rule
return np.where(r < 0, th + np.pi, th), np.abs(r)
th = np.linspace(0, 2 * np.pi, 2000)
fig, axes = plt.subplots(1, 3, figsize=(10, 3.8), subplot_kw={"projection": "polar"})
axes[0].plot(*polar_xy(th, np.cos(3 * th))); axes[0].set_title("r = cos 3θ (3 petals)")
axes[1].plot(*polar_xy(th, np.cos(4 * th))); axes[1].set_title("r = cos 4θ (8 petals)")
t6 = np.linspace(0, 6 * np.pi, 3000)
axes[2].plot(t6, 0.5 * t6, label="r = θ/2")
axes[2].plot(t6, np.exp(0.15 * t6) - 1, label="r = e^(0.15θ) − 1")
axes[2].set_title("spirals"); axes[2].legend(loc="upper center", bbox_to_anchor=(0.5, -0.12), fontsize=7)
for ax in axes:
ax.set_rlim(0, None); ax.set_yticklabels([])
plt.tight_layout(); plt.show()
# Matplotlib does not apply the negative-r rule itself, so polar_xy does it
print("r = cos 3θ is negative on", round(float(np.mean(np.cos(3 * th) < 0)) * 100), "% of [0, 2π]")r = cos 3θ is negative on 50 % of [0, 2π]
Tangents to polar curves
Treat as a parameter: , . With , the parametric slope formula gives
At the pole (, ) this collapses to : the curve passes through the pole along the ray at angle . For the rose , the zeros are exactly the directions in which the petals meet at the centre.
import sympy as sp
th = sp.symbols("theta", real=True)
r = 1 + sp.cos(th) # cardioid
x, y = r * sp.cos(th), r * sp.sin(th)
slope = sp.simplify(y.diff(th) / x.diff(th))
print("dy/dx =", slope)
print("slope at θ = π/3:", sp.simplify(slope.subs(th, sp.pi / 3)))
print("horizontal tangents:", sp.solve(sp.Eq(y.diff(th), 0), th))
print("vertical tangents: ", sp.solve(sp.Eq(x.diff(th), 0), th))
print("at θ = π: dx/dθ =", x.diff(th).subs(th, sp.pi), ", dy/dθ =", y.diff(th).subs(th, sp.pi))dy/dx = -(cos(theta) + cos(2*theta))/(sin(theta) + sin(2*theta))
slope at θ = π/3: 0
horizontal tangents: [-pi/3, pi/3]
vertical tangents: [0, -2*pi/3, 2*pi/3]
at θ = π: dx/dθ = 0 , dy/dθ = 0
By hand, and , so both also vanish at , a root SymPy's lists happen to leave out (always check candidate points by substitution; the slope formula is there). The last line confirms it: is the cusp of the cardioid at the pole, not a horizontal or vertical tangent.
In software
- Radial menus, gauges and pie charts place items at and find the item under the mouse with
atan2. - Bullet-hell and particle patterns are polar curves: rotate the emission angle by a constant each frame and you get a spiral; modulate radius by and you get a rose.
- Shaders convert UVs to polar coordinates (
length(uv),atan(uv.y, uv.x)) to draw rings, radar sweeps and kaleidoscopes. - Procedural generation: spiral galaxies use logarithmic spirals; sunflower-style point layouts use , .
- Signal processing: complex numbers in polar form (magnitude and phase) are the language of the FFT.
Exercises
Exercise 1: Convert to Cartesian
Convert the point to Cartesian coordinates and give one other polar representation with negative .
Answer
; for example .
Solution
Exercise 2: Identify the curve
Show that is a circle and find its centre and radius.
Answer
Circle with centre and radius 3.
Solution
(Multiplying by adds only the pole, which is already on the curve at .)
Exercise 3: Polar angle in code
Write a function that returns the polar angle of in degrees in , and test it on , , and .
Answer
90.0, 180.0, 315.0, 240.0
Solution
atan2 returns ; add 360 and reduce mod 360. For : , the reference angle is 60° and the point is in the third quadrant, so 240°.
import math
def polar_deg(x, y):
return round(math.degrees(math.atan2(y, x)) % 360, 9)
print([polar_deg(*p) for p in [(0, 1), (-1, 0), (1, -1), (-2, -2 * math.sqrt(3))]])[90.0, 180.0, 315.0, 240.0]
Exercise 4: Petals and tangents at the pole
How many petals does have, and in which directions does the curve pass through the pole for ?
Answer
5 petals; through the pole at .
Solution
is odd, so the curve has 5 petals (the interval already draws them all). At the pole , i.e. , so ; since there, the tangent at the pole is the ray at that angle.
Test yourself
Which polar coordinates describe the same point as ?
Why do programs use atan2(y, x) instead of atan(y/x) to get the polar angle?
- It is faster
- It picks the correct quadrant and handles
- It returns degrees
- It returns as well
How many petals does have?
- 3
- 6
- 12
- 24