Hard Disk Gas
N elastic disks in a box — nothing more. No heat bath, no Maxwell's demon, no ensemble averaging. Just Newton's laws applied to every collision, frame by frame. The speed distribution that emerges below is Maxwell-Boltzmann: a theorem of statistical mechanics that follows inevitably from the microscopic dynamics. The orange curve is the exact theoretical prediction; the cyan bars are what the simulation actually produces. Watch them converge.
The physics
Each disk has mass m = 1 and follows Newton's second law between collisions.
When two disks touch, momentum and kinetic energy are both conserved — the collision is
elastic. Wall bounces conserve speed. That's the entire model. No stochastic forces,
no thermostats, no phenomenological damping.
Temperature is defined microscopically via the equipartition theorem. In two dimensions,
each translational degree of freedom carries average kinetic energy ½kT,
giving T = ⟨v²⟩ / 2 in units where k = m = 1.
Maxwell-Boltzmann in 2D
The equilibrium speed distribution in two dimensions is the Rayleigh distribution:
The histogram converges to this distribution through collisions alone — each collision reshuffles kinetic energy between particles, driving the system towards the unique distribution that is stationary under the dynamics: the maximum-entropy state compatible with a fixed total energy.
What to try
Start from the Cold preset — particles initialised with a narrow, low-speed
distribution. Watch the histogram broaden and relax toward the orange curve within seconds.
Switch to Hot and the curve shifts right; the peak speed scales as
√T. Hit Dense to pack the box: collision rate climbs,
equilibration accelerates, and at very high packing you'll see glassy, correlated motion
that departs from the ideal-gas picture.
Numerical method
Time-step integration with overlap detection and resolution each frame. For equal-mass elastic
collisions the update rule in the normal direction is simply a velocity swap.
With N ≤ 260 disks the O(N²) pairwise check runs comfortably inside a 16 ms
frame budget at 60 Hz. The temperature slider rescales all velocities by √(T_new / T_cur),
preserving the velocity directions and thus the existing equilibration state.