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 .
1. Summary & Key Takeaways
- Explicit Euler Method: Updates position using current velocity:
- Flaw: Accumulates truncation error over time, causing physical systems to artificially gain energy and explode!
- Verlet Integration: Evaluates position from current and previous frame positions:
- 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!
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!
// 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 :
Forward Taylor Series ()
Backward Taylor Series ()
Adding Both Equations (Eliminates Velocity & Odd Terms!)
Because the term cancels out, Verlet integration achieves 4th-order local accuracy without calculating velocity vectors directly!
4. Integration Method Comparison Matrix
| Method | Order of Accuracy | Symplectic (Conserves Energy)? | Best Use Case |
|---|---|---|---|
| Explicit Euler | Order () | No (Gains Energy) | Basic UI animations |
| Verlet Integration | Order () | Yes | Molecular dynamics, cloth & ragdoll physics |
| Runge-Kutta 4 (RK4) | Order () | No (High Precision) | Orbital mechanics & aerospace trajectories |