# Spring Time

Hooke’s law is fairly standard material for intro physics classes, and in the previous section we implemented a system that simulates it.

Now let’s take our system and play!

# Let’s Get Physical

Before we get too far into exploring, let’s refine our physics model. In particular, you may have noticed that with enough initial displacement, the mass will cross over the wall that it is attached to (see the example above).

Real springs don’t do that, if you try to stretch or squeeze them enough, they stop wanting to move (this non-linearity is illustrated in the chart below):

Modelling this sort of non-linearity is doable, but for our purposes, we can get pretty close by simply by placing constraints on the length that a spring can take.

We do this in the following example. Try to see what happens when you start the system outside of the constraints. Why is the system behaving like that?

Min Value
0.2
X position
1.45
Max Value
2.5

Here is the implementation of the above simulation. Note that it is now spread across two files to make it easier to think about. The first file is concerned with initialization and display, and the second file is the “math”, which implements the more general algorithms.

Going forward, we will be playing with different ways of initializing and displaying the system while keeping the simulation layer more or less the same.

If you are curious about the details of how the constraint enforcement is implemented, take a look at the second editor. The reason that the system behaves strangely when initialized outside of a constrained region is because the constraint enforcer moves the particle, which to the vertlet integrator looks as though the particle has a very high initial velocity.

# Under Pressure

Once you have spent enough time playing with the previous example, you might become interested in connecting a few springs together to see what happens. One such thing you can do is to connect the springs together between two fixed points (as demonstrated here, as an aside, check out some of Dan Russell’s other animations). For a more formal treatment of this thought, check out this chapter on normal modes from this book on waves.

For a more poetic treatment, consider how physical models might apply to interpersonal relationships.

Let’s reproduce the 2 degree of freedom (DOF)-system for fun. As an exercise, try to modify the code to implement the 3 or 4 or $n$ DOF-system!

Particle 1
1
Particle 2
1.5

# New Wave

Well now that we’ve done so much work, let’s double down. One nice thing about this simulator is that we can approximate a spring with mass (like a slinky) as a collection of masses connected by massless springs. Thus, we can use our simulator to study all sorts of wave behaviors, like transverse and longitudinal waves.

Perceptually, these are interesting because longitudinal waves provide a good model for understanding sound (here is a nice interactive presentation). On the other hand, transverse waves appear in places like violins and other stringed instruments. This page provides a good overview of the physics, and the video below shows this taking place in the real world!

While this is physically intersting, it doesn’t immediately provide a model for generating sound that mimics a violin. An (apparently) convincing way of doing this for a plucked string is called the Karplus–Strong algorithm (the rest of this book is compelling as well).

Anyway, here is a demo which might help to illuminate some of these thoughts! What is going on below is that we have a row of masses connected by springs. The leftmost spring is being driven (i.e. we force it to occupy a particular point in space at a particular point in time), and the right most spring is fixed.

Transverse
1.35
Longitudinal
Off

The sliders control frequency.

Some things to try:

• When the transverse frequency is high, the waves stop travelling. This is due to an effect called impedance. What happens to this effect when you change the damping of the system? What happens when you change the mass of each weight?
• Press run on the editor to restart the simulation. What can you say about the initial transient behavior that you see?
• Try setting Transverse to 0 and pressing run on the editor. This should then allow you to study Longitudinal waves.
• Try changing the rendering code to make the particles smaller. Try adding more particles to the simulation to improve the approximation. Then try only having a few particles. How does the behavior of the system change?
• Use this system to implement a simulator for Fermi-Pasta-Ulam-Tsingou, one of the first experimental mathematics/physics problems.

Tangents: We can actually use the constraint enforcing function to implement one way of solving inverse kinematics problems called FABRIK. An animated explination of the method can be found below:
To tangent the tangent, this paper from disney explores another way of avoiding the traditional approach to solving inverse kinematics problems.