Contents · Physics Engines
Part 0 · Orientation
Part 1 · Mathematical Foundations
Part 2 · Equations of Motion
Part 3 · Time Integration
- Time Integration and Energy Drift
Part 4 · Collision Detection
Part 5 · Contact & Constraints
Part 6 · Constraint Solvers
Part 7 · Position-Based Dynamics
Part 8 · GPU & Parallelism
Part 9 · Differentiable Simulation
Part 3 · Time Integration
Time Integration and Energy Drift
The integrate step looked like the trivial one: advance by . The catch is which velocity and position you use, and the wrong choice quietly creates or destroys energy until the simulation either explodes or grinds to a stop.
Four integrators, one pendulum
Take an undamped pendulum, which should conserve energy exactly, and integrate it four ways at the same step :
- Explicit (forward) Euler. Use the current acceleration and velocity for both updates. Simplest possible, and for an oscillator it pumps energy in: the pendulum spirals outward.
- Semi-implicit (symplectic) Euler. Update velocity first, then use the new velocity for position. One character of difference in code, but it is symplectic, so the energy error stays bounded forever.1 This is why it is the default in most game and robotics engines.
- Implicit (backward) Euler. Solve for the end-of-step state. Unconditionally stable but dissipative: energy bleeds away and motion damps. Ideal for stiff systems where you want stability, wrong if you care about liveliness.
- RK4. Four derivative evaluations, fourth-order accurate, energy nearly conserved over these timescales, but it costs four times as much and still is not symplectic.
Watch the total energy. Push up to exaggerate the split:
What engines actually pick
Most rigid-body engines use semi-implicit Euler: it is cheap and its energy stays bounded, which is exactly the trade a real-time simulator wants. To cut the error further they shrink the effective step with substepping (PhysX's TGS is literally a substepped solver). Stiff or soft systems lean toward implicit integration for its stability. And when conservation over long horizons truly matters, variational integrators derive the update from a discrete action principle, preserving momentum and symplectic structure by construction.2
Integration assumed we already had the forces and the contacts. The next chapter is where the loop finds contacts, and the three after that are where it computes the forces.
Footnotes
-
Hairer, Lubich & Wanner, Geometric Numerical Integration: "the error in the energy grows linearly for the explicit Euler method, and it remains bounded and small (no secular terms) for the symplectic Euler method." ↩
-
Marsden & West, Discrete mechanics and variational integrators, Acta Numerica (2001). ↩