Rendering walkable hyperbolic tilings on the Poincare disk
hyperbolic-geometrypoincare-diskmobiustilingwebglshader
A regular {p,q} tiling (p-gons, q meeting at each vertex) is hyperbolic when (p-2)(q-2) > 4, e.g. {7,3} or {5,4}. "The Floor That Won't Stay Flat" (justinahampton.com/fun/freetime/hyperbolic/) draws one on the Poincare disk endlessly in a WebGL1 fragment shader and lets you walk on it.
Per-pixel folding (no tile list)
For each pixel: apply the camera transform (a Mobius map), then fold the point into the fundamental triangle with angles (pi/p, pi/q, pi/2) by repeatedly reflecting across its three sides: the real axis, the line at angle pi/p, and a circle centered on the real axis at cx = cos(b) / sqrt(cos²(b) - sin²(a)) with radius R = cx * sin(a) / cos(b) (a = pi/p, b = pi/q). Stop when inside (up to ~110 iterations). The parity of the reflection count colors alternate tiles. Because nothing is enumerated, the tiling is infinite; sub-pixel detail near the rim should fade to the average color.
Camera and walking
- The camera is an SU(1,1) matrix [[a, b], [conj b, conj a]] acting by Mobius transformation. Dragging composes
M * phi(s0)^-1 * phi(s1)so the grabbed world point stays under the pointer (checked to 1e-16). Forward and turn are small Mobius steps. - Float32 precision: walking far from the origin pushes shader math past float32 range quickly. Periodically recenter in double precision on the CPU: fold the camera position back into the home cell with an even number of reflections and replace the camera with the equivalent symmetric one. The picture is unchanged (pixel diff ~2.7% from thin-line subpixel noise, vs 13.8% for a deliberate 0.08 rad turn).
Measuring curvature
- Triangle tool: three taps draw geodesic arcs; angles from the arc tangents sum to less than 180 degrees and the angle deficit equals the area (curvature -1). Checked against the hyperbolic law of cosines to 3e-16.
- Circle tool: circumference
2 pi sinh rvs the flat2 pi r; area2 pi (cosh r - 1).
Gotcha
In a shader, a variable f shadowed a JavaScript helper f() in the same template code path, leaving "f is not a function" and a dead page; --enable-logging=stderr in headless Chrome showed it.
See also
- Emergent-systems simulations: models, parameters and measured results
- three.js in a static site (bundling, viewers, snapshots)