Instructions: drag the ball, or try changing control values (gravity, damping, etc.)
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 = v2/r (eqn 1)
This is the acceleration,
Suppose the ball is moving with velocity
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
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
Fgravity = m g sin(θ)
Fspring = sin(θ) c (√(sx2 + sy2) - R)
(Please see those pages for the definition of these symbols.) Since we already know
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
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
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
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
To find
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
xc = v0 tc + x0
tc = (xc - x0)/v0
If
(v1 - v0) xc = —————————— tc2 + v0 tc + x0 2(t1 - t0) |
We can use the standard solution to the quadratic equation to find
The next step is to re-run the simulation starting from time
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
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
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
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!