Skip to content

Mathematical Background

SRIJA DE CHOWDHURY edited this page Jan 3, 2026 · 1 revision

🔢 Mathematical Background

Learn about the fascinating mathematics behind the butterfly curve!

The Butterfly Curve

The butterfly curve is a transcendental plane curve discovered by Temple H. Fay at the University of Southern Mississippi in 1989.

The Formula

Polar Form

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)

Cartesian Conversion

To plot on an x-y coordinate system:

x(t) = sin(t) × r(t)
y(t) = cos(t) × r(t)

Breaking Down the Formula

Let's understand each component of the radius function:

Component 1: e^cos(t)

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

Component 2: -2cos(4t)

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!

Component 3: -sin^5(t/12)

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

Combined Formula

r(t) = e^cos(t) − 2cos(4t) − sin^5(t/12)

All three components work together to create the butterfly shape!

Parametric Equations

A parametric equation defines a curve using a parameter (t) rather than y as a function of x.

Our Butterfly Parametric Form

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!

Polar vs. Cartesian Coordinates

Polar Coordinates (r, θ)

  • r = distance from origin
  • θ = angle from positive x-axis

Cartesian Coordinates (x, y)

  • x = horizontal position
  • y = vertical position

Conversion Formulas

x = r × sin(θ)
y = r × cos(θ)

Or reverse:

r = √(x² + y²)
θ = arctan(y/x)

Why This Creates a Butterfly

Symmetry

The formula creates approximate bilateral symmetry because:

  • Cosine and sine are periodic functions
  • The combination of different frequencies creates mirror-like patterns

The Wing Lobes

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

Range of t

In our code:

t = k / STEP_DIVISOR  # k from 0 to 4999, STEP_DIVISOR = 50

So t ranges from 0 to ~100

This is about 16 full rotations (100 / 2π ≈ 16), allowing the pattern to fully develop and close.

Mathematical Properties

Classification

  • Type: Transcendental curve (uses transcendental function e)
  • Nature: Closed curve (starts and ends at same point)
  • Symmetry: Approximate bilateral symmetry

Interesting Facts

  1. Non-algebraic: Can't be expressed as polynomial equation
  2. Self-similar: Has repeating patterns at different scales
  3. Smooth: Continuously differentiable (no sharp corners)

Variations You Can Try

Change the Frequency

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

Change the Amplitude

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

Change the Detail Component

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)

Related Curves

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

Mathematical Visualization

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

Further Reading


Ready to customize? Check out the Customization Guide! 🦋