Hyoungseo Son

Part 3 · Time Integration

Time Integration and Energy Drift

6 min read

The integrate step looked like the trivial one: advance xx by vhv\,h. 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 hh:

  • 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 dtdt up to exaggerate the split:

Energy drift by integratorinteractive
E₀
explicit Euler
symplectic Euler
implicit Euler
RK4
E/E₀ over time. Explicit Euler (red) climbs, implicit Euler (yellow) sinks, symplectic Euler (blue) stays near E₀, RK4 (green) rides on it. The dashed line is the true conserved energy.

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

  1. 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."

  2. Marsden & West, Discrete mechanics and variational integrators, Acta Numerica (2001).