Article Physics & Mechanics · ≈ ⏱ 10 min read

Conservation laws in simulations: what can you break?

Real physics conserves energy, momentum and angular momentum exactly. Real-time simulations almost never do — and that's often fine. The trick is knowing which violations are invisible and which ones will make your simulation look obviously fake.

TL;DR: Real-time simulations rarely conserve energy, momentum and angular momentum exactly — integrators, collision solvers and floating-point rounding all leak them. Games and cloth can tolerate heavy drift since it's invisible; orbital and scientific simulations can't. PBD trades conservation for stability outright, while XPBD claws some back via compliance.

1. The three laws that matter

Three quantities are conserved in an isolated classical system with no external forces or torques: total mechanical energy (kinetic + potential), linear momentum (mass × velocity, summed over all bodies), and angular momentum (moment of inertia × angular velocity, summed about a common point). Noether's theorem ties each one to a symmetry of physical law — energy to time-translation symmetry, momentum to space-translation symmetry, angular momentum to rotational symmetry.

Conserved quantities E = ½·m·v² + U(x)    (mechanical energy)
p = Σ mᵢ·vᵢ    (linear momentum)
L = Σ Iᵢ·ωᵢ + rᵢ×(mᵢ·vᵢ)    (angular momentum)

A perfect simulation would hold all three constant, frame after frame, forever. No real-time simulation does — the only question is how much drift is tolerable and where it's hidden.

2. Where simulations leak them

There are three independent sources of conservation error, and they stack:

  • The integrator. Non-symplectic methods (explicit Euler, RK4) systematically add or remove energy every step — see Verlet, Leapfrog and RK4 for the mechanism.
  • The collision solver. Iterative Gauss-Seidel solvers (used by Cannon-es and nearly every real-time engine) only approximately satisfy contact constraints, and that approximation error injects or removes momentum.
  • Floating-point arithmetic. Every addition of 32-bit floats rounds; over millions of steps in an N-body simulation this alone produces measurable energy drift, independent of the integrator's own bias.

3. Energy: the easiest to violate

Energy is the most fragile of the three, because damping — deliberate or accidental — always removes it and never conserves it. Cloth and rope simulations add velocity damping specifically to stay numerically stable; that damping is a controlled energy leak that makes the cloth look "heavier" and less jittery than a perfectly conservative model would.

The double pendulum trap

A chaotic system like the double pendulum amplifies any energy drift exponentially — a tiny non-symplectic error compounds into a visibly wrong trajectory within seconds. This is exactly why that simulation uses RK4 with a small fixed timestep rather than a cheaper first-order method.

4. Momentum: collisions and restitution

An elastic collision between two billiard balls should conserve both momentum and kinetic energy exactly. In practice, engines apply an impulse scaled by a coefficient of restitution e (1 = perfectly elastic, 0 = perfectly inelastic) — and any rounding or solver-iteration shortfall in that impulse calculation shows up as balls that drift very slightly faster or slower than they should after a long rally. The Billiards simulation keeps restitution close to 1 and increases solver iterations around contacts specifically to keep this drift below the threshold a human eye can detect.

5. Angular momentum: spin and gyroscopes

Angular momentum conservation is what makes a spinning gyroscope resist tipping over and instead precess — and it's one of the more unforgiving quantities to get right numerically, because it couples rotation, the inertia tensor, and torque all at once. Small integration errors in orientation (quaternion drift) compound into visibly wrong precession rates. The Gyroscope simulation and Maxwell's Wheel simulation both re-normalize quaternions every step specifically to stop floating-point drift from slowly growing the rotation representation's magnitude and injecting phantom angular momentum.

6. PBD and XPBD: violate on purpose

Position Based Dynamics doesn't integrate forces at all — it directly projects particle positions onto constraint manifolds (see Position Based Dynamics: Cloth, Soft Bodies & Constraints for the full algorithm). That projection is not derived from a physical force law, so plain PBD has no energy conservation guarantee whatsoever — it's stable but not physically accurate, and stiffer constraints or more solver iterations silently add numerical damping.

XPBD (Extended PBD) fixes exactly this by adding a compliance parameter to each constraint, making the projection converge to a real force law as the substep count grows — trading some of PBD's raw speed for a principled path back toward energy conservation.

7. Detecting a violation

The simplest diagnostic: log total system energy (or momentum) every frame and plot it. A conservative integrator on an isolated system produces a flat line with small oscillation around the true value; a leaking one shows a monotonic drift — usually downward (damping) but sometimes upward, which signals a genuine solver bug rather than intentional damping.

Simple energy-drift check (JS) const E0 = totalEnergy(bodies)
// ...run N steps...
const drift = Math.abs(totalEnergy(bodies) - E0) / E0

8. When it's OK to cheat

ContextAcceptable driftWhy
Game / interactive toyHighPlayer never sees the raw energy number; stability > accuracy
Cloth, rope, soft bodyMedium-highDeliberate damping avoids explosion; look matters more than exactness
Orbital / N-body demoLowDrift visibly changes orbit shape over time — pick a symplectic integrator
Scientific / research codeNear zeroWrong conclusions if conservation isn't verified numerically
▶ Live Demo

See conservation in action

N-body gravity holds up over thousands of orbits. Try nudging a planet and watch total energy.

⭐ N-Body Gravity 🌀 Gyroscope

🔗 Related Simulations

N-Body 🎱Billiards 🌀Gyroscope 🎡Maxwell's Wheel