Cloth Simulation with Verlet Physics, Explained

After reading this you will understand how a grid of point masses and simple distance constraints produces convincing cloth, why relaxation keeps the fabric from stretching, and how to read the stress colours to predict where a tear will run.

What the simulator is doing

The cloth is not a surface. It is a grid of 44 × 28 = 1232 point masses, each connected to its neighbours by short springs called constraints. The top row of points is pinned. Everything else falls under gravity and blows in the wind, held together only by the demand that each thread stay close to its rest length.

Here is the hook. Grab a point near the bottom and pull it sideways. You do not just move that one point. A line of threads between your pointer and the nearest pins turns white, then edges toward red, because those threads carry the load. The rest of the cloth stays blue and slack. You are watching a load path form in real time, the same structure an engineer draws for a hanging cable.

Every frame runs two stages. First each free point moves according to Verlet integration under gravity and wind. Second, a few relaxation passes nudge every constraint back toward its rest length. Neither stage alone gives cloth. The combination does.

When this model is useful and when it is not

Use this simulator to build intuition about mass-spring systems, load paths, and how local failure spreads. It reproduces the qualitative behaviour of hanging fabric well: draping folds, swinging under a swung pointer, and the way a single cut rips onward under tension.

Do not read it as a fabric-testing lab. The threads are massless linear constraints, not woven yarn with bending stiffness and friction between fibres. There is no self-collision, so the cloth passes through itself. The failure threshold is a single number chosen for feel. Real textiles have direction-dependent strength (warp versus weft), hysteresis, and fray behaviour this model does not touch.

The relaxation step treats the fabric as inextensible. Real cloth stretches a little and springs back. This model instead forbids stretch and lets you tune how hard it enforces that rule through the number of passes.

The Verlet update, and why it is stable

Ordinary integration stores position and velocity. Verlet integration stores position now and position last frame, and treats the difference as an implicit velocity. The update for one point is:

x_{t+1} = x_t + (x_t - x_{t-1}) + a\, \Delta t^2

Here x_t is the current position, x_{t-1} is the previous position, a is acceleration from gravity and wind, and \Delta t is the timestep. The term (x_t - x_{t-1}) is the implicit velocity: whatever the point moved last frame, it keeps moving unless a force or a constraint changes it.

The payoff comes at the constraint step. When relaxation shoves a point back into place, it edits x_t directly. Velocity is never touched explicitly, so there is no mismatch between a corrected position and a stale velocity. Energy does not blow up. That is why ragdolls and cloth in games use this scheme: you can yank the geometry hard and the system stays calm.

Constraints and the relaxation that enforces them

Each thread wants a fixed rest length L_0. After the Verlet move, most threads are wrong: some too long, some too short. One relaxation pass looks at each thread, measures its current length d, and moves both endpoints toward each other (or apart) to fix half the error each.

\text{correction} = \frac{d - L_0}{d} \cdot \frac{1}{2} (x_b - x_a)

In words: d - L_0 is how far the thread is from its target. Dividing by d turns that into a fraction of the current vector between the two points x_a and x_b. The factor \tfrac{1}{2} splits the fix between them. Pinned points do not move, so a thread attached to a pin gives its full correction to the free end.

One pass fixes each thread in isolation, but moving one point breaks its other threads. So the passes repeat. This is Gauss-Seidel iteration. Three passes per frame get you close enough to inextensible that the eye is satisfied.

Reproducing the demo defaults

Load the tool with its defaults and follow one thread. Take a horizontal thread with rest length L_0 = 10 units. Suppose gravity has pulled its two endpoints apart so the current length is 13 units, with point A at x = 0 and point B at x = 13 along one axis.

  1. Length error: d - L_0 = 13 - 10 = 3 units. The thread is 30% too long.
  2. Correction fraction: \tfrac{d - L_0}{d} = \tfrac{3}{13} \approx 0.2308.
  3. Vector between points: x_b - x_a = 13. Half of it is 6.5.
  4. Each endpoint moves 0.2308 × 6.5 ≈ 1.5 units inward. A goes to 1.5, B goes to 11.5. New length 10, exactly L_0.

One pass fixed this thread completely because nothing else disturbed it. In the full cloth the neighbouring threads pull those same points, so after pass one the length might land at 10.4, after pass two at 10.05, after pass three at 10.006. Watch that convergence in the widget below.

