skip to content

Velocity Verlet and RK4 both beat Euler on accuracy; what does each cost per physics step, and why do rigid-body engines rarely use RK4?

level: seniorimportance: should knowfreq 45%

answer

  1. count force evaluations per step
  2. order of accuracy vs structure preservation
  3. contact forces are not smooth
  4. spend four evaluations on four substeps

basics

~20 s

Velocity Verlet needs one force evaluation per step and is second-order and symplectic. RK4 needs four, is fourth-order but not symplectic, and assumes smooth forces; contacts are not smooth, so engines spend that budget on substeps instead.

solid answer

~40 s

Velocity Verlet sets `x += v*dt + 0.5*a*dt²`, evaluates the new acceleration once, then `v += 0.5*(a + a_new)*dt`; reusing `a_new` next step keeps it at one force evaluation, like semi-implicit Euler, with second-order accuracy and bounded energy error. RK4 samples the derivative four times at trial states inside the step, giving fourth-order accuracy for smooth forces, but it is not symplectic, so an undamped spring slowly loses energy. In a rigid-body engine each sample would mean rerunning collision detection and the contact solver, and contact forces jump discontinuously, which throws the high order away. The same four evaluations as four semi-implicit Euler substeps raise the spring stability limit from `ω*dt < 2.83` to `ω*dt < 8`. RK4 earns its cost on smooth, contact-free problems: orbits, or a projectile's predicted arc with drag.

code

pseudocode · 5 lines
pseudocode
// state per body: x, v, and a = force(x) / m kept from the previous step
x = x + v * dt + 0.5 * a * dt * dt
a_new = force(x) / m          // the only force evaluation this step
v = v + 0.5 * (a + a_new) * dt
a = a_new                     // reused at the start of the next step

go deeper

for a junior

Recall the cost of each method: velocity Verlet uses one force evaluation per step, RK4 uses four, and RK4 has the higher order of accuracy.

for a middle

Walk through the velocity Verlet update and the four RK4 samples, and explain the difference between order of accuracy and being symplectic.

for a senior

Argue from contacts and solver structure why RK4 rarely pays off in a rigid-body engine, and compare it with spending the same budget on substeps.

for a principal

Choose integrators per subsystem: a symplectic default for contact physics, a higher-order method only where smooth, contact-free accuracy is the product requirement.

## Three ways to judge an integrator - **Cost:** how many times per step it evaluates forces. In a game a force evaluation can mean collision detection plus a constraint solve, so this usually dominates. - **Order of accuracy:** how the error over a fixed stretch of simulated time shrinks with `dt`. A first-order method halves it when `dt` halves; a fourth-order method divides it by sixteen. - **Structure:** whether the method is **symplectic** (it preserves phase-space area, so its energy error stays bounded over long runs) and **time-reversible**. ## Velocity Verlet Velocity Verlet keeps the position, the velocity and the last acceleration: 1. `x = x + v*dt + 0.5*a*dt²`; 2. `a_new = force(x) / m`; 3. `v = v + 0.5*(a + a_new)*dt`; 4. keep `a_new` as `a` for the next step. It evaluates forces **once** per step, the same as semi-implicit Euler, but it is **second-order**, symplectic and time-reversible. On a spring of angular frequency `ω` its stability limit is the same `ω*dt < 2`. Its relative **position Verlet** (`x_next = 2*x - x_prev + a*dt²`) stores the previous position instead of a velocity and is popular for particle systems. ## RK4 Classic fourth-order Runge-Kutta works on the state `y = (x, v)` and its derivative `f(y) = (v, a)`, sampling the derivative four times: 1. `k1 = f(y)`; 2. `k2 = f(y + 0.5*dt*k1)`; 3. `k3 = f(y + 0.5*dt*k2)`; 4. `k4 = f(y + dt*k3)`; then `y = y + dt/6 * (k1 + 2*k2 + 2*k3 + k4)`. Its global error is fourth-order, but it is **not symplectic**: on an undamped spring it slowly removes energy while `ω*dt` is below `2*sqrt(2)` (about 2.83) and blows up above it. | Method | Force evaluations per step | Order | Symplectic | Stable on a spring while | |---|---|---|---|---| | Semi-implicit Euler | 1 | 1 | yes | `ω*dt < 2` | | Velocity Verlet | 1 (reusing `a`) | 2 | yes | `ω*dt < 2` | | RK4 | 4 | 4 | no | `ω*dt < 2.83` | Read the table with the step length fixed by the game: halving `dt` cuts semi-implicit Euler's error over a fixed time roughly in half, velocity Verlet's to a quarter and RK4's to a sixteenth, but only while the forces are smooth across the step, and only RK4 pays four evaluations for it. ## Why rigid-body engines rarely use RK4 - **Every derivative sample is a full force evaluation.** For a body in contact, the force depends on which contacts exist and what the solver computes for them, so RK4's three trial states would need collision detection and constraint solving three more times per step. - **Contacts are not smooth.** A contact appears, separates or switches from sticking to sliding inside a step, so the force is discontinuous. High order assumes smooth derivatives; across a discontinuity the error falls back to low order while the cost stays fourfold. - **Many solvers work on velocities.** Impulse-based contact and joint solvers commonly integrate velocity, correct it once, then integrate position once; that structure fits a single-sample integrator, not four blended samples. - **The same budget buys more stability as substeps.** Four substeps of semi-implicit Euler at `dt/4` use four force evaluations and stay stable while `ω*dt < 8`, almost three times RK4's limit, with bounded energy error. ## When RK4 is the right tool - Smooth forces and no contacts: an orbital or space-flight model, a projectile's predicted arc with quadratic drag drawn as an aiming line, a smooth force field. - Short horizons where accuracy per step matters more than long-run energy behaviour. - Offline tools that can afford the cost. For long runs of conservative motion, a symplectic method usually ages better than RK4, because RK4's small per-step energy loss accumulates while a symplectic method's error stays bounded.

  • What goes wrong with velocity Verlet when forces depend on velocity, such as drag?
    The new acceleration needs the new velocity, which is the thing being computed, so the step becomes implicit. Common workarounds evaluate drag with a half-step velocity estimate `v + 0.5*a*dt`, or apply damping as a separate multiplicative step. Both work in practice, but the method is then no longer exactly symplectic.
  • Why does RK4 lose energy on an undamped spring?
    For a spring its per-step amplification factor is `1 + z + z²/2 + z³/6 + z⁴/24` with `z = i*ω*dt`. Its magnitude is slightly below one while `ω*dt` is under `2*sqrt(2)`, so every step shrinks the amplitude a little. The loss per step is tiny but systematic, so over thousands of oscillations the motion visibly damps; above `2*sqrt(2)` the magnitude exceeds one and it explodes.

  • RK4 is always better because fourth order means less error.
  • Velocity Verlet needs two force evaluations every step.
  • A higher-order integrator automatically conserves energy.
  • RK4 can step through contacts with no extra collision work.
  • Velocity Verlet handles drag exactly, like position-only forces.