... about ... what's new ... how to ...

Saturday, January 2, 2010

Cloth Simulation

Since I have no knack for sewing or knitting, I decided to give something similar a try on my computer screen:) As a quick and fun programming exercise, I wrote this simple cloth simulator based on the mass-spring model. The cloth is a simple grid of 13x13 nodes, each node connected to its neighbors by three different types of springs (structural, shear, and flexion). The cloth is initially suspended in air, and each end gets detached by a programmed keystroke. The node position is determined by the influence of the internal spring forces, the gravity and the wind. And lastly, the simulation is based on the leap-frog numerical integration method, slightly a higher order of accuracy than the Euler.
There're many features that could be added to improve the system, like adding a few more user-interaction GUI controls for the spring constants and the integration timestep size, as well as improving the lighting and rendering aspects, not to mention prettying up the scene a bit:)
Over all, it was a fun and rewarding exercise which kept me occupied for a few days.