• Create BookmarkCreate Bookmark
• Create Note or TagCreate Note or Tag
• PrintPrint

### Newton's Three Laws of Motion

A chapter about physics would not be complete without discussing Newton's three laws of motion. Sir Isaac Newton (1642–1727), a brilliant physicist and the father of calculus, developed—among other things—three fundamental laws of motion. Only one of these laws, the second, will we actually apply with ActionScript. However, we will discuss all three, since knowledge of these “basic” facts may help you to solve some programming problems within your games.

#### Newton's First Law

At some point in your life you may have heard something to the effect of “A body at rest tends to stay at rest; a body in motion tends to stay in motion.” While this is not a complete description, it is the gist of Newton's first law of motion. This law is best understood with the concept of systems. A system is anything—any entity, whether it contains one or one million objects—you wish to study. For instance, a baseball can be a system. A roomful of people can be a system (as can the room itself, if that's what you're studying). Even an entire planet can be a system.

The astronaut cannot move himself.

For the sake of understanding this law, let's take the example of an astronaut floating with no velocity in space. No matter what he does, he cannot move his center of gravity (a point by which you can measure his real position). He can kick his legs and wave his arms, but his velocity is not going to change. There is only one possible way he could move from that position: He'd need to have another system apply a force to him, such as gravity from a planet. With this example in mind, let's take a look at Newton's first law:

The velocity of a system will not change unless it experiences a net external force.

This law does not directly apply to your Flash applications. However, understanding it can help you if you find yourself struggling through conceptual programming problems.

#### Newton's Second Law

Newton's first law assumes a system that will not change its velocity unless a net external force is applied to it. That begs the question, what is the acceleration (change in velocity) when a net external force is applied? Newton's second law answers this question.

The acceleration of an object is inversely proportional to its mass and proportional to the net external force applied.

Mathematically, this is written as follows:

```net force = mass*acceleration
```

or, as most people see it:

```F = m*a
```

where F is force, m is mass, and a is acceleration. The net force is the sum of all the force vectors.

This is an immensely handy equation. You can sum all of the forces acting on an object (the net force), and from that sum determine its acceleration. What does this mean for you, and when would you need it? It means that once you have found the acceleration of an object, you can use it with the equations of motion to move the object around on the screen.

 As an example, open balloon.fla from the Chapter04 directory on the CD. In this file, I've applied two forces to a balloon of mass = 1—a gravitational force of 30 (its weight) and a buoyant force of -31 (the force that makes a helium balloon rise).

Notice that the buoyant force is a negative number. This indicates that the force is pointing in the –y direction (also known as “up”). The goal is to code this in such a way that the balloon moves in the correct direction. To move the balloon, we need to know its acceleration. To find its acceleration, we use Newton's second law. The simple process to find the acceleration is as follows:

 1 Sum all of the forces. In this case, netForce = force1 + force2. 2 Solve for the acceleration. Since netForce = mass*accel, then accel = netForce/mass.

Let's take a look at the ActionScript for the single movie clip in this file (in the Actions layer):

```							1   ymov = 0;
2   mass = 1;
3   //weight, the downward force
4   force1 = 30;
5   //bouyancy, the upward force
6   force2 = -31;
7   //total force
8   netForce = force1 + force2;
9   //Newton's second law applied to find the acceleration
10  yaccel = netForce/mass;
11  _root.onEnterFrame = function () {
12     ymov += yaccel;
13     balloon._y += ymov;
14  }
```

The first thing you'll notice is that all of the forces are only in the y direction. That means we only need to deal with movement in the y direction. In line 2, we set the mass variable. (I've just chosen an arbitrary value of 1.) We then define force1 and force2. In line 8, the forces are summed to arrive at a net force. We then apply Newton's second law in line 10. After the acceleration is found in line 10, everything else deals with moving the object and should be familiar from the section on “Speed, Velocity, and Acceleration.”

When you test the movie, you can see that since the buoyant force has a greater magnitude than the gravitational force, the balloon floats up.

I hope you can see the power of this law. With it, you can create a complicated situation with an unlimited number of forces acting on an unlimited number of objects. By summing the forces on an object, you can find its acceleration. Even if the situation is complex, the math remains simple—you just keep applying it to the parts until you have solved for all the variables.

## Terminal Velocity

In the rising-balloon example we've been using in this section, the balloon accelerates with no upper limit. This means that the balloon will rise faster and faster and will never reach a maximum velocity (except the speed of light, of course). In real life, we know that we are surrounded by atmosphere, and that the atmosphere must have a certain amount of effect on us. As a balloon rises, you know it's going to encounter wind resistance (from the atmosphere), which will oppose (or at least affect) its acceleration. There is no simple equation to calculate the force of the wind resistance, because it depends on several factors. What you should know, though, is that eventually the wind-resistance force will be so large that the sum of all of the forces on the balloon will be 0, and then there will be no further acceleration. At that point, the balloon is traveling upward at its maximum velocity. This is called terminal velocity. In games, such as some of those presented later in this book, it's good to set an upper limit to the speed of your objects so they can't move so fast that you can't keep up with them. This upper limit is, of course, subjective, and depends on the game, the object, and the frame rate.

We will add our own terminal velocities just by using simple if statements to see if the velocity is too great.

 How fast is too fast? An object is moving too fast when game play is no longer fun!

#### Newton's Third Law

You probably don't think much about physics as you move through your everyday activities, but those activities actually afford lots of examples and physics “problems” to ponder. Here's one: When you sit on a chair, you don't fall through it. Why not? Because while you are exerting a force on the chair (your weight), the chair is also exerting a force on you—in the opposite direction. You may have heard of Newton's third law:

For every action there is an equal and opposite reaction.

Action: You applying a force to a chair by sitting on it. Reaction: The chair exerts a force on you equal to that of your weight but opposite in direction.

If you're like most people, you are probably now trying to imagine a situation where this does not hold up. But you can't! Try this one on for size: If a baseball is falling toward the earth, the earth is applying a force (its weight) to the baseball. What you may not have realized is that the baseball is applying an equal but opposite force on the earth. The result is that the ball and the earth accelerate toward each other (yes, the ball does move the earth—however small the amount may be).

As with Newton's first law, there is no immediate application of this law in your physics programming. However, if you are trying to code something physical in Flash that is not discussed in this book, then figuring out the logic involved may be easier with the help of this law.

• Create BookmarkCreate Bookmark
• Create Note or TagCreate Note or Tag
• PrintPrint