Ball Physics

Read time: 10 minutes (2664 words)

Reference:https://en.wikipedia.org/wiki/Newton%27s_laws_of_motion

We will be working on a pool ball simulation in class, so we need to understand a few things about how a pool ball moves. We also need to understand what happens when we put a lot of moving balls on a table. You already have an idea what happens, but we need to figure out the math needed to calculate exactly what happens.

Stand by, this is interesting. (Even if you hate math!)

Newton’s Laws

We start off by lookig at three laws from Physics, created by Isaac Newton back in 1687 [newton:1687]

  1. Inertia: Every object in a state of uniform motion tends to remain in that state of motion unless an external force is applied to it.

    \sum {\vec F} = 0 \iff \frac{d{\vec V}}{dt} = 0

  2. The change of momentum of a body is proportional to the impulse impressed on the body, and happens along the straight line on which that impulse is impressed.

  3. To every action there is always opposed an equal reaction: or the mutual actions of two bodies upon each other are always equal, and directed to contrary parts.

The wording back then was a little, well, dated! (Or, is it us?)

Basically, these three laws tell us how a pool ball will move along on a table with walls all around (we will ignore pockets).

Moving a Ball

We will place a ball on the screen at some point, and begin a simulation loop that models the passing of time. Each pass through the loop represents one unit of time. During that time, the ball will move to a new position. If we draw the ball at the starting point, then erase it and redraw it at a new point after that period of time, it will look like the ball moved.

All we need to do is track the current position of the ball, and the velocities of that ball in the X direction (left to right) and in the Y direction (up and down). The “speed” of the ball is the vector sum of these two velocities.

Phew, physics!

If we make the speed of the ball in each direction the number of pixels the ball moves each pass through our loop, all we need to do to calculate a new position is add the speed in the X direction to the X``position of the ball, and do the same for the ``Y position:

Xball = Xball + DX;
Yball = Yball + DY;

Here, I am using DX to indicate the speed of the ball in the positive X diection (to the right), and DY to represent the speed of the ball in the positive Y` direction (up).

Obviously, big numbers for DX and DY will make the ball appear to move faster!

Once we set a ball in motion somehow, it will continue moving in that direction until something interferes witht hat motion. If all we are dealing with is a single ball moving on the bable, we will eventurlly run into a wall. Exactly what happens then is our first challenge.

You know what will happen, but how to we model that action in a simple simulation?