Starting from a thread stretched to 13 units against a rest length of 10, each relaxation pass removes about 77% of the remaining error when only one competing neighbour pulls back. Pass 1 lands near 10.4, pass 2 near 10.05, pass 3 near 10.006. More passes give a stiffer, more inextensible cloth at a higher compute cost.

Reading the stress colours

The colour of a thread encodes its current length relative to rest length. Blue means slack (shorter than rest, under compression the model cannot really carry). White means taut (near rest length, carrying tension). Red means near breaking, which the tool sets at about 2.4 times rest length.

Turn that into numbers. A thread at rest length shows white. Stretch it to 1.5× and it warms toward orange. At 2.4× it is bright red and, if tearing is on, it snaps. The chart below maps stretch ratio to a stress score on a 0 to 1 scale, where 0 is fully slack and 1 is at the break point.

Stress stays at zero while the thread is slack, then climbs linearly from rest length (ratio 1) to the break point at ratio 2.4. The vertical marker is the snapping threshold.

Watch load paths, not individual threads. When you pull, a connected chain of white threads links your pointer to the pins. That chain carries the weight. Everything off the path stays blue. Cut one thread on the path and the load instantly reroutes: neighbouring threads whiten as they pick up the slack.

Why a small cut rips onward

This is the most instructive behaviour to trigger deliberately. Make one cut in the middle of a taut region. The two threads that used to share the load with the cut thread now carry more, so they stretch further, so they turn redder. If tearing is on, the reddest one snaps next, right at the edge of the hole. Then its neighbour inherits the load, and the tear runs.

Do not conclude that real fabric tears exactly this way. The model concentrates stress at a hole edge, which is genuinely why cuts propagate, but real fabric also fights back with fibre friction, fray, and warp-weft direction that this grid ignores. The mechanism is right; the numbers are not calibrated to any real cloth.

The stress concentration is the point. In a continuous sheet, tension that flowed through the removed material must detour around the gap, and the detour crowds into the material right beside the hole. That crowding is why crack tips in metal, tears in paper, and rips in fabric all advance from an existing edge rather than starting fresh in undamaged material.

Common mistakes when reading the sim

Three misreadings come up often.

Treating blue as broken
Blue means slack, not failed. A slack thread is still there and still connected; it just carries no tension right now. The intact-thread count is the true measure of what remains.
Expecting stretch to persist
Because relaxation enforces near-inextensibility every frame, threads snap back to rest length almost immediately once you release them. The colour returns to white or blue within a frame or two. Any lasting red means you are still loading that thread.
Blaming wind for instability
If the cloth jitters wildly, the cause is usually a large timestep or too few relaxation passes, not the wind slider. Verlet stays stable across a wide wind range because velocity is implicit; the failure mode is numeric, not physical.

Related simulations to try next

If mass-spring dynamics interest you, several other simulations here explore neighbouring ideas. The Double Pendulum shows how a two-body constrained system becomes chaotic, a sharp contrast to the cloth's stable relaxation. The Galaxy Collision Simulator integrates thousands of point masses under gravity without constraints, so you can see what Verlet-style integration looks like when nothing pulls the points back. For fields and flows rather than particles, the Wave Interference tank and the Magnetic Field Lines tool build intuition about superposition and field structure. The Chladni Plate Patterns demo shows standing waves on a constrained plate, a stiffer cousin of this flexible sheet.

Frequently asked questions

Why does the cloth pass through itself?

There is no self-collision test. Adding one would mean checking pairs of threads every frame, which for 1232 points is expensive. The model trades that realism for speed. Real cloth stacks and folds because fibres cannot occupy the same space; this simulation has no such rule.

What controls how stretchy the cloth looks?

The number of relaxation passes per frame. One pass leaves visible stretch, because each pass only removes about three quarters of the length error. Three passes get residual stretch under one percent for a lightly loaded thread, which reads as inextensible fabric.

Why exactly 2.4 times rest length for breaking?

It is a tuned value chosen so tears feel neither instant nor impossible. Lower it and the cloth is fragile; raise it and it becomes almost unrippable. It is not a measured property of any material.

Does the wind add energy that could destabilise the sim?

Wind is an acceleration applied in the Verlet step, so it feeds through the implicit velocity like gravity does. It moves the cloth but does not cause the runaway growth you would see from an explicit spring force at a large timestep. Instability comes from the timestep and pass count, not the wind.

How is velocity stored if I only see positions?

It is not stored separately. Velocity is the difference between the current and previous position, recomputed implicitly each frame. When you grab and fling a point, the fling speed is simply how far it moved in the last frame while pinned to your pointer.