Triangle Group Tilings

A Python tool that draws the tiling generated by the triangle group Δ(p,q,r) — the group of reflections in the sides of a triangle with angles π/p, π/q and π/r. Depending on the angles, the triangle lives on the sphere, in the Euclidean plane, or in the hyperbolic plane, and repeatedly reflecting it fills the whole space with copies.

Every tile is labelled by the group word that reaches it, so the tool also exports a JSON file mapping each word to its tile’s vertex coordinates — useful for checking word-problem automata against the actual geometry. Large tilings can be exported as a zoomable viewer that only draws the tiles you can actually see.

Gallery

How it works

The triangle group is generated by three reflections a, b, c, one for each side of the fundamental triangle. Each reflection undoes itself, and each pair of reflections composes to a rotation around the corner where its two sides meet:

Δ(p,q,r) = ⟨ a, b, c  |  a2 = b2 = c2 = (ab)r = (bc)p = (ca)q = 1 ⟩

The angle sum decides which geometry the triangle lives in:

1/p + 1/q + 1/rGeometryDrawn in
> 1SphericalStereographic projection
= 1EuclideanThe plane
< 1HyperbolicPoincaré disk

Reflections are stored as anti-Möbius maps z ↦ M·z̄ acting on the complex plane. A breadth-first search applies a, b and c to build every reduced word up to a chosen length, keeping each tile once under the shortest word that reaches it. Because every relation has even length, coloring tiles by the parity of their word length gives the classic checkerboard. Edges are drawn as true circular arcs, so in the disk every geodesic meets the boundary at a right angle.

Usage

$ python tiling.py --pqr 2 3 7
Δ(2,3,7) [hyperbolic] depth=40 tiles=30508 (drawn 30508) 5.10s
png → data/2_3_7/d40_m0.001.png
json → data/2_3_7/d40_m0.001.json

$ python tiling.py --pqr 2 3 0 --svg --html # 0 = ∞
$ cat data/2_3_7/d40_m0.001.json
{ "e": [[0.0, 0.0], [0.1406, 0.0], [0.0, 0.2661]],
  "a": [[0.2109, 0.1170], [0.1406, 0.0], [0.0, 0.2661]], … }

What it does

Three Geometries

Picks spherical, Euclidean or hyperbolic geometry from the angles and builds the fundamental triangle from the law of cosines.

Ideal Vertices

An order of 0 means ∞: that corner sits on the boundary circle as a cusp, as in the modular group Δ(2,3,∞).

Word Export

Writes every group word with its tile’s three vertices to JSON, for cross-checking automata against the geometry.

Zoomable Viewer

Exports a self-contained HTML canvas viewer that skips off-screen and sub-pixel tiles, stays smooth with 100k+ tiles, and shows each tile’s word on hover.

PNG, SVG and HTML

A PNG is always written; SVG and HTML are opt-in. Runs are saved to data/<group>/ under names built from their settings.

Numerically Tested

Tests check that each reflection undoes itself, that the group relations hold exactly, and that the triangle’s measured angles are π/p, π/q, π/r.

Roadmap

Tech Stack

Built with Python 3, numpy for the Möbius-map arithmetic and matplotlib for PNG and SVG output. The viewer is vanilla JavaScript on an HTML canvas with no dependencies. Tests use Python’s built-in unittest.

Viewer: The viewer.html linked above was generated by the tool for Δ(2,3,7) — 68,721 tiles up to word length 45, about 5 MB. Near the boundary, past what was generated, the tiles blend into a flat color; generating locally with a larger --depth and smaller --min-size lets you zoom further.