The Problem

Model a bouncy ball, under the influence of gravity, which can bounce off of horizontal or vertical walls. Oh, and it experiences air drag.

Newton’s 2nd Law

Newton’s 2nd Law of Motion basically is physics. It describes how forces interact with macroscopic objects. If you’ve ever seen a ball fly through the air, or a car moving, or something rolling down a hill, or if you’ve ever felt anything, you know (indirectly) about Newton’s 2nd Law.


Newton’s 2nd Law looks like this: F = ma.

Well, not quite. It looks more like this: Fnet = ma.

As you can imagine, physics has a manner of starting simple and then getting very complicated very quickly. The subscript “net” means that the “F” doesn’t just refer to a single force, but the sum total of all forces on the object. The bold “F” and “a” mean that those variables (force and acceleration) are vectors — meaning that they exist separately in 3 different directions (X, Y, and Z).

But that’s not too bad. If you don’t want to do vector math, you can simply rewrite Fnet = ma as the following three separate equations:

You may think that having three equations to worry about makes things tougher, but trust me, it doesn’t. Just remember that you have to do the F = ma equation for each direction. We’ll very rarely use the Z direction, so all we really have to worry about stuff happening in the X and Y directions (left/right, and up/down).

Let’s just jump into a simple example. You have a ball with a mass of 2 kg, and there are three forces acting on it:

We combine the left and right forces to get our overall Fx, net = -2 N. (4 to the left and 2 to the right leaves us with 2 left over pulling to the left. The number is negative because in general, we’ll consider “right” to be positive and “left” to be negative.)

And since there’s only one force acting in the Y direction, the Fy, net is just -1 N. (Let’s say “up” is positive and “down” is negative — but only for now. We’ll switch that up later. In general, you use positive and negative signs in a way that makes sense for your specific problem.)

Finally, since our ball weighs 2 kg, we can substitute our numbers into F = ma and get the following two equations:

So far, so good. Truth be told, we’re really interested in the accelerations here, so we’ll just rearrange:

And then I’ll tell you that when you divide “Newtons” by “kilograms” you get “meters per second-squared”:

So we had a situation where we know the mass of an object and the forces acting on it. We added up the forces (assigning negative signs to “left” and “down”, causing those forces to subtract instead), and rearranged to solve for acceleration — and we did this for both the X and the Y directions separately. In this example, the ball is accelerating down and to the left, but it’s accelerating more to the left than it is downwards.

(More advanced: sometimes you don’t know the X and Y components of a force. It’s possible that you only know about one force that’s angled at, say, 30 degrees up from right. In that case, you can use cosine and sine to figure out the X and Y pieces of that force respectively. We’ll do that in a future article.)

Gravity

Gravity is one of the universal fundamental interactions, along with the electromagnetic, strong, and weak forces. Gravity causes a force to act on every single object from every other single object, but fortunately everything works out to simplify nicely if you’re on the surface of a planet. On Earth, for instance, we don’t even need to worry about the force that gravity causes, we can just look at the end result: every single object on Earth experiences an additional downward acceleration of 9.8 m / s2. That simple.

If our ball from above (that we already solved for) is on Earth and experiencing gravity, then we just need to modify the ay equation slightly. We’ll take the downward acceleration that the force is causing and combine it with the downward acceleration that gravity causes:

ay = -0.5 m / s2 – 9.8 m / s2

That leaves us with an acceleration of

ay = -10.3 m / s2

As you can see, the downward force combined with the acceleration from gravity shoots the ball downward even faster than either gravity or the force alone could.

So, gravity is simple (if you’re on a planet). All you do is modify the ay acceleration to factor in the downward pull of gravity.

In a future article we’ll look at how to model gravity if you’re not on a planet (perhaps you are a planet), but that doesn’t come until later…

Aerodynamic Drag

Our ball experiences gravity, but as I mentioned, we don’t need to model that as a force; we just plug it directly into the acceleration result. Drag, however, is a force, and we’ll have to model it.

The equation (one of the equations) for aerodynamic drag looks like this:

FD = -0.5 * CD * A * ρ * v2

It looks complicated, but when we break it down, it’s pretty simple. First off, notice the bold characters. Like F = ma above, a bold variable means it’s actually a vector — so right off the bat we can split this into two equations:

And then we look at each one of those terms above:

A Touch of Calculus

Calculus, like physics, is amazing and has a wonderful depth that I can’t do justice in a blog post.

The “derivative” in calculus describes how something changes as something else is changing; often this will be called the “rate of change”. When you drive a car at 30 MPH, your position is changing by 30 miles every hour. Your position changes as time changes. It can then be said that velocity is the “derivative of position with respect to time” or simply the “time derivative of position”.

Then we can think about what happens when you speed up or slow down (accelerate). You might change your velocity by 5 MPH per hour (MPHPH?). In that sense, your velocity is changing with time, and you can say that acceleration is the time derivative of velocity.

So it starts with position. The derivative of position is velocity. And the derivative of velocity is acceleration. (The derivative of acceleration is called “jerk”, and the derivative of jerk is called “jounce”.)

Why is this relevant? Because if you know the acceleration of something (5 meters per second per second), and if you know how fast it’s going when you start looking at it (let’s say it’s not moving at all), you can figure out where it will be at every moment in the future.

An example: your ball is accelerating at 2 m / s2 (meters per second per second). Let’s say it’s not moving at all when you start looking at it, and that the starting point is called x = 0;

Time Accel Velocity Position
0 s 2 m / s2 0 m / s 0 m
1 s 2 m / s2 2 m / s 0 m
2 s 2 m / s2 4 m / s 2 m
3 s 2 m / s2 6 m / s 6 m
4 s 2 m / s2 8 m / s 12 m
5 s 2 m / s2 10 m / s 20 m
6 s 2 m / s2 12 m / s 30 m

And so on. This is the approach we’ll use when solving for the motion of our ball, except we’ll do it not once per second but 40 times per second. All we’re doing is using our knowledge of the forces to figure out the acceleration at every frame. Then we use the acceleration and current velocity to figure out the new velocity. And then we use the velocity and last position to find the current position.