This sandbox models a swarm of balls bouncing and colliding inside a 2D box, resolving every impact with the impulse-based collision response used in physics engines and games. Conservation of momentum is at the heart of everything from snooker breaks and car-crash analysis to spacecraft docking. It is fascinating because a single coefficient, the restitution e, smoothly tunes the system between perfectly bouncy and perfectly sticky behaviour while total momentum stays fixed.
j = -(1 + e)(v_rel . n) / (1/m1 + 1/m2) — j is the impulse magnitude, e the restitution, v_rel the relative velocity, n the unit contact normal, and m1, m2 the two masses. Velocities update as v1 += j*n/m1 and v2 -= j*n/m2.
When two equal masses collide elastically head-on, they simply swap velocities — which is why a snooker cue ball can stop dead while sending the object ball off at nearly its full speed.
When two balls collide, the impulse-momentum theorem governs the exchange: the total momentum of the system is conserved regardless of the coefficient of restitution e. Setting e=1 gives a perfectly elastic collision (kinetic energy also conserved); e=0 gives a perfectly inelastic collision where the balls stick together and maximum kinetic energy is lost as heat.
Drag the Restitution (e) slider between 0 and 1 to switch between inelastic and elastic regimes. The Mass ratio slider changes the relative mass of alternating balls — unequal masses produce asymmetric velocity exchanges. Add Gravity for more complex multi-ball pile-ups. Drag any ball with the mouse to reposition it.
The coefficient of restitution was first studied by Newton and later formalised by Poisson. Real-world values: steel ball on steel plate ~0.9, rubber ball ~0.7, soft clay ~0.0. In snooker, the cue ball (e ≈ 0.97) transfers nearly all its momentum to the target ball when they hit head-on — a result that follows directly from equal masses and high e.
This simulation models a system of balls moving and colliding inside a bounded 2D box, governed by classical Newtonian mechanics. Each collision is resolved using impulse-based physics: a computed impulse along the contact normal updates both balls' velocities while conserving total linear momentum. The coefficient of restitution (e) controls how much kinetic energy is retained, ranging from perfectly elastic (e=1) to perfectly inelastic (e=0) collisions.
Two-dimensional collision mechanics underpin a vast range of real-world applications, from billiards and snooker to vehicle crash-test engineering, molecular dynamics simulations, and the design of sports equipment such as tennis rackets and cricket balls.
In any collision between isolated objects, the total linear momentum of the system remains constant before and after impact. In 2D, this means both the x-component and y-component of total momentum are each conserved independently. This principle holds regardless of whether the collision is elastic or inelastic, and regardless of the coefficient of restitution.
Use the Ball count slider (2–20) to set how many balls are active. The Mass ratio slider changes the relative mass of alternating balls, so you can observe asymmetric velocity exchanges. Drag the Restitution (e) slider from 0 (balls stick together) to 1 (perfectly bouncy). Enable Gravity to create pile-up dynamics. You can also drag any ball with your mouse or finger to reposition it mid-simulation.
The coefficient of restitution (e) is the ratio of the relative speed of separation to the relative speed of approach along the contact normal after a collision. A value of e=1 means no kinetic energy is lost (perfectly elastic); e=0 means the objects move together after impact (perfectly inelastic). Real-world examples: steel ball on steel plate ~0.9, rubber ball ~0.7, tennis ball on court ~0.75, soft clay ~0.0.
The impulse magnitude is calculated as: j = -(1 + e)(v_rel · n) / (1/m1 + 1/m2), where e is the restitution coefficient, v_rel is the relative velocity vector, n is the unit contact normal, and m1, m2 are the masses. Velocities are then updated as v1 += j*n/m1 and v2 -= j*n/m2. This formulation guarantees momentum conservation and produces the correct energy dissipation for any value of e between 0 and 1.
Snooker and billiards are classic examples: when a cue ball strikes an object ball of equal mass at an angle, the two balls scatter at 90 degrees to each other in the elastic limit (e close to 1). Crash-test engineering uses 2D collision models to predict vehicle deformation and occupant motion during side impacts. Particle accelerators rely on 2D (and 3D) collision dynamics to predict scattering angles of subatomic particles.
A common misconception is that a heavier ball always pushes a lighter one away without being affected itself. In reality, both balls always experience velocity changes; the heavier ball changes speed less while the lighter ball changes more. When a very heavy ball strikes a stationary very light ball elastically, the heavy ball barely slows down while the light ball bounces off at nearly twice the heavy ball's speed — a result seen in Newton's cradle-style demonstrations.
The mathematical treatment of elastic collisions was developed by Christiaan Huygens around 1668, who formulated the rules for velocity exchange in equal and unequal mass collisions. Isaac Newton introduced the concept of the coefficient of restitution in his Principia Mathematica (1687). Siméon-Denis Poisson later provided a more rigorous impulse-based framework in the early 19th century, which forms the basis of modern collision resolution algorithms.
2D collision resolution is a fundamental building block shared by many simulation types. Rigid-body physics engines (used in games and robotics) extend this to rotational impulses and friction. SPH fluid simulations handle many-particle interactions that are statistical analogues of repeated collisions. Cloth and soft-body simulations use similar impulse-correction techniques for constraint resolution. Molecular dynamics simulations of gases treat atom interactions as a sequence of two-body elastic collisions.
Game engines such as Unity and Unreal Engine use real-time impulse-based 2D and 3D collision solvers for realistic object interactions. Robotics engineers simulate robot-arm grasp contacts using the same equations. Sports-equipment designers model ball-bat and ball-racket impacts to optimize energy transfer. Automotive safety engineers use 2D collision models during the early design phase before expensive full-scale crash tests, reducing development costs and time significantly.
Current research topics include granular material simulations (where thousands of particles interact simultaneously), oblique and spinning-ball collisions that require combined linear and angular impulse models, and the transition from classical to quantum collision mechanics at the nanoscale. Researchers are also improving real-time collision detection algorithms using broad-phase spatial hashing and narrow-phase GJK/EPA solvers that handle non-spherical shapes efficiently enough for large-scale VR and robotics applications.