... 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.

2 comments:

sukogirl said...

neat! you have some mad skills. could you possibly make a program that will make a three dimensional shape in to 2D for the purposes of making patterns for sewing clothes or stuffed animals or bags?

cignoh said...

wow, i'm so impressed! what did you program in?

when i was in grad school, they offered a physically based modeling class that i wanted to take, but wasn't able to fit into my schedule. i started to audit it, but there is really no point in auditing a class like that, you have to do the assignments to get anything out of it. anyway, i'm totally impressed that you could do something like that on your own for fun! i like how you demoed falling, then wind, then falling onto sphere, followed by wind when it's on sphere, then falling onto the plane finally, nice to see all the stages and different behaviors... very cool!