Spirograph¶
By the end of this lab you'll be able to:
- Plot a hypotrochoid (inner rolling circle) using parametric equations
- Understand how
R,r, anddcontrol the petal and loop count - See how the ratio
R/rdetermines when the curve closes
A Spirograph pattern — the curves made by a rolling circle inside a larger circle. Changing the three parameters R (outer radius), r (inner radius), and d (pen distance from center) produces hundreds of different patterns.
Welcome to the Spirograph!
Spirographs were a famous toy in the 1970s — now you can code one!
A small circle rolls inside a big circle, with a pen attached to the small circle.
The result: beautiful looping curves called hypotrochoids. Let's code it!
How It Works¶
x(t) = (R-r)*cos(t) + d*cos((R-r)/r * t)
y(t) = (R-r)*sin(t) - d*sin((R-r)/r * t)
R is the outer circle radius, r the inner, d the pen offset from the inner center.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
What Do You Think Will Happen?
R/r = 130/50 = 2.6. The curve loops R/r times — approximately how many petals?
Make your guess — then click Run to find out!
Try It Now¶
A looping Spirograph curve — the inner circle rolls around 2.6 times for each full orbit, creating overlapping loops. Were you right?
How It Works¶
When R/r is a ratio of small integers (like 5/2), the curve closes perfectly after a small number of loops. When it's not a simple fraction, the curve takes many loops to close — or never closes at all.
Explanation Table¶
| Line | What it does |
|---|---|
R = 130 |
Outer circle radius |
r = 50 |
Inner rolling circle radius |
d = 90 |
Pen distance from inner center |
(R-r)*cos(t) + d*cos(...) |
Parametric x position |
steps * r |
More loops for larger inner circles |
Learning Check¶
Your Turn — Use Exact Integers
Change to R=100, r=40, d=70. This gives R/r = 5/2 exactly — a ratio of small integers.
The curve should close perfectly after 2 orbits and have 5 petals. Predict and run!
R/r = 100/40 = 5/2 → a perfect 5-petaled hypotrochoid that closes cleanly after 2 orbits.
Experiments¶
-
Try R=120, r=30 (ratio 4:1). You'll know it worked when a 4-lobed curve appears.
-
Change d to a very small value. Try
d = 10. You'll know it worked when the curve looks almost circular. -
Change d larger than r. Try
d = 120with the original parameters. You'll know it worked when the inner loops become larger. -
Try an epitrochoid (circle rolling outside). Change
(R - r)to(R + r)in the formula. You'll know it worked when a different style of looped curve appears.
Spirograph Complete!
You coded the math behind a real toy from the 1970s!
These curves are called hypotrochoids — they're used in engineering to design
Wankel rotary engines. Up next: Butterfly Curve — a trigonometric classic.