Matteo Piano

Software Security Engineer

Back

The mass-spring model

It is now time to start creating a mesh with cloth-like properties. The technique which will be employed to achieve that is called Mass-Spring Model since it uses a system of springs and particles to simulate the flexibility of fabric materials. The particles are disposed as a 2-dimensional grid and are connected using horizontal, vertical and oblique springs as shown in the image below.

Connections between cloth particles

This structure provides to the cloth flexibility and at the same time should not allow too big deformation (which would not look natural). Once the system is in place, we need to define the physics to control its behavior. First, each particle is subjected to the force of gravity, which can be represented just as a vector point down on the Y axis, then the internal forces generated by the springs must be evaluated. This is done using Hooke’s law which states that the force generated by a spring is proportional to its displacement times the spring constant: F = K * dx. This force is then applied in opposite directions to the two particles attached to the ends of the springs. After calculating the forces in place, those must be applied using the equations of motion to evaluate the position of the particles at the next time step. Different integration methods exist to perform this operation and they are mainly divided in two categories: explicit methods and implicit methods. The first ones derive the next state of the system from the current one and are usually easy to compute though often leading the mathematical instability. The seconds use both the current and the future state in the calculations and are usually more precise and stable though being more computationally complex. The final decision was made in favor of the Verlet explicit integration method as it was suggested by different sources for providing solid results:

dx = (position - old_position) * (1 - DAMP) + acceleration * dt * dt

In the formula, position is the current position in 3D space of the particle, old_position is the position at the previous time step, DAMP is a dampening factor and acceleration is the acceleration derived from the forces accumulated on the particle. After implementing this, we were ready to execute the cloth simulation for the first time and the results is shown in the short video clip below.

It is clear that the cloth is stretching too much because the forces generated by the springs are not strong enough to balance with the acceleration of gravity. To correct this behavior, the spring constants were incremented and this caused the previously mentioned instability problems to verify as shown in the clip below. The reason for this is that the employed equations are so called stiff which means that when plugging in large numerical values (big time steps or forces) they have the tendency to diverge to infinite values.

In the next posts I will try to find a good strategy to solve these issues and have a stable model and, successively, implement collision detection for the cloth object.