The idea: a circle rolling in a ring

A Spirograph is a toy: a toothed ring is pinned to the paper, a small toothed wheel rolls around inside it, and a pen through a hole in the wheel draws. The ring has radius R, the wheel radius r, and the pen hole sits at distance d from the wheel's centre. Rolling inside gives a hypotrochoid; rolling around the outside gives an epitrochoid.

A grey ring of radius R around O. A blue circle of radius r touches it from inside at an orange contact point. A grey line goes from O to the blue centre at angle t, and a purple arm of length d goes from the centre to the red pen, which has drawn part of a red curve
t is the angle of the rolling circle's centre; the pen is at distance d from that centre.

The formula

Two things move. The centre of the small circle goes around O on a circle of radius R − r (inside) or R + r (outside), at angle t. And the small circle spins. Because it rolls without slipping, the arc it rolls over on the ring, R·t, equals the arc of its own rim that touched the ring. Counting the spin in the fixed frame of the paper, the arm turns k times per turn of the centre:

inside:   x = (R − r) cos t + d cos(k t)    y = (R − r) sin t − d sin(k t)    k = (R − r)/r
outside:  x = (R + r) cos t − d cos(k t)    y = (R + r) sin t − d sin(k t)    k = (R + r)/r

The minus sign in y means: inside, the wheel spins the other way to its trip around the ring (clockwise while t goes counter-clockwise). Outside it spins the same way. With R = 10, r = 3 inside, k = 7/3: the centre goes around once while the wheel spins 2⅓ times backwards.

In complex numbers the pen is just the sum of two rotating arrows, (R − r)·eit + d·e−ikt: see Euler's Formula. Adding more arrows like this is how the epicycles on Fourier Series, Harmonic by Harmonic draw any closed curve.

When does the curve close?

After the centre has gone around n times, the arm has turned n·k = n·(R − r)/r times. The pen is back at its start only when both are whole numbers, that is when n·R/r is whole. The smallest such n is

turns to close = r / gcd(R, r)        points (loops, petals) = R / gcd(R, r)

The pen comes to the ring once every r/R of a turn, so in r/gcd turns it does that R/gcd times: the picture has R/gcd-fold symmetry. Dividing by the gcd matters: R = 8, r = 2 is really R = 4, r = 1, one turn and 4 points, not 8. (The gcd itself comes from Euclid's algorithm.)

Rrgcdturns to closepointsarm spins (inside)
10313107
822143
531352
11717114
1042253

(Demo: roll R = 10, r = 3, d = 5: at the end of turn 1 the centre is back but the pen is not; it closes after turn 3 with 10 loops. Demo: many loops: R = 11, r = 7, d = 9 needs 7 turns.) If r/R were irrational the curve would never close and would slowly fill a ring-shaped band.

What d does: smooth, cusps or loops

The pen's speed is the speed of the centre plus the speed of its spin around the centre. When the pen is on the ring side of the wheel these two point in opposite directions.

  • d < r: the spin part is smaller, the pen never stops: a smooth wavy curve.
  • d = r: the pen is on the rim. At the contact point the rim does not move (that is what rolling means), so the pen stops dead and turns back: a cusp on the ring. These curves are the hypocycloids and epicycloids.
  • d > r: the pen goes past the rim and the spin wins: the pen moves backwards for a moment and makes a loop that crosses itself.
Three curves for R = 10, r = 4 inside, 5 points each: d = 2 is a smooth five-lobed wave, d = 4 has five sharp cusps touching the ring, d = 7 is five long loops that cross each other and reach outside the ring
Same R and r, three pen distances: smooth (d < r), cusps (d = r), crossing loops (d > r).

(Demo: d < r, d = r, d > r (R = 10, r = 4).)

Curves with names

rollsR : rdcurve
inside3 : 1rdeltoid, 3 cusps
inside4 : 1rastroid, 4 cusps
inside5 : 3ra 5-point star drawn in 3 turns
inside2 : 1≠ ran ellipse
inside2 : 1ra straight line, a diameter (the Tusi couple)
outside1 : 1rcardioid, 1 cusp
outside2 : 1rnephroid, 2 cusps
outside1 : 1≠ ra limaçon
eitherany0a circle: the pen is the centre
Four curves with their rings: the deltoid with 3 cusps and the astroid with 4 cusps inside a ring, the cardioid with 1 cusp and the nephroid with 2 cusps around a ring
d = r: the deltoid and astroid roll inside, the cardioid and nephroid roll outside.

The R = 2r case is a surprise: the wheel is exactly half the ring, and every point of its rim moves back and forth on a straight line. (Demo: astroid, Demo: deltoid, Demo: 5-point star.) The cardioid also comes up in polar coordinates as r = 1 − cos θ: see Polar Coordinates.

Rolling outside: the coin paradox

Outside, k = (R + r)/r = R/r + 1. Roll one coin around another coin of the same size (R = r) and it turns twice, not once: once for the distance rolled, plus once because it went all the way round. That is why the cardioid demo's arm spins 2 times. (Demo: cardioid, Demo: nephroid.) The closing rule is the same: r/gcd turns, R/gcd points.

Counting points around a circle shows up again in rose curves r = cos(kθ), where k sets the number of petals: see Rose Curves and Maurer Roses.

What the page leaves out

Non-integer and irrational radii (the curve never closes), real Spirograph wheels counted in teeth (the same rule with tooth counts), the arc length and area of the curves, rolling on shapes that are not circles, and curves built from more than two rotating arms. R stays between 2 and 12 and r between 1 and 9.