A tiny idealised billiards machine where counting elastic collisions reveals the
digits of pi for special mass ratios.
Model notes
A wall, two blocks, and a strange count
This simulator is inspired by 3Blue1Brown's video "Why colliding blocks compute pi".
I found the idea fascinating: a classical mechanics toy with no visible circle in
the setup can still make pi appear, simply by counting the clacks. I wanted to make
that idea explorable rather than just watched.
The model is deliberately idealised. A unit-mass block sits between a rigid wall and
a larger incoming block. Both slide on a frictionless one-dimensional track, every
collision is perfectly elastic, and the counter increments for wall impacts and
block-block impacts.
The setup
The wall is at x = 0. The small block has mass m = 1 and starts
at rest between the wall and the large block. The large block has mass M = 10n,
starts to the right, and moves left. The visible block sizes are symbolic so that very
large mass ratios remain usable on screen.
Why this is surprising
There is no circle drawn on the track, but the velocity state can be transformed into
a scaled plane where kinetic energy is a circle. In that transformed view, collisions
act like reflections. The number of reflections before no further collision is possible
is tied to how many angular steps fit into a half-turn.
What the simulator demonstrates
Momentum and kinetic energy conservation during block-block collisions.
Velocity reversal when the small block hits the rigid wall.
A finite collision sequence ending when no future collision is possible.
The decimal digit cases M = 1, 100, 10,000, and 1,000,000, where the mass exponent is even.
What this model omits
It omits friction, deformation, finite contact time, sound propagation, air
resistance, relativity, and real-world problems caused by nearly simultaneous
contacts. Browser floating-point arithmetic also limits extreme mass ratios. This
is not a practical pi-computation machine; it is an educational demonstration of
an exact ideal model.
Historical context
The result is commonly called Galperin billiards, after Gregory Galperin's "Playing
Pool with Pi" result. 3Blue1Brown's presentation made the argument widely accessible
and is the direct inspiration for this lab.
Step through collision events, fast-solve large ratios, and inspect the scaled velocity state.
Simulation running
Total collisions
0
Wall
0
Block-block
0
Pi approximation
N / sqrt(M) ~= 0
Digit rule
Even n gives decimal digits
Small velocity
0
Large velocity
0
Kinetic energy
0
Momentum
0
Model time
0
Status
running
Collision log
Under the hood
The Mathematics Being Simulated
Updated
Conservation laws
During a block-block collision, the implementation applies the standard one-dimensional
perfectly elastic update derived from conservation of momentum and kinetic energy:
m v1 + M v2 = m v′1 + M v′2
½m v12 + ½M v22 = ½m v′12 + ½M v′22
v′1 = ((m - M)/(m + M))v1 + (2M/(m + M))v2
v′2 = (2m/(m + M))v1 + ((M - m)/(m + M))v2
Wall collision
The wall is rigid and infinitely massive, so only the small block reverses velocity:
v′1 = -v1
Why pi appears
Define scaled velocity coordinates u1 = √mv1
and u2 = √Mv2. Kinetic energy is proportional
to u12 + u22, so the velocity state lies
on a circle in this plane. Collisions reflect that point. For special mass ratios, counting
the reflections is closely related to counting angular steps around a half-turn.
Why 100^k gives decimal digits
θ = arctan(√(m/M)), N = ⌈π/θ⌉ - 1
For this initially stationary small block, the ideal total N is one less than the
ceiling of π/θ (the ceiling rounds up to an integer).
When M/m = 100k, √(M/m) = 10k.
The available even-exponent settings give counts of 3, 31, 314, 3,141, 31,415,
314,159, and 3,141,592: the opening digits of π.
This page controls M = 10n, so those familiar decimal
cases occur when n is even.
Odd exponents introduce a factor of √10 alongside a power of ten.
For example, M = 103 produces 99 collisions.
The normalised final count N / √M tends toward π
as the mass ratio increases, but odd-exponent counts do not follow its decimal digits.
Numerical method
The code calculates the time to the next wall or block-block contact, advances both blocks to
that event, applies the instantaneous elastic velocity update, and repeats. It does not
use a soft-body physics engine, force integration during contact, or overlap correction as
the source of the collision count. Floating-point arithmetic still introduces limits at
extreme mass ratios.
Assumptions and limits
The track is one-dimensional and frictionless, the wall is perfectly rigid, the blocks do
not rotate or deform, and collisions take no time. The mass controls change inertia but
the drawn block sizes remain symbolic. Browser floating-point arithmetic and the fast-solve
event cap limit extreme ratios.