# myphysicslab – 2-dimensional spring

this simulation shows a single mass on a spring, which is connected to the ceiling. the mass is able to move in 2 dimensions, and gravity operates. does the motion look random to you? watch the graph for a while and you'll see its actually an intricate pattern.
you can change parameters in the simulation such as gravity, mass, spring stiffness, and friction (damping). you can drag the mass with your mouse to change the starting position. if you don't see the simulation try instructions for enabling java. scroll down to see the math!

## physics of the 2-dimensional spring

2d spring variables
an immoveable (but draggable) anchor point has a spring and bob hanging below and swinging in two dimensions. regard the bob as a point mass. define the following variables:
• θ = angle (0 = vertical, increases counter-clockwise)
• s = spring stretch (displacement from rest length)
• l = length of spring
• u = position of bob
• v = u'= velocity of bob
• a = u''= acceleration of bob
define some constants:
• r = rest length of spring
• t = position of anchor point
• m = mass of bob
• k = spring constant
• b = damping constant
• g = gravitational constant

i & j unit vectors
note that for this simulation the vertical dimension increases downwards. we'll need the standard unit vectors i, j. we use bold and overline to indicate a vector.
• i = unit vector in horizontal direction
• j = unit vector in vertical (down) direction
there are three vector forces acting on the bob:
• fgravity = m g j = gravity acting straight down
• fspring = −k s (sin θ i + cos θ j) = the spring pulling (or pushing) along the line from bob to anchor point.
• fdamping = −b (vx i + vy j) = damping (friction) acting opposite to the direction of motion of the bob, ie. opposite to its velocity vector.
summing these forces and using newton's second law we get: m a = fgravity + fspring + fdamping m (ax i + ay j) = m g jk s (sin θ i + cos θ j)b (vx i + vy j) we can write the horizontal and vertical components of the above as separate equations. this gives us two simultaneous equations. we also divide each side by m.
 ax = − k⁄m s sin θ − b⁄m vx (1a)
 ay = g − k⁄m s cos θ − b⁄m vy (1b)
these are the equations of motion. it only remains to show how s sin θ and s cos θ are functions of the position of the bob. the displacement of the spring s is the current length of the spring minus the rest length.
 s = l − r (2)
from the pythagorean theorem we can get the length of the spring l in terms of from the position of the bob, u, and the position of the anchor point, t.
 (3)
the sine and cosine of the angle θ are:
 sin θ = (ux − tx)/l (4a)
 cos θ = (uy − ty)/l (4b)

## numerical solution of the 2-dimensional spring

to solve the equations of motion numerically, so that we can drive the simulation, we use the runge-kutta method for solving sets of ordinary differential equations. since the runge-kutta method only works with first-order differential equations, we convert the two second-order equations (1) to the following four first-order equations. ux' = vx uy' = vy vx' = − km s sin θbm vx vy' = gkm s cos θbm vy keep in mind that s sin θ and s cos θ are functions of the position of the bob, ux, uy, as given in equations (2-4).