myphysicslab – roller coaster
if you had first-year physics in college, you probably solved lots of problems with a ball rolling down a flat inclined plane. did you ever wonder how to solve for the motion with a curved surface instead?
of course the same principles apply, but the forces are changing as the slope changes. so the math gets a bit more interesting!
you can change the track shape by clicking a button below. you can change parameters such as gravity or damping. you can drag the ball 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!
click to select a different track:
is it correct? using energy to decide
how can we decide whether this simulation is correct? we know that the ball should not spontaneously gain energy, nor mysteriously lose energy. so we can look for situations that may violate this constraint.
try dragging the ball to a certain height on a curve, and letting go. if damping (friction) is set to
, the ball should reach the same height on the track again and again. it shouldn't gain or lose height at the moment that it reverses direction. at that moment the velocity is zero, and all the energy is gravitational (potential) energy.
here is a more sensitive test: click on the circle track. with damping set to 0
, move the ball to the apex of the circle and let the ball go. when you release the ball it has zero velocity, and only potential (gravitational) energy. the ball will fall to one side and then roll back up the other side to almost where you released it from. it should then reverse direction and fall the other way.
if instead the ball crosses over the top of the circle, you know that it has gained some energy because it will have non-zero velocity at the top of the circle. this shows the simulation is imperfect.
to observe the energy directly, click the "show energy" checkbox. the energy shown is the sum of the kinetic and gravitational energy.
kinetic energy = 1⁄2 m v2
gravitational energy = m g y
where m =
mass, v =
velocity, g =
gravity constant, and y =
vertical position. with damping off, total energy should remain constant. instead, you will see the energy fluctuating quite a bit. this is due to some shortcuts used in the simulation programming. for example, we use a table to represent the curve (see below) and the slope at a given point is approximated somewhat crudely.
perhaps you can appreciate that programming a simulation like this involves tradeoffs between correctness, display speed, and programming effort!
physics of the simple roller coaster
a ball moves along a curved track. we assume that the ball cannot leave the track, but is free to move along its length. we have two variables
- p = position on the track (measured by path length along the track)
- v = velocity
we pick some point on the track to be position p = 0
and pick a direction along the track to be positive. then the position is equal to the length of the track, from the origin to that point.
the gravity force on the ball is shown in the diagram as m g
pointing downwards. the component of this force that is parallel to the track is what causes the ball to accelerate. the steeper the track, the faster the acceleration.
be the slope of the track at this point. let θ
be the angle between the gravity vector
and the slope vector (the slope vector points in the direction where p
increases). then we can write the force equation for gravity as
where m =
mass, a =
acceleration, and g =
the gravitational constant. if we add a damping (friction) force that is proportional to the velocity we get
f = m a = m g cos θ − b v
is a constant determining the amount of damping. we can find cos θ
by using the formula for the angle between two vectors a, b
where the numerator is the dot product
, and the denominator is the product of the lengths
. (note that we indicate vectors with bold letters here.) define our two vectors by
- a = (1, k) the slope vector, pointing in the direction of increasing p
- b = (0, −m g) the gravity vector
this leads to
cos θ =
−k m g
m g √(1 + k2)
√(1 + k2)
now we can write equation (2) as
− b⁄m v
√(1 + k2)
where we keep in mind that the slope k
is really a function of position k(p)
. that is, given the position, we need to find the slope at that point. this is the equation of motion for the roller coaster.
the two equations needed for the runge-kutta numerical solver
are given by:
p' = v
− b⁄m v
√(1 + k(p)2)
here we indicate that the slope k
is a function of position p
by the notation k(p)
there is a small additional complication in that the track can loop around. this requires us to determine whether the path is increasing (in the sense of increasing p
) to the left or to the right. this affects the direction of the slope vector and can change the sign of cos θ
. this enters into the first term of equation (3) as a possible multiplication by −1
finally, vertical lines need a special treatment, because the slope is infinite there. when we detect that the slope is vertical, equation (3) becomes:
a = −g − b⁄m v
measuring the length of a curve
to program this simulation on the computer we need to find the relationships between:
- p = position (measured by path length)
- k = slope of the track
- (x, y) = position in 2 dimensional space
for the correctness of the simulation, the most important relationship is p → k
because this is used in the differential equation, represented by the function k(p)
. the other relationships can be less exact because they are only used to update the graphics or for user input. for example, the relation p → (x, y)
is used to update the graphics. and the relation (x, y) → p
is used for dragging the ball.
suppose that the curve can be defined parametrically by two functions x(t), y(t)
. that is, to sweep out the curve we increase the variable t
to some value. and for each value of t
we can find the position of the curve from the functions x(t), y(t)
. for example, a circle can be defined parametrically by
x(t) = cos t
y(t) = sin t
varies from 0
. in two dimensions, the length of a curve can be determined by the path integral
where the limits of integration are the starting and ending value of t
corresponding to the points you want to measure between.
we can try to solve the path integral analytically to get the needed relations. for some curves this is easily done. for the circle, the path integral is especially simple:
p = ∫ √ (sin2t + cos2t) dt = ∫ 1 dt = t
but for most curves the integral is too difficult to solve. for example, the "hump" curve in the simulation is defined by a simple polynomial
x(t) = t
y(t) = 3 − 7⁄6 t 2 + 1⁄6 t 4
but this leads to the following nasty integral which even mathematica
faced with difficult integrals, we instead take an approximate numeric approach and construct a table to represent the curve, as explained below.
representing the curve with a table
here is how we construct a table to represent the curve. assume we have the functions
which describe the curve parametrically. suppose we want the curve to be defined from
t = −3
to t = 3
. then we start forming a table that would look something like this:
|. . .
||. . .
||. . .
||. . .
each row of the table represents a point on the curve. the table is constructed by starting with t = −3
and setting p = 0
. we then find x, y
from the equations x(−3), y(−3)
. to add each row, we increase t
by some small increment (here it is 0.01) and find the corresponding x(t), y(t)
. we can then find p
either by numerically evaluating the path integral (see above
), or as a cruder and simpler method we can just increase p
by the distance to the previous x, y
point. i've chosen the simple, crude method for the program here (a refinement would be to fit a polynomial to 3 or 4 neighboring points).
once we have the table, we can implement a routine that maps p → k
. this can be done quickly by using a binary search algorithm, since the p
values are all sorted. suppose that p
is closest to the i-th
value in the table, so that p[i] < p < p[i+1]
represents the list of p
values in the table. then an approximate value for the slope is given by
y[i+1] − y[i]
x[i+1] − x[i]
where x, y
are the tables of x, y
values. similar methods can be used for finding the relation p → (x, y)
. for slightly better accuracy we can use a polynomial interpolation of the 4 points in the table that are nearest to the value of p
we are seeking.
the routine that maps (x, y) → p
is used less frequently and doesn't need to be as efficient. i use a linear search through the entire table to find the point in the table that minimizes the distance from the given (x, y)
to the curve.