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.

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 = v^{2}/r (eqn 1)

This is the acceleration,

Suppose the ball is moving with velocity ^{2}/r

To apply this to a general curve other than a circle, we need the notion of
radius of curvature at a point

φ = arctan(dy/dx)

where

κ = dφ/ds (eqn 2)

where

r = 1/κ

We can estimate this using the table representing the curve. For a given point

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

The radius of curvature *normal to the curve* is greater than ^{2}/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

F_{gravity} = m g sin(θ)

F_{spring} = sin(θ) c (√(s_{x}^{2} + s_{y}^{2}) - R)

(Please see those pages for the definition of these symbols.) Since we already know

sin(θ) = √(1 - cos^{2}(θ))

Now we can find the acceleration normal to the curve from

F_{gravity} + F_{spring} = 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 ^{2}/r^{2}/r

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:

p = position on the track (measured by path length along the track)v = velocity

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:

u horizontal position_{x}=u vertical position_{y}=v horizontal velocity_{x}=v vertical velocity_{y}=

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

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:

t time of last simulation calculation before collision_{0}=t current time (after collision)_{1}=t time of collision_{c}=

So we have that _{0} < t_{c} < t_{1}_{c}*constant velocity* over the time interval _{0}, t_{1})*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 horizontal position at time_{0}=t _{0}x horizontal position at time_{1}=t _{1}x horizontal position at time of collision_{c}=v horizontal velocity at time_{0}=t _{0}v horizontal velocity at time_{1}=t _{1}

To find _{c}

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 t^{2} + v_{0} t + x_{0} (eqn 3)

a = (v_{1} - v_{0})/(t_{1} - t_{0})

Here we are taking _{0}_{c}

x_{c} = v_{0} t_{c} + x_{0}

t_{c} = (x_{c} - x_{0})/v_{0}

If

(v |

We can use the standard solution to the quadratic equation to find _{c}

The next step is to re-run the simulation starting from time _{0}_{c}

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

A = (vx, vy) is the velocity vector of the ballB = (1,k) is the vector tangent to the curve where slope= k C = the component ofA in theB directionN = the component ofA normal toB R = the reflected velocity vector

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

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 *stickiness* parameter and looks like this:

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

If the normal velocity

Now that the collision has been handled, we run the simulation from time _{c}_{1}_{1}

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.

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!