Newton's Three Laws of MotionA 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 LawAt 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 LawNewton'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.
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:
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.
Newton's Third LawYou 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. |