The full sample code for this article is available for download on Patreon after following.
(It uses openFrameworks for the implementation.)
Support my Work:) / Coffee Supplier on Patreon

This guide covers the following:

  • The basic concept and formula of Verlet integration
  • Comparison with the Euler method
  • Variants: Position Verlet, Velocity Verlet, and Leapfrog method
  • Implementation examples in Processing
  • Key considerations and limitations

Whether you’re a beginner or a more advanced user, this article provides a practical overview for understanding and applying Verlet integration.

1. What Is Verlet Integration?

Verlet integration is a numerical method used to compute the motion of objects over time, particularly well-suited for simulations that require energy conservation and natural dynamics. It calculates the next position based only on the current and previous positions along with the applied force.

Advantages of Verlet Integration:

  • Energy Stability: Prevents artificial gain or loss of energy over time
  • No Explicit Velocity Required: Simplifies calculation and leads to natural behavior
  • Lightweight and Responsive: Ideal for visual art, real-time systems, and interactive environments

These features make it widely adopted in game development, generative art, and scientific simulations.

2. Mathematical Foundation

The core formula of Verlet integration updates the position based on previous and current positions:

  1. x(t+Δt) : Position at the next time step
  2. x(t) : Current position
  3. x(t−Δt) : Previous position
  4. a(t) : Current acceleration
  5. Δt : Time step

Rather than computing future positions from velocity like in Euler’s method, Verlet uses a combination of:

  • Displacement from the previous step: (x(t)−x(t−Δt))
  • The influence of acceleration

This results in a natural “inertial” motion plus force-driven behavior.

3. Comparison with the Euler Method

FeatureEuler MethodVerlet Method
Stability✗ Low (can diverge)✓ High (energy-conserving)
Simplicity✓ Very simple✗ Slightly more complex
AccuracyLowMedium to High
Use CasesPrototypesRealistic simulations

Example: Euler can cause spring simulations to spiral out of control, while Verlet maintains natural oscillations.

4. Variants of Verlet Integration

Verlet integration has multiple variants tailored to different use cases. Here, we introduce three widely used forms, each with code examples in Processing:

Velocity Verlet (explicit velocity tracking)

Velocity Verlet is one of the most widely used time integration algorithms in molecular dynamics simulations. It explicitly maintains velocity and calculates the next velocity using the average of the current and new acceleration. This allows it to naturally handle velocity-dependent forces such as air resistance and friction. It is known for its stability and energy conservation properties, making it suitable for long-term simulations.

Formulas:

  1. x(t+Δt) = x(t) + v(t)Δt + 0.5·a(t)Δt²
  2. a(t+Δt) = F(r(t+Δt)) / m
  3. v(t+Δt) = v(t) + 0.5·(a(t) + a(t+Δt))Δt

Pros:

  • Direct velocity access
  • Highly stable and energy-conserving
  • Time-reversible

Sample:


PVector position = new PVector(100, 100);
PVector velocity = new PVector(0, 0);
PVector acceleration = new PVector(0, 0.5);

void update() {
  position.add(PVector.mult(velocity, 1));
  position.add(PVector.mult(acceleration, 0.5));               // 0.5 * a(t) * dt^2(dt=1)
  PVector newAcc = new PVector(0, 0.5);
  vel.add(PVector.add(acceleration, newAcc).mult(0.5));   // v(t+1) = v(t) + 0.5*(a(t)+a(t+1))
  acceleration = newAcc;
}
}

Leapfrog Method (velocity offset by half-step)

The Leapfrog method evaluates position and velocity at staggered time steps—position at integer time steps and velocity at half-integer time steps, like a “leaping frog.”
Because of this half-step offset between updates of position and velocity, Leapfrog achieves highly stable numerical integration over long periods, similar to Velocity Verlet. It is often used in game physics and particle systems.Formulas:

  1. v(t+Δt/2)=v(t−Δt/2)+a(t)Δt
  2. x(t+Δt)=x(t)+v(t+Δt/2)Δt
  3. a(t+Δt)=F(x(t+Δt)​)/m

