From 38d89c1182a61ca4e024e0834ae9187db76c67f8 Mon Sep 17 00:00:00 2001
From: mattkae
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. We will begin with what I believe
- by investigating the most common of all deformations: a weight attached to a spring in two dimensions.
+ vertices of our shapes are no longer fixed to one point within the model. Towards this end, we will begin by investigating
+ springs.
+ 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:
+ Undamped Spring Explanation
+
+
+ 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: +
+ We can define an undamped 1D spring in code like so: +
struct Spring {
+ float mass = 1.f; // Mass of the weight on the end of the spring
+ float k = 4; // Spring Constant, in N / m
+ float force = 0.f;
+ float velocity = 0.f;
+ float position = 0.f;
+};
+
+void updateSpring(Spring* spring, float dtSeconds) {
+ spring->force = spring->k * spring->position;
+ float acceleration = spring->force / spring->mass; // F = ma
+ spring->velocity = spring->velocity + acceleration * dtSeconds;
+ spring->position = spring->position + spring->velocity * dtSeconds;
+}
+
+ Note that we are just using Euler Integration here.
+
+ 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: + +
+ 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: +
struct Spring {
+ float mass = 1.f; // Mass of the weight on the end of the spring
+ float k = 4; // Spring Constant, in N / m
+ float c = 1; // Viscous damping constant, in N / m/s
+ float force = 0.f;
+ float velocity = 0.f;
+ float position = 0.f;
+};
+
+void updateSpring(Spring* spring, float dtSeconds) {
+ spring->force = spring->c * spring->velocity + spring->k * spring->position;
+ float acceleration = spring->force / spring->mass; // F = ma
+ spring->velocity = spring->velocity + acceleration * dtSeconds;
+ spring->position = spring->position + spring->velocity * dtSeconds;
+}
+
+ Note that we are just using Euler Integration here.
+
+