Cloth Simulation: Particle Systems and Constraint Solving

simulator advanced ~12 min
Loading simulation...
15×15 cloth mesh — 225 particles with distance constraints draping under gravity

A 15×15 grid of particles connected by distance constraints, integrated with Verlet. Five constraint solver iterations per frame produce realistic draping with minimal stretch. Wind adds dynamic secondary motion.

Formula

Verlet: x_new = 2x - x_old + a × dt²
Constraint correction: Δx = 0.5 × (|p2-p1| - rest_length) × (p2-p1)/|p2-p1|

Fabric in the Machine

Cloth simulation is one of the most visually rewarding challenges in computer graphics. From Batman's cape to the flags in Assassin's Creed, every piece of simulated fabric starts as a flat grid of particles connected by invisible springs. The art lies in making these simple connections produce the rich, flowing behavior we associate with real textiles — silk, denim, chainmail each requiring different parameters.

Position-Based Dynamics

Modern cloth engines use Position Based Dynamics (PBD), pioneered by Matthias Muller and collaborators. Instead of computing forces and integrating accelerations, PBD directly moves particles to satisfy constraints — distance constraints prevent stretching, collision constraints prevent penetration, and bend constraints control fold stiffness. The result is a robust, stable simulation that rarely explodes even under extreme conditions.

The Constraint Solver

Each frame, gravity and wind displace the particles. The constraint solver then iterates through every constraint, nudging connected particles toward their rest distance. More iterations mean stiffer cloth but higher CPU cost. Real-time engines typically use 3-8 iterations — enough for convincing fabric without breaking the frame budget. This simulation lets you see how iteration count directly affects cloth behavior.

Wind, Collision, and Self-Intersection

Gravity alone produces static draping. Wind transforms cloth into a dynamic, living surface — flags snap, capes billow, curtains flutter. Wind forces are applied per-triangle based on face normal and wind direction, creating aerodynamic lift and drag. Collision detection keeps the cloth from passing through characters and scenery. Self-collision — preventing the cloth from passing through itself — remains one of the hardest problems in real-time graphics.

FAQ

How does real-time cloth simulation work?

Cloth is modeled as a grid of particles connected by distance constraints. Each frame, gravity and wind move the particles, then a constraint solver iteratively corrects particle positions to maintain the original link distances, preventing unrealistic stretching.

What are structural, shear, and bend constraints?

Structural constraints connect horizontal and vertical neighbors (resist stretching). Shear constraints connect diagonal neighbors (resist shearing). Bend constraints connect particles two steps apart (resist folding). Together they approximate fabric behavior.

Why use Verlet integration for cloth?

Verlet integration is position-based and inherently stable, making it ideal for constraint-based systems. Velocity is implicit in the position history, so constraints can directly modify positions without separately tracking and correcting velocities.

How do games handle cloth collisions?

After each constraint solve, particles are tested against collision objects (spheres, capsules, meshes). If a particle penetrates a surface, it is projected back to the surface. Multiple collision iterations prevent cloth from passing through objects.

Sources

Embed

<iframe src="https://homo-deus.com/lab/animation-physics/cloth-simulation/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub