# myphysicslab – roller coaster with spring

this simulation shows a roller coaster with a ball which is also attached to a spring.
you can change the track shape by clicking a button below. you can change parameters such as gravity or damping. you can drag the spring anchor point or drag the ball to change the starting position. if you don't see the simulation try instructions for enabling java. scroll down to see the math!

click to select a different track:
 hump loop circle infinity oval spiral

## physics of the roller coaster with spring

this simulation is a variation of the simple roller coaster, please see that page for more information on the physics and how the simulation is done. the only difference here is that the spring force is added to the differential equation.

roller coaster forces
define the following variables:
• p = (px, py) = position of ball in 2 dimensional space
• q = (qx, qy) = fixed end of spring
• k = slope of track at point p
• r = rest length of spring
• c = stiffness of spring (constant)
• θ = angle between the spring and tangent vector
• m = mass
• g = gravity constant

the width and height of the spring is given by: sx = qxpx
sy = qypy
the length of the spring is then √(sx2 + sy2). the magnitude of the spring force is c (√(sx2 + sy2) − r).  the direction of the spring force is towards q, the fixed end of the spring. the component of the spring force that is parallel to the track is
 f = cos(θ) c (√(sx2 + sy2) − r) (1)
it is this parallel-to-the-track component of the spring force that will accelerate the ball along the track. consider a couple of cases to convince yourself of this: if the spring is perpendicular to the track, then θ ≈ 90° and cos(θ) ≈ 0 so the spring doesn't accelerate the ball. conversely, if θ ≈ 0 then the spring will accelerate the ball in the positive track direction. or, if θ ≈ 180° then the spring accelerates the ball in the negative track direction.

we can find cos(θ) by using the formula for the angle between two vectors a, b
 cos θ = a · b |a| |b|
where the numerator is the dot product, and the denominator is the product of the magnitudes. define our two vectors by
• a = (1, k) the slope vector, pointing in the direction of increasing p
• b = (sx, sy) the spring force vector