Project 5a: Mass-Spring Locomotion

CS 7492, Spring 2021

Due: TBD

Objective

The purpose of this project is for you to learn about physical simulation by creating a mass/spring system. Mass/spring systems can be used to explore a wide variety of biological phenomena. For this project, you will create a mass/spring simulator and then use it to demonstrate some form of animal locomotion. The form of locomotion is up to you. It can be crawling, walking, swimming, hopping, or flying. Depending on the type of locomotion that you choose, you will include interaction between your animals and the ground, water, or air. In order to cause your creatures to move, you will modify the rest lengths of their springs over time. You can choose to simulate your animals in 2D or 3D.

Mass/Spring Creature Simulation

This project is more open-ended than prior course projects. You can choose the kind of virtual creature you will make. You can attempt to model a real-world animal, or you can make up a body plan of your own design. Your creature may swim, crawl, walk, jump, fly, or roll. You can choose to create just a single creature, or you can make multiple virtual animals. Your simulated world can be either 2D or 3D. The main goal is to demonstrate creature locomotion through mass/spring simulation.

You have considerable freedom in this project as to the type of creature you simulate. There are, however, a few requirements for this project in order to make sure you challenge yourself sufficiently. Here are the requirements of your simulator:

Beyond the above requirements, you are free to embelish the simulation in any way that you see fit. You can work to draw your creature in a pleasing manner. You can add various GUI elements, such as buttons and sliders to help control your creature. You can automatically cause the camera to follow your creature.


Suggested Approach

Whether or not you ultimately plan to create a 2D or a 3D simulation, I recommend that you begin your project in 2D, since this is easier to debug.

Begin creating a simulator by defining a class of point masses. These points should have mass, current position, and velocity. You may also find it useful to have a force or acceleration associated with each point. This is quite similar to the flocking assignment, and you may even wish to borrow code from this earlier assignment. At first, you can create a collection of points at random positions and with random velocities. Store them in a list. Then, include an update step that moves each point according to their velocity, and draw their positions after each simulation step. Next, add a simple force, namely viscous damping. Including damping should cause your points to slow down and eventually come to rest. You may then wish to add gravity. Depending on your ultimate goal, you may also wish to confine the points to a fixed region of the screen, or at least keep them from passing through the floor.

Once you have point masses implemented, you should add springs. The easiest way to define a spring class is to have each spring have a reference to a pair of point masses. Each spring should also have associated with it a rest length and a spring constant. During the simulation loop, add a step that calculates the forces on the pair of points that a given spring uses. This will be based on the deviation of the distance between the points from the rest length. Add these forces to the per-point accumulated force.

When testing your springs, it is best to work with just two point masses and a single spring connecting them. It is also useful to be able to take a single step in the simulation, instead of causing the simulation to run continuously. Start your point masses at a distance away from each other that is different than their rest length, say by a factor of 20%. When you simulate the spring motion, be sure to turn on some form of damping, such as viscous damping or spring damping. You will probably have to tune the damping and spring constants until you find parameter settings that cause a spring to oscillate but then finally come to rest. Your first few attempts may well have the points flying off the screen.

Once you have one spring that oscillates and then comes to rest, it is time to put together a small collection of springs. Create a triangle that is formed by three springs that connect three point masses. See if you can drop the triangle onto a virtual ground. If the spring forces are too weak, the triangle will collapse. Modify the spring constants and damping coefficients until the triangle is strong enough to hold up under its own weight.

Once you can create a fairly rigid triangle, it is time to add virtual muscles. Allow some (or all) of your springs to oscillate over time. You will want to give each spring at least three new parameters: frequency, phase, and amplitude. These are attributes of a sine wave that defines how the rest length of the spring varies over time. At each time-step, each spring should adjust its rest length based on the sinusoid. You can test this by making just one of the triangle's springs oscillate.

With the ability to create oscillating springs, you should be able to build virtual creatures that move. You may have to add additional effects such a simple fluid force on the springs, or a friction force due to the ground that influences a point mass.


Programming Language

For this assignment, you may use any programming language that you wish. You may use Processing, but you are also free to use any other language instead.

Project Presentations

Each of you will demonstrate your project to the class. These demonstrations will take place during the time-slot that has been assigned for our final exam. You can demo your project either by playing a video or by giving a live demonstration. These project demonstrations will be short -- five minutes maximum. Plan to bring a laptop to class during project demo day.

Turning In Your Assignment

You will turn in a write-up that describes your simulator and the creature that you created. Include in this document some still images of your creature. Your project description can be a PDF, an MS Word document, or an HTML document. Also, you should turn in the source code for your project. You will be graded based on your project presentation and your write-up. Although I may look through your source code, I will not attempt to run your program. Your written description and your source code should be zipped up and turned in on T-square.


Authorship Rules

The code that you turn in must be entirely your own. You are allowed to talk to other members of the class and to the teacher about general implementation issues. It is also fine to seek the help of others for general programming questions about Processing. You may not, however, use code that anyone other than yourself has written. Code that is explicitly not allowed includes code taken from the Web, from books, or from any source other than yourself. You should not show your code to other students. Feel free to seek the help of the teacher for suggestions about debugging your code.