Pros:

  • High stability
  • Time-reversibility
  • Slightly simpler than Velocity Verlet

Cons:

  • Requires handling half-step velocities

Sample:


PVector position = new PVector(100, 100);
PVector velocity = new PVector(0, 0.5);
PVector acceleration = new PVector(0, 0.5);

void update() {
  velocity.add(PVector.mult(acceleration, 1));         // v(t+1/2)
  position.add(velocity);                          // x(t+1)
  acceleration = new PVector(0, 0.5);
}

Position Verlet (simplest form)

Position Verlet is the simplest form of Verlet integration. It does not store velocity explicitly but estimates the next position using only the current and previous positions. Due to its strong energy conservation characteristics, it is well-suited for simulating systems like cloth and spring dynamics.

Formulas:

  1. x(t+Δt) = 2x(t) − x(t−Δt) + a(t)Δt²
  2. a(t+Δt) = F(x(t+Δt)) / m​

Pros:

  • Very stable
  • Time-reversible
  • Compact and efficient

Cons:

  • Velocity must be inferred from positions
  • Requires initialization of two positions

Sample:


PVector pos = new PVector(100, 100);
PVector prevPos = pos.copy();
PVector acc = new PVector(0, 0.5);

void update() {
  PVector temp = pos.copy();
  PVector velocity = PVector.sub(pos, prevPos);
  pos.add(velocity).add(acc);               // x(t+1) = x(t) + (x(t) - x(t-1)) + a(t)
  prevPos = temp;
}

Summary Table

VariantUses VelocityAccuracyStabilityBest For
Velocity VerletYesHighHighMolecular dynamics, damping
LeapfrogHalf-stepMed-HighVery HighGame physics, particle systems
Position VerletNoMediumHighSprings, ropes, cloth simulations

5. Implementation Examples in Processing

Verlet integration allows for easy implementation of real-time physics visualizations.
Example code for visual implementation using Processing is available for download on Patreon.

Bouncing Ball (Position Verlet)

sample_1_PositonVerlet

Cloth Simulation (Grid of Particles)

sample_2_ClothSimulation

6. Limitations and Considerations

While powerful, Verlet integration has its caveats:

  • No Explicit Velocity in Position Verlet:
    Hard to model air resistance or friction. Use Velocity Verlet or Leapfrog when velocity matters.
  • Not Ideal for Rigid Constraints:
    Complex rigid bodies or rotation may require constraint solvers or hybrid methods.
  • Numerical Stability Depends on Time Step:
    Large Δt leads to instability. Use smaller steps for high-frequency systems.
  • Energy Conservation May Delay Damping:
    Additional damping must be introduced to stabilize behavior.

7. Verlet integration

Verlet integration is an excellent tool for simulating natural motion and oscillation. It is simple, visually expressive, and works across a wide range of applications, from generative visuals and interactive art to game physics and scientific modeling.

Reference:Wikipedia Verlet integration

Recommended Book / Generative art for beginner

Generative Art: A Practical Guide Using Processing – Matt Pearson

Generative Art presents both the techniques and the beauty of algorithmic art. In it, you’ll find dozens of high-quality examples of generative art, along with the specific steps the author followed to create each unique piece using the Processing programming language. The book includes concise tutorials for each of the technical components required to create the book’s images, and it offers countless suggestions for how you can combine and reuse the various techniques to create your own works.

Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.
—–
► Generative Art: A Practical Guide Using Processing – Matt Pearson
Publication date: 2011. July

 Support my Website
By using our affiliate links, you’re helping my content and allows me to keep creating valuable articles. I appreciate it so much:)

BGD_SOUNDS (barbe_generative_diary SOUNDS)

barbe_generative_diary SOUNDS will start sharing and selling a variety of field recordings collected for use in my artwork “Sound Visualization” experiments. All sounds are royalty-free.

Link / BGD_SOUNDS on bandcamp