Game Development Reference
In-Depth Information
Application of linear springs is not the only method available to connect objects, but it
has the advantages of being conceptually simple, easy to implement, and effective. One
of the potential disadvantages is that you can run into numerical stability problems if
the springs are too stiff. We'll talk more about these issues throughout this chapter. Also,
the examples we'll cover are in 2D for simplicity, but the techniques apply in 3D, too.
Springs and Dampers
You learned in Chapter 3 that springs are structural elements that, when connected
between two objects, apply equal and opposite forces to each object. This spring force
follows Hooke's law and is a function of the stretched or compressed length of the spring
relative to the rest length of the spring and the spring constant. The spring constant is
a quantity that relates the force exerted by the spring to its deflection:
F s = -k s (L - r)
Here, F s is the spring force, k s is the spring constant, L is the stretched or compressed
length of the spring, and r is the rest length of the spring. The negative sign in the
preceding equation just means that the force is in the opposite direction of the dis‐
placement.
Dampers are usually used in conjunction with springs in numerical simulations. They
act like viscous drag in that dampers act against velocity. The force developed by a
damper is proportional to the relative velocity of the connected objects and a damping
constant, k d , that relates relative velocity to damping force.
F d = -k d (v 1 - v 2 )
This equation shows the damping force, F d , as a function of the damping constant and
the relative velocity of the connected points on the two connected bodies.
Typically, springs and dampers are combined into a single spring-damper element
where a single formula is used to represent the combined force. In vector notation, the
formula for a spring-damper element connecting two bodies is:
F 1 = -{k s (L - r) + k d (( v 1 - v 2 ) • L )/L} L /L
Here, F 1 is the force exerted on body 1, while the force, F 2 , exerted on body 2 is:
F 2 = - F 1
L is the length of the spring-damper ( L , not in bold print, is the magnitude of the vector
L ), which is equal to the vector difference in position between the connected points on
bodies 1 and 2. If the connected objects are particles, then L is equal to the position of
Search Nedrilad ::




Custom Search