Springs

Hooke's Law
Force is proportional to displacement



K = spring constant
d = displacement from rest length

Spring is modeled as 2 point masses, linked by the spring

Equal but opposite force is applied to each end



When spring is stretched, spring force pulls masses together


When spring is compressed, spring force pushes masses apart



Vector between the two points is used to compute both the displacement and the direction of the force:

    Vector3 v = point1 - point0;
    float displacement = v.length() - restLength;
    v.normalize();
    Vector3 force = springConstant * displacement * v;

Example: spring0.cpp




next