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.

Click to select a different track:

hump shaped track

loop track

circle track

infinity track

oval track

spiral track







คลิกเข้าไปทดลอง  คลิกค่ะ

ทดลองไม่ได้ให้ Download  มา setup ที่เครื่องของท่านก่อนครับ Download จากฟิสิกส์ราชมงคล

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 0, 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 = 12 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

roller coaster variables

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.

Let k 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


F = m a = m g cos θ


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


where b is a constant determining the amount of damping. We can find cos θ by using the formula for the angle between two vectors A, B

cos θ =  


|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

a =  

g k

  − bm 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.

Numerical Simulation

The two equations needed for the Runge-Kutta numerical solver are given by: p' = v

v' =  

g k(p)

  − bm 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 = −gbm 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 pk 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 from 0 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
where t varies from 0 to . In two dimensions, the length of a curve can be determined by the path integral p = \int \sqrt{\left( \frac{dx}{dt} \right)^2 + \left( \frac{dy}{dt} \right)^2} dt 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 − 76 t 2 + 16 t 4
But this leads to the following nasty integral which even Mathematica cannot solve. p = \int \frac{1}{3} \sqrt{9 + 49 t^2 - 28 t^4 + 4 t^6} \; dt 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 x(t), y(t) 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 pk. 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] where P represents the list of p values in the table. Then an approximate value for the slope is given by

k =  

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.


MyPhysicsLab – Physics Simulation with Java

     Click on one of the physics simulations below... you'll see them animating in real time, and be able to interact with them by dragging objects or changing parameters like gravity. Get Java software if you don't already have it.
single spring
single spring
double spring
double spring
chaotic pendulum
chaotic pendulum
double pendulum
double pendulum
2D spring
2D spring
double 2D spring
double 2D spring
colliding blocks
colliding blocks
cart with pendulum
cart with pendulum
dangling stick
dangling stick
rigid body collisions
rigid body
sumo wrestling simulation
sumo wrestling
roller coaster
roller coaster

roller coaster with spring
roller coaster
with spring
roller coaster with 2 balls
roller coaster
with 2 balls
roller coaster with flight
roller coaster
with flight
molecule 2
molecule 2
molecule 3
molecule 3
molecule 4
molecule 4
molecule 5
molecule 5
molecule 6
molecule 6


ศัพท์วิทยาศาสตร์ ฉบับราชบัณฑิตสถาน

A  B  D  F  G  H  I  J  K  L  M  N  O  Q  R  S  T  U  V  W  X  Y 

                        ถ                                       อ   

นักวิทยาศาสตร    หน่วย      ศัพท์แผ่นดินไหวตัวอักษรจาก A-M   จาก N-Z

  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


หมวด :

| | | | | | | | | | | | | | | | | | | | | | | |

    ศัพท์เคมี    ศัพท์คณิตศาสตร์   ศัพท์ฟิสิกส์   

       บทความวิทยาศาสตร์      ศัพท์ชีววิทยา      สื่อการสอนฟิสิกส์      ศัพท์วิทยาศาสตร์    

พจนานุกรมเสียง 1   แมว    วัว 1    วัว 2    วัว 3    เหมียว   แกะ     พจนานุกรมภาพการ์ตูน

พจนานุกรมภาพเคลื่อนไหว   ดนตรี  Bullets แบบ JEWEL  พจนานุกรมภาพต่างๆ  ภาพเคลื่อนไหวของสัตว์ต่างๆ  โลกและอวกาศ




ฟิสิกส์ 1(ภาคกลศาสตร์) 

 ฟิสิกส์ 1 (ความร้อน)

ฟิสิกส์ 2 



เอกสารคำสอนฟิสิกส์ 1

ฟิสิกส์  2 (บรรยาย)

แก้ปัญหาฟิสิกส์ด้วยภาษา c  







เอกสารการสอน PDF




ตารางธาตุ(ไทย1)   2  (Eng)











 อะไรเอ่ย ?
















  การเรียนการสอนฟิสิกส์ 1  ผ่านทางอินเตอร์เน็ต

1. การวัด

2. เวกเตอร์

3.  การเคลื่อนที่แบบหนึ่งมิติ

4.  การเคลื่อนที่บนระนาบ

5.  กฎการเคลื่อนที่ของนิวตัน

6. การประยุกต์กฎการเคลื่อนที่ของนิวตัน

7.  งานและพลังงาน 

8.  การดลและโมเมนตัม

9.  การหมุน  

10.  สมดุลของวัตถุแข็งเกร็ง

11. การเคลื่อนที่แบบคาบ

12. ความยืดหยุ่น

13. กลศาสตร์ของไหล  

14. ปริมาณความร้อน และ กลไกการถ่ายโอนความร้อน

15. กฎข้อที่หนึ่งและสองของเทอร์โมไดนามิก 

16. คุณสมบัติเชิงโมเลกุลของสสาร

17.  คลื่น

18.การสั่น และคลื่นเสียง

   การเรียนการสอนฟิสิกส์ 2  ผ่านทางอินเตอร์เน็ต  

1. ไฟฟ้าสถิต

2.  สนามไฟฟ้า

3. ความกว้างของสายฟ้า 

4.  ตัวเก็บประจุและการต่อตัวต้านทาน 

5. ศักย์ไฟฟ้า

6. กระแสไฟฟ้า 

7. สนามแม่เหล็ก


9. ไฟฟ้ากระแสสลับ 

10. ทรานซิสเตอร์ 

11. สนามแม่เหล็กไฟฟ้าและเสาอากาศ 

12. แสงและการมองเห็น

13. ทฤษฎีสัมพัทธภาพ

14. กลศาสตร์ควอนตัม

15. โครงสร้างของอะตอม

16. นิวเคลียร์ 

   การเรียนการสอนฟิสิกส์ทั่วไป  ผ่านทางอินเตอร์เน็ต

1. จลศาสตร์ ( kinematic)

   2. จลพลศาสตร์ (kinetics) 

3. งานและโมเมนตัม

4. ซิมเปิลฮาร์โมนิก คลื่น และเสียง

5.  ของไหลกับความร้อน


7. แม่เหล็กไฟฟ้า 

8.    คลื่นแม่เหล็กไฟฟ้ากับแสง

9.  ทฤษฎีสัมพัทธภาพ อะตอม และนิวเคลียร์