Given a set of mass points (vertices) and springs (edges). For each spring connecting two mass points (a,b), the stretch force from a to b as fa→b=ks(b−a) where ks is the stiffness of the spring. The reverse force fb→a=−fa→b=ks(a−b).
For non-zero length spring, let l0 be its length as rest pose, we can expand the equation to
Potential force
fa→b=ks∥b−a∥b−a(∥b−a∥−l0)
The potential energy of the spring is the integral over the displacement length x=(∥b−a∥−l0) and the potential energy is
V=ks(∥b−a∥−l0)2
Note that ks defines the "stiffness" of a spring, while the value of ks has different effect on springs of different resolution. Therefore, we need to normalize each ks by spring length, so that the stiffness is defined on the change in length as a fraction of the original length.
Damping force
Behaves like viscous drag on motion, slow down motion in the direction of motion. However, we should only drag on change in spring length so that the damping force is only on internal, spring-driven motion instead of the whole system.
fa=−kd∥b−a∥b−a(b˙−a˙)⋅∥b−a∥b−a
Standard Form
The standard form of motion describes the external forces as
where K,D,M can be linearized as matrices. Also, zero-length springs can result in constant K,D and typically we use a pre-computed constant M and keep it diagonal by lumping.
Euler's Method (Forward Euler)
xt+dtx˙t+dt=xt+dtx˙t=x˙t+dtx¨t
Forward Euler is simple but only first order accurate, and often goes unstable. In a mass spring system, the velocity is always estimated from the last timestamp. Thus, energy is always increasing exponentially.
Modified Euler
To prevent the error growing too quick, average velocity at start and end of step.
Implicit Euler can be made unconditionally stable, while we need to solve a nonlinear problem for the unknown acceleration, which often involves optimization based solver, such as Newton's method. Therefore, implicit Euler takes longer than explicit method.
Position-based / Verlet Integration
Note that forward Euler is unstable because error is growing exponentially. Masses will move increasingly faster and eventually diverge. Therefore, the idea is to constrain mass positions after each forward step so that it cannot diverge. The constraints will dissipate the increased energy hence stabilize the system.
Generally, the constraints are expressed as "stiffness" of the springs. For example, limit the spring max lengths by
∀a,b∈V.∥a−b∥≤lmax
At each update, do the forward step as normally, then enforce the stiff constraints by adjusting the velocities.