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!
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?
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.
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 DOF-system!
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.
The sliders control frequency.
Some things to try: