MyPhysicsLab – Roller Coaster with Flight

Instructions: drag the ball, or try changing control values (gravity, damping, etc.)

graph type:       Show Energy

This version of the roller coaster has the ball jump off the track when appropriate. When the ball is on the track, it is colored blue; when in free flight it is colored red.

The spring is activated when the spring stiffness is non-zero, which you can change by clicking "show controls". You can also click the "spring on" or "spring off" buttons to change the spring stiffness.

When Should the Ball Jump the Track?

This simulation is based on the Roller Coaster with Spring. The main difference is that we check for when the ball should jump off the track into "free flight". The key to when this happens lies in the formula for acceleration with uniform circular motion, which is

a = v2/r    (eqn 1)

This is the acceleration, a, needed to keep a projectile moving in a circle of radius r with velocity v. The direction of the acceleration is towards the center of the circle. So, moving faster in a given circle means you need more acceleration. Conversely, moving in a larger circle means you need less acceleration.

Suppose the ball is moving with velocity v over a hill shaped like a circle with radius r. The minimum acceleration (towards the center of the circle) needed to keep the ball on the hill is v2/r. If at any moment the acceleration (towards the center) is less than this, then the ball will fly off the hill.

To apply this to a general curve other than a circle, we need the notion of radius of curvature at a point p on the curve. Let φ= the angle of the tangent to the curve at p. We can express φ as

φ = arctan(dy/dx)

where dy/dx is the slope of the curve at p. We define the curvature κ as the rate of change of the tangent angle φ as we move along the curve.

κ = dφ/ds    (eqn 2)

where s= arc length along the curve. The radius of curvature r is the reciprocal of the curvature:

r = 1/κ

We can estimate this using the table representing the curve. For a given point p we estimate the slope a short distance δ on either side of p. Equation (2) is then approximated by

     arctan(slope at p+δ) - arctan(slope at p-δ)
κ =  ———————————————————————————————————————————
                       2 δ

The radius of curvature r is then the reciprocal of this. And this radius of curvature is what we need to apply equation (1). We know that the ball will stay on the curve as long as the acceleration normal to the curve is greater than v2/r.

In the Simple Roller Coaster we developed the gravity force on the ball. In the Roller Coaster with Spring we developed the spring force on the ball. To determine the acceleration normal (perpendicular) to the curve we use the same calculations except that now we use sin(θ) instead of cos(θ).

Fgravity = m g sin(θ)
Fspring = sin(θ) c (√(sx2 + sy2) - R)

(Please see those pages for the definition of these symbols.) Since we already know cos(θ) we can easily find sin(θ) from

sin(θ) = √(1 - cos2(θ))

Now we can find the acceleration normal to the curve from

Fgravity + Fspring = m a

We then compare the acceleration to that given by equation (1) to determine whether the ball should leave the track. To stay on the track going over a hill, we must have a > v2/r. On the other hand, to stay on the track when going through a valley we need a < v2/r.  (I am glossing over the details of how to determine the correct sign of the acceleration and various other quantities).

Switching to Free Flight

When the ball is on the track, the simulation is controlled by the differential equations given in the Roller Coaster with Spring. In this case there are two variables:

When we detect that the ball should leave the track, we switch the controlling differential equations to those of "free flight". There are then four variables:

The differential equations for free flight are the same as those given for the 2-Dimensional Spring

Finding the Time of Collision

While the ball is in free flight we need to handle collisions with the track. The Colliding Blocks simulation describes some general aspects of collision handling.

When we detect that the ball is below the track, we need to estimate when the collision happened. Define the following variables:

So we have that t0 < tc < t1. There are various ways we could estimate tc. A very crude method would assume constant velocity over the time interval (t0, t1). A step up from this is to assume constant acceleration over this time interval, which is what we choose here. This is not correct because the spring force changes with distance; but if the distance travelled is not too great the spring force will be approximately constant.

We can do this calculation in either the horizontal or vertical dimension (but not both together). To increase the accuracy, we choose whichever dimension had the most travel in the time period. Assume for discussion that the ball travelled more horizontally than vertically, so we will work with the x dimensions only. Define the following variables:


To find xc we use simple geometry to get the intersection of the (assumed straight) trajectory line and the curve. We can derive the formula for constant acceleration from the equations

v = dx/dt
a = dv/dt = constant

After integrating these (see your first-year physics textbook for more info) we get

x(t) = (1/2)a t2 + v0 t + x0    (eqn 3)
a = (v1 - v0)/(t1 - t0)

Here we are taking t to be the elapsed time since t0. Equation (3) gives the horizontal position as a function of time, so we can solve for when the ball reaches the collision point xc. We have two cases depending on whether the acceleration is zero or non-zero. If a = 0 then equation (3) gives the time of collision as

xc = v0 tc + x0
tc = (xc - x0)/v0

If a <> 0 then equation (3) becomes

     (v1 - v0)
xc = —————————— tc2 + v0 tc + x0
     2(t1 - t0)

We can use the standard solution to the quadratic equation to find tc in this case.

Adjusting Velocity During Collision

The next step is to re-run the simulation starting from time t0 up to the calculated (approximate) time of collision tc. If we needed more accuracy we could repeat this process until we get the ball as close as desired to the track. Since we are trying to run the simulation in real-time, we accept the reduced accuracy and just assume the ball is now "close enough" to the track.

The next task is to adjust the velocity of the ball so that it bounces off the track. Define the following vectors:

Some elementary vector algebra gives us

    (A·B)
C = —————  B
    (B·B)

N = A - C
R = C - N    (eqn 4)

The elasticity parameter determines how bouncy the ball is. Let e = elasticity. A perfectly elastic ball will have elasticity e = 1.0 and will bounce forever. An elasticity of e = 0.2 would indicate a rather "dead" ball that doesn't bounce very much. To model this behavior we multiply N in equation (4) by the elasticity to get

R = C - e N

This represents the new velocity that we assign to the ball at the time of collision.

Eventually, the ball will make smaller and smaller bounces. In real life, there comes a time when the ball is back in continuous contact with the ground. To determine whether the ball should "jump back onto the track" and be controlled by the "on the track" set of differential equations, we compare the magnitude of the normal vector e N to the magnitude of the total velocity vector. The test involves the stickiness parameter and looks like this:

if |e N|/|R| < stickiness then "jump back onto track"

If the normal velocity e N is small enough we decide the ball should be back on the track. The stickiness is a parameter on the order of 0.1 that can be changed in the simulation controls.

Multiple Collisions

Now that the collision has been handled, we run the simulation from time tc up to the current time t1. If there are no new collisions detected, then this simulation step is done. However if a new collision is detected, we begin the entire collision handling process over again. We will eventually reach time t1 even if we have to handle multiple collisions along the way.

The figure at left shows a typical situation where multiple collisions occur over one simulation time period because the ball goes into a tight corner at high speed.

Limitations of this Simulation

Unlike the other roller coaster simulations, this one does not have the option to use various tracks. The reason is that having a track that doesn't loop simplified the code considerably. For example, to determine whether there is a collision, we only test whether the ball is below the track. With a looped track there would be more complicated criteria for deciding if the ball has collided with the track, such as checking if it is inside or outside the track. So if you are looking for a programming project, grab the source code and go to work! Warning: it won't be easy!