Sierpiński’s triangle and carpet#

Sierpiński’s triangle (1915) removes the middle quarter of a filled triangle and repeats on the three corner triangles; his carpet (1916) removes the middle ninth of a square and repeats on the eight remaining squares. Both limits have zero area and a dimension strictly between 1 and 2. Here both are drawn with the chaos game.

import matplotlib.pyplot as plt
import numpy as np

from mathematicskit.fractals_chaos import SierpinskiCarpet, SierpinskiTriangle
from mathematicskit.fractals_chaos.visualizers.plots import plot_ifs_points

The two sets#

fig, axes = plt.subplots(1, 2, figsize=(10, 5))
plot_ifs_points(SierpinskiTriangle().generate(60000, seed=0), ax=axes[0], color="steelblue")
axes[0].set_title("Sierpiński triangle")
plot_ifs_points(SierpinskiCarpet().generate(80000, seed=0), ax=axes[1], color="firebrick")
axes[1].set_title("Sierpiński carpet")
fig.tight_layout()
Sierpiński triangle, Sierpiński carpet

Area vanishes, dimension is fractional#

After \(n\) removals the triangle keeps \((3/4)^n\) of its area and the carpet \((8/9)^n\); both tend to zero. Three copies at scale 1/2 and eight copies at scale 1/3 give dimensions \(\log 3/\log 2\) and \(\log 8/\log 3\).

for n in (1, 5, 20, 50):
    print(f"n = {n:2d}: triangle area {(3 / 4) ** n:.2e}, carpet area {(8 / 9) ** n:.2e}")
print(f"dimension of triangle: {np.log(3) / np.log(2):.4f}, carpet: {np.log(8) / np.log(3):.4f}")
n =  1: triangle area 7.50e-01, carpet area 8.89e-01
n =  5: triangle area 2.37e-01, carpet area 5.55e-01
n = 20: triangle area 3.17e-03, carpet area 9.48e-02
n = 50: triangle area 5.66e-07, carpet area 2.77e-03
dimension of triangle: 1.5850, carpet: 1.8928

Total running time of the script: (0 minutes 0.145 seconds)

Gallery generated by Sphinx-Gallery