2D Collision Simulator - Interactive Physics Engine with Elastic & Inelastic Collisions
Interactive 2D collision simulator with real physics: elastic/inelastic collisions, gravity, drag-to-spawn bodies, energy tracking, and spatial hashing.
About
Collision response calculations require precise impulse resolution. A miscalculated coefficient of restitution e produces energy that either vanishes or appears from nowhere, breaking conservation laws and yielding physically meaningless results. This simulator solves the two-body collision problem using impulse-based response derived from conservation of linear momentum and the restitution equation vrel′ = −e ⋅ vrel. It handles circle-circle and circle-wall interactions with positional correction to prevent tunneling at high velocities.
The engine uses semi-implicit Euler integration and a spatial hash grid for broad-phase detection, scaling from a handful of bodies to several hundred without frame drops. Kinetic energy is tracked in real time so you can verify conservation during elastic collisions or observe energy dissipation when e < 1. Note: the simulation assumes 2D rigid bodies with no rotational inertia. Friction and angular momentum are not modeled. At very high speeds or very small radii, tunneling may still occur due to discrete time stepping.
Formulas
The impulse magnitude J along the collision normal n for two colliding circles:
Post-collision velocities are then updated:
Semi-implicit Euler integration advances state each frame:
Where e = coefficient of restitution, vrel = relative velocity of approach (v1 − v2), n = unit collision normal from body 2 to body 1, m1, m2 = masses, a = acceleration due to gravity and external forces, Δt = fixed time step.
Reference Data
| Parameter | Symbol | Typical Range | Unit | Notes |
|---|---|---|---|---|
| Coefficient of Restitution | e | 0 - 1 | - | 1 = perfectly elastic, 0 = perfectly inelastic |
| Steel on Steel | e | 0.80 - 0.95 | - | Hardened steel balls |
| Glass on Glass | e | 0.93 - 0.97 | - | Tempered glass spheres |
| Rubber on Concrete | e | 0.75 - 0.85 | - | Standard basketball bounce |
| Tennis Ball on Court | e | 0.70 - 0.75 | - | ITF regulation range |
| Clay (Putty) | e | 0.0 - 0.10 | - | Nearly perfectly inelastic |
| Billiard Balls | e | 0.92 - 0.98 | - | Phenolic resin, polished |
| Gravitational Accel. (Earth) | g | 9.81 | m/s2 | Sea level, 45° latitude |
| Gravitational Accel. (Moon) | g | 1.62 | m/s2 | Approx. 1/6 Earth gravity |
| Gravitational Accel. (Mars) | g | 3.72 | m/s2 | Approx. 0.38 Earth gravity |
| Gravitational Accel. (Jupiter) | g | 24.79 | m/s2 | Gas giant surface equiv. |
| Linear Momentum | p | - | kg⋅m/s | p = mv |
| Kinetic Energy | KE | - | J | KE = ½mv2 |
| Semi-implicit Euler Order | - | 1 | - | Symplectic, energy-stable for oscillatory systems |
| Spatial Hash Cell Size | - | 2×rmax | px | Optimal when cell ≥ largest diameter |
| Velocity Damping Range | d | 0.90 - 1.00 | - | 1.00 = no damping |
| Time Step (Fixed) | Δt | 0.016 | s | ~60 FPS equivalent |
| Overlap Correction Factor | - | 0.4 - 0.8 | - | Percentage of penetration resolved per frame |
| Max Bodies (Smooth) | - | 200 - 500 | - | Depends on device GPU/CPU |