Iterated Function System Discovered 1915 Dimension log 3 / log 2 ≈ 1.585

The Sierpinski Triangle

Two routes to the same triangle: a random walk that jumps toward a random vertex forever, or simply removing the middle triangle, recursively. The figure uses the second — true vector triangles, crisp at any zoom.

History

Wacław Sierpiński introduced this triangle in 1915 as an example of a curve that is simultaneously connected everywhere and has empty interior everywhere. Like Cantor’s dust, it began life as a counterexample in point-set topology, not as a picture to admire.

Construction: two routes to the same shape

Direct subdivision: remove the central inverted triangle, recurse into the three corners. The chaos game: pick any starting point, then repeatedly jump halfway toward a uniformly random vertex. Despite the randomness, the resulting cloud converges to exactly the same attractor:

S=f1(S)f2(S)f3(S),fi(x)=x+vi2S = f_1(S) \cup f_2(S) \cup f_3(S), \qquad f_i(x) = \frac{x + v_i}{2}

where v1,v2,v3v_1, v_2, v_3 are the triangle’s three corners. Concretely, starting the chaos game from the origin with v1=(0,1)v_1=(0,1): jumping halfway toward v1v_1 lands at (0, 0.5)(0,\ 0.5); jumping halfway toward v1v_1 again from there lands at (0, 0.75)(0,\ 0.75) — each jump halves the remaining distance to whichever corner got picked, which is exactly what fi(x)=(x+vi)/2f_i(x)=(x+v_i)/2 says algebraically.

Built from N=3N=3 copies scaled by r=1/2r=1/2: D=log3/log21.585D = \log 3/\log 2 \approx 1.585.

Experiment: can randomness draw a perfect triangle?

The rule below never says “remove the middle triangle.” It knows only random vertex + halfway jump. Add a few points first; then a few hundred. Watch the apparent noise acquire forbidden regions and finally crystallise into the same Sierpinski triangle.

0 plotted points. Pick a button: the first few jumps look like noise.
Rule: choose one of the three vertices at random, then move halfway toward it. No triangle-removal instruction is ever given.

The surprise is easier to understand if we separate which map is chosen from what each map does. Every jump applies one of the same three contractions fif_i. Randomness changes the itinerary through those maps, but all sufficiently long itineraries are trapped near the unique IFS attractor. In that sense, chance chooses the route; contraction supplies the geometry.

Cool Fact

The same triangle falls out of Pascal’s triangle: colour every odd binomial coefficient black, every even one white, and as nn \to \infty the pattern converges to the Sierpinski triangle. Already unmistakable after just ten rows:

Pascal's triangle with odd entries shaded black

Ten rows of Pascal’s triangle; odd entries shaded solid, even entries left white.

Python implementation

Pseudocode first

Algorithm in one glance Recursive
Keep the three corner triangles
sierpinski(a, b, c, depth) {
    if (depth == 0) return {(a,b,c)}
    ab = midpoint(a,b); bc = midpoint(b,c); ca = midpoint(c,a)
    return recurse into (a,ab,ca), (ab,b,bc), (ca,bc,c)
}

The executable version keeps the recursive idea visible and delegates the polygon rendering to fractalfair_helpers.py.

from fractalfair_helpers import triangles_figure

def sierpinski(depth, a, b, c):
    if depth == 0:
        return [(a,b,c)]
    ab, bc, ca = (a+b)/2, (b+c)/2, (c+a)/2
    return (sierpinski(depth-1, a,ab,ca)
            + sierpinski(depth-1, ab,b,bc)
            + sierpinski(depth-1, ca,bc,c))

def draw(depth=7):
    return triangles_figure(sierpinski(depth, *VERTICES))
λThe Same Idea in Haskell
sierpinskiRec :: Int -> P2 Double -> P2 Double -> P2 Double
              -> [(P2 Double, P2 Double, P2 Double)]
sierpinskiRec 0 a b c = [(a, b, c)]
sierpinskiRec depth a b c =
  concat [ sierpinskiRec (depth-1) a ab ca
         , sierpinskiRec (depth-1) ab b bc
         , sierpinskiRec (depth-1) ca bc c ]
  where ab = mid a b; bc = mid b c; ca = mid c a
Sierpinski triangle, recursive vector construction

Figure: 2,187 filled triangles from seven levels of recursion, coloured by height from deep purple (bottom) to pale gold (apex).

Fractal geometry will make you see everything differently.

— Michael Barnsley
Where You've Seen This

Sierpinski-triangle geometry shows up in fractal antenna design: the shape packs a long conducting path into a small footprint and resonates at multiple wavelengths, useful for compact multi-band mobile antennas.