-
Notifications
You must be signed in to change notification settings - Fork 0
Mathematical Background
Learn about the fascinating mathematics behind the butterfly curve!
The butterfly curve is a transcendental plane curve discovered by Temple H. Fay at the University of Southern Mississippi in 1989.
r(t) = e^cos(t) − 2cos(4t) − sin^5(t/12)
Where:
- r = radius (distance from origin)
- t = angle parameter (in radians)
- e = Euler's number (≈ 2.71828)
To plot on an x-y coordinate system:
x(t) = sin(t) × r(t)
y(t) = cos(t) × r(t)
Let's understand each component of the radius function:
r₁ = e^cos(t)
- Creates a gentle oscillation
- Range: [e^(-1), e^1] ≈ [0.368, 2.718]
- Varies smoothly as t changes
Visual Effect: Base pulsing motion
r₂ = -2cos(4t)
- Oscillates 4 times as t goes 0 to 2π
- Range: [-2, 2]
- The "4" creates the 4-lobed wing pattern
Visual Effect: Creates the butterfly wings!
r₃ = -(sin(t/12))^5
- Very slow oscillation (dividing by 12)
- Fifth power emphasizes extremes
- Range: [-1, 1]
Visual Effect: Adds fine details and asymmetry
r(t) = e^cos(t) − 2cos(4t) − sin^5(t/12)
All three components work together to create the butterfly shape!
A parametric equation defines a curve using a parameter (t) rather than y as a function of x.
x(t) = sin(t) × [e^cos(t) − 2cos(4t) − sin^5(t/12)]
y(t) = cos(t) × [e^cos(t) − 2cos(4t) − sin^5(t/12)]
As t varies from 0 to ~100, the point (x(t), y(t)) traces out the butterfly!
- r = distance from origin
- θ = angle from positive x-axis
- x = horizontal position
- y = vertical position
x = r × sin(θ)
y = r × cos(θ)
Or reverse:
r = √(x² + y²)
θ = arctan(y/x)
The formula creates approximate bilateral symmetry because:
- Cosine and sine are periodic functions
- The combination of different frequencies creates mirror-like patterns
The term -2cos(4t) is crucial:
- The coefficient 4 means it oscillates 4 times per full rotation
- This creates the 4 major lobes (2 on each side)
- The amplitude of 2 makes them prominent
In our code:
t = k / STEP_DIVISOR # k from 0 to 4999, STEP_DIVISOR = 50So t ranges from 0 to ~100
This is about 16 full rotations (100 / 2π ≈ 16), allowing the pattern to fully develop and close.
- Type: Transcendental curve (uses transcendental function e)
- Nature: Closed curve (starts and ends at same point)
- Symmetry: Approximate bilateral symmetry
- Non-algebraic: Can't be expressed as polynomial equation
- Self-similar: Has repeating patterns at different scales
- Smooth: Continuously differentiable (no sharp corners)
r = math.exp(math.cos(t)) - 2 * math.cos(n * t) - (math.sin(t / 12)) ** 5- n = 3: Creates 3-lobed butterfly
- n = 5: Creates 5-lobed butterfly
- n = 6: Creates 6-lobed butterfly
r = math.exp(math.cos(t)) - A * math.cos(4 * t) - (math.sin(t / 12)) ** 5- A = 1: Smaller wings
- A = 3: Larger, more dramatic wings
r = math.exp(math.cos(t)) - 2 * math.cos(4 * t) - (math.sin(t / n)) ** p- n: Controls detail frequency (higher = slower change)
- p: Controls emphasis (higher = sharper transitions)
If you enjoyed the butterfly curve, check out:
- Cardioid: r = 1 + cos(θ)
- Rose Curve: r = cos(kθ)
- Lissajous Curves: x = A sin(at), y = B sin(bt)
- Spirograph Patterns: Using epicycloids
This project demonstrates:
✅ Converting mathematical formulas to visual art
✅ Using parametric equations
✅ Polar to Cartesian coordinate conversion
✅ The beauty of mathematical functions
✅ How different frequencies combine to create complex shapes
- Butterfly Curve on Wikipedia
- Temple H. Fay's original paper (1989)
- Parametric equations in calculus textbooks
Ready to customize? Check out the Customization Guide! 🦋