Subroutine Logo
Subroutine
← Back to Playground Physics & Math Intermediate

Numerical Integration: Verlet vs. Euler Physics Simulation

An interactive physics exploration comparing explicit Euler numerical integration against energy-conserving Verlet position integration.

Published: 2026-07-26
#Physics & Math#Physics Engine#Numerical Integration#Verlet#Simulation

When building physics engines for video games, graphics simulations, or astronomical modeling, computer hardware cannot continuously integrate physical differential equations. Instead, physics engines approximate motion using numerical integration over discrete time steps Δt\Delta t.


1. Summary & Key Takeaways

  • Explicit Euler Method: Updates position using current velocity: xt+Δt=xt+vtΔt,vt+Δt=vt+atΔtx_{t+\Delta t} = x_t + v_t \Delta t, \quad v_{t+\Delta t} = v_t + a_t \Delta t
    • Flaw: Accumulates truncation error over time, causing physical systems to artificially gain energy and explode!
  • Verlet Integration: Evaluates position from current xtx_t and previous xtΔtx_{t-\Delta t} frame positions: xt+Δt=2xtxtΔt+atΔt2x_{t+\Delta t} = 2x_t - x_{t-\Delta t} + a_t \Delta t^2
    • Advantage: Symplectic & time-reversible, accurately conserving total mechanical energy (Potential + Kinetic).

2. Interactive Physics Simulator

Use the interactive pendulum engine below to toggle between Explicit Euler and Verlet Integration!

Energy Explosion Warning

Select Explicit Euler (Unstable) and watch the mechanical energy meter explode over time! Then switch to Verlet Integration (Stable) to observe smooth, energy-conserving pendulum swings.

Numerical Integration Physics EngineVerlet vs Explicit Euler

Observe how Explicit Euler gains non-physical energy and explodes, whereas Verlet Integration conserves mechanical energy!

Mechanical Energy Metric:100 Joules
Numerical Integration Code
physics_integration.cpp
C++
// Verlet vs. Explicit Euler Numerical Integration in C++
struct Particle {
    double x, y;
    double oldX, oldY; // For Verlet Integration
    double vx, vy;     // For Euler Integration
    double ax, ay;
};

// 1. Explicit Euler Integration (Unstable for orbits & springs)
void stepEuler(Particle& p, double dt) {
    p.x += p.vx * dt;
    p.y += p.vy * dt;
    p.vx += p.ax * dt;
    p.vy += p.ay * dt;
}

// 2. Verlet Integration (Symplectic & Energy Preserving)
void stepVerlet(Particle& p, double dt) {
    double nextX = 2 * p.x - p.oldX + p.ax * dt * dt;
    double nextY = 2 * p.y - p.oldY + p.ay * dt * dt;
    p.oldX = p.x; p.oldY = p.y;
    p.x = nextX; p.y = nextY;
}

3. Mathematical Foundations

Verlet integration is derived directly by adding the forward and backward Taylor expansions of position x(t)x(t):

Forward Taylor Series (t+Δtt + \Delta t)

x(t+Δt)=x(t)+v(t)Δt+12a(t)Δt2+16b(t)Δt3+O(Δt4)x(t + \Delta t) = x(t) + v(t)\Delta t + \frac{1}{2}a(t)\Delta t^2 + \frac{1}{6}b(t)\Delta t^3 + \mathcal{O}(\Delta t^4)

Backward Taylor Series (tΔtt - \Delta t)

x(tΔt)=x(t)v(t)Δt+12a(t)Δt216b(t)Δt3+O(Δt4)x(t - \Delta t) = x(t) - v(t)\Delta t + \frac{1}{2}a(t)\Delta t^2 - \frac{1}{6}b(t)\Delta t^3 + \mathcal{O}(\Delta t^4)

Adding Both Equations (Eliminates Velocity & Odd Terms!)

x(t+Δt)=2x(t)x(tΔt)+a(t)Δt2+O(Δt4)x(t + \Delta t) = 2x(t) - x(t - \Delta t) + a(t)\Delta t^2 + \mathcal{O}(\Delta t^4)

Because the O(Δt3)\mathcal{O}(\Delta t^3) term cancels out, Verlet integration achieves 4th-order local accuracy without calculating velocity vectors directly!


4. Integration Method Comparison Matrix

MethodOrder of AccuracySymplectic (Conserves Energy)?Best Use Case
Explicit Euler1st1^{\text{st}} Order (O(Δt)\mathcal{O}(\Delta t))No (Gains Energy)Basic UI animations
Verlet Integration2nd2^{\text{nd}} Order (O(Δt2)\mathcal{O}(\Delta t^2))YesMolecular dynamics, cloth & ragdoll physics
Runge-Kutta 4 (RK4)4th4^{\text{th}} Order (O(Δt4)\mathcal{O}(\Delta t^4))No (High Precision)Orbital mechanics & aerospace trajectories