Science lab / elastic collisions

Colliding Blocks Compute π

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 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 both blocks escape to the right 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 special decimal cases M = 1, 100, 10,000, and 1,000,000.

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.

References and further reading

Article last reviewed for factual accuracy on 27 June 2026.

Deep instrument

Elastic collision workbench

Step through exact 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
Small velocity
0
Large velocity
0
Kinetic energy
0
Momentum
0
Model time
0
Status
running
Setup
Collision log

    Under the hood

    The Mathematics Being Simulated

    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 = √m v1 and u2 = √M v2. 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

    When M/m = 100k, √(M/m) = 10k. The total collision count is approximately pi times 10k, so the integer count begins with the digits of pi. This page controls M = 10n, so the familiar decimal cases occur when n is even.

    Numerical method

    The code schedules the next wall or block-block contact exactly, 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.

    Further mathematics