Cloth Simulation

A demo of a simple physics simulation based on the (now classic) paper by Thomas Jakobsen, “Advanced Character Physics”.

Tags: physics, simulation, particles, cloth

Summary

This is based on a mechanism to manipulate particles called “Verlet integration”. The key elements of this approach are:

The resulting system tends to be stable, given a fluid framerate. That is, if there’s not a lot of variation between the time-steps.

This can be used in games, for example, to produce interesting effects, but be careful if you plan to use it in elements directly related to gameplay (like the position of characters in a side-scroller, for example), because its behaviour can be unpredictable when the framerate is not fluid. Unless, of course, you’re creating a game based on quirky physics that allows for some randomness. In any case, this could be remedied by forcing a steady time-step at each frame, but then the simulation’s perceived speed will fluctuate. It’s basically a balancing act.

The beauty of this system, at least for me, is that this illustrates how seemingly “complex” behaviour, like how a piece of cloth should look like when moving in space, can be emulated by very simple rules (forces, constraints) applied to a simple system (just a group of particles). Particles individually do not possess any “knowledge” about the overall system, they simply move around trying to satisfy the constraints that affect them, and yet the global behaviour simply emerges from those small individual operations. I just find that deeply fascinating.

For more details about the physics simulation process and the math behind it, you may refer to:

Links

ChangeLog

Current revision: rev2

2013-06-12

    * Updated dependencies.
    * Don't restart the simulation when gravity is changed.

2013-03-19

    * First version of this program.

To Do