CS 491 -- Fall Quarter 2022

Project #7: Mesh of Springs

Due: December 6

100 Points

Note: You cannot use Bonus Days to extend this due date !


This page was last updated: September 5, 2022


Requirements

You get to create a chain spring mesh (like the example in the notes), where all nodes can move in 2D. Its motion will be like a Slinky dangling from your hand.

I have a wrapper program that will give you the basic program, including sliders to control the X and Y locations of the top node. Other sliders will let you control the spring constant, gravity, mass, and damping. Here it is: Coming soon.


struct state
{
	float  x;
	float vx;
	float  y;
	float vy;
};

struct derivatives
{
	float vx;
	float ax;
	float vy;
	float ay;
};


In the GetDerivs( ) function, fill in the equation for the force on each node, taking into account weights, springs, and damping.

Hints

Structure of the GetDerivs( ) Function:


void
GetDerivs( struct state state[NUMNODES], struct derivatives derivs[NUMNODES] )
{
        for( int node = 0; node < NUMNODES; node++ )
        {
                float xm, ym;           // vector from bottom of node #node to preious node
                float xp, yp;           // vector from bottom of node #node to next node

                float sumfx = 0.;
                float sumfy = Mass*Gravity;

                if( node == 0 )  // node #0 is attached to node Y0 by a spring
                {
                        xm = ?????
                        ym = ?????
                }
                else
                {
                        xm = ?????
                        ym = ?????
                }

                float length = sqrtf( xm*xm + ym*ym );          // to normailze the vector
                float stretch = length - LENGTH0;               // amount spring is stretched
                float force = K * stretch;
                sumfx += ?????
                sumfy += ?????

                if( node < NUMNODES-1 )
                {
                        xp = ?????
                        yp = ?????
                        length = sqrtf( xp*xp + yp*yp );
                        stretch = length - LENGTH0;
                        force = K * stretch;
                        sumfx += ?????
                        sumfy += ?????
                }

                float vx = state[node].vx;
                float vy = state[node].vy;
                float v = sqrtf(vx*vx + vy*vy);
                if( v > 0. )
                {
                        force = Cd * v;
                        sumfx -= ?????
                        sumfy -= ?????
                }

                derivs[node].vx = vx;
                derivs[node].ax = sumfx / Mass;
                derivs[node].vy = vy;
                derivs[node].ay = sumfy / Mass;
        }
}

Testing and Debugging

You will definitely need to see if your program is working. Here is the file: Chain2019Wrapper.zip, a graphics wrapper program and all the Visual Studio stuff that goes with it. Just unzip all of this into a separate folder and double click on the .sln file.

Warning #1: This will not compile as-is. There are question marks indicating things you need to fill in.

Warning #2: You might need to tune the key parameters (Mass, K, Cd, Dt) for the speed of the system you are on. (The given values are tuned for my laptop.)

Turn-In

Your electronic turnin will be done at http://engr.oregonstate.edu/teach and will consist of:

  1. Your .cpp file.
  2. A one-page PDF with a title, your name, your email address, a nice screen shot from your program, and the link to the video demonstrating that your project does what the requirements ask for. If you narrate your video, then you get to tell us what it is doing, and we can grade it more accurately.
    Be sure that your Kaltura video is flagged as unlisted.
    A good way to test this is to ask a friend to try to open the same video link that you are giving us.
  3. Leave your PDF file out by itself -- do not place it in any zip files.
  4. Be sure your video convinces me that your chain properly responds to:

This is due at 23:59:59 on the listed due date.

Grading

Item Points
Motion behaves correctly when X0,Y0 is moved 20
Motion behaves correctly when the Mass (Mass) is changed 20
Motion behaves correctly when the Spring Constant (K) is changed 20
Motion behaves correctly when the Damping Coefficient (Cd) is changed 20
Motion behaves correctly when Gravity is changed 20
Potential Total 100