Springs

It is time to investigate what it means to have a deformation in our physics system. By deformation, I mean that the vertices of our shapes are no longer fixed to one point within the model. Towards this end, we will begin by investigating springs.

Undamped Spring Explanation

An undamped spring is one that never stops oscillating. Once an undamped spring starts moving back and forth, it moves back and forth forever.

From Newton's second law, we know that the sum of all the forces acting on an object will equal zero. We know that one of these forces is mass times acceleration, but for a spring we will add another force which uses the spring constant. This force grows in proportion to the displacment that spring is currently set at. So, if the spring is currently displaced 10m, the effect of this force will be greater than if the spring was at equlibrium, which means that it is displaced by 0m. This should make sense intuitively.

One thing to note is that a damped spring has three cases:

I will not go into the mathematical details as to why this happens, as the links at the end of this video can very easily tell you. Just know that they are dependent on your values of c and k, so choose wisely for your use case.

The equation is given as such:

ma + kx = 0
where m is the mass, a is acceleration, k is the spring constant, and x is the current displacement from the rest position.

We can define an undamped 1D spring in code like so: #SNIPPET softbody_1/snippet1.cpp Note that we are just using Euler Integration here.

Undamped Springs Example

Damped Spring Explanation

Undamped springs are loads of fun, but if we want to make a softbody physics system, we're going to want our simulation to stop oscillating at some point. That is where the viscous damping constant (c) force comes in. The damping force grows in proportion to the velocity. The equation is given as such:

ma + cv + kx = 0
where m is the mass, a is acceleration, c is the damping constant, v is the velocity k is the spring constant, and x is the current displacement from the rest position.

This force produces the most effect when the velocity is largest. Let's try to intuit exactly what this means. When our spring is extended downward, it will want to move upward to return to its equlibrium position. At this point, the displacement (x) will be negative and the velocity (v) will be positive. Since the signs are different, we can see that our spring force will be mitigated by the damping force. Hence, we damp!

We can define a damped 1D spring in code like so: #SNIPPET softbody_1/snippet2.cpp Note that we are just using Euler Integration here.

Damped Springs Example