Tricks of the Windows Game Programming Gurus:Playing God: Basic Physics Modeling

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

#### Forces in Higher Dimensions

Of course forces can act in all three dimensions, not just in a straight line. For example, take a look at Figure 13.9, which depicts 3 forces acting on a particle in a 2D plane. The resulting force that the particle p “feels” is simply the sum of the forces that are acting on it. However, in this case it’s not as simple as adding scalar numbers together since the forces are vectors. Nevertheless, vectors can be decomposed into their x, y, and z components and then the forces acting in each axis can be computed. The result is the sum of the forces acting on the particle.

Figure 13.9 Forces acting on a particle in 2D.

In the example shown in Figure 13.9 there are three forces; F1, F2, and F3. The final force Ffinal=<fx, fy> that object p feels is simply the sum of these forces:

    fx = f1x + f2x + f3x

    fy = f1y + f2y + f3y

Plugging in the values from the example in the figure, you get

    fx = (x+x+x) = x.x

    fy = (y+y+y) = y.y

With that in mind, it doesn’t take much to deduce that in general the final force F on an object is just the vector sum of forces, or mathematically:

    Ffinal = F1+F2+...+Fn

Where each force Fi can have 1, 2, or 3 components, that is, each vector can be a 1D (scalar), 2D, or 3D.

#### Momentum (P)

Momentum is one of those quantities that’s hard to define verbally. It’s basically the property that objects in motion have. Momentum was invented as a measure of both the velocity and mass of an object. Momentum is defined as the product of mass (m) and the velocity (v) of an object:

P = m*v

And the units of measure are kg*m/s, kilogram–meters per second. Now the cool thing about momentum is its relationship to force—watch this:

F = m*a

or substituting, p for m:

> Note: I was on an FZR600 one time, going about 155 mph, and a bee hit my visor. Not only did it crack the visor, but it felt like someone threw a baseball at me! Lesson to be learned—only speed in designated bee-free areas!

F = (p*a)/v

But, a = dv/dt, thus:

Or in English, force is the time rate change of momentum per unit time. Hmmm… interesting. That means if the momentum of an object changes a lot then so must the force acting on the object. Now here’s the clincher. A pea can have as much momentum as a train—how? A pea may have mass of 0.001 kg and a train have a mass of 1,000,000 kg. But if the train is going 1 m/s and the pea is going 100,000,000,000 m/s (that’s one fast pea) then the pea will have more momentum:

    mpea*vpea    = 0.001 kg * 10,000,000,000 m/s = 10,000,000 kg*m/s

    mtrain*vtrain = 1,000,000 kg * 1 m/s = 1,000,000 kg*m/s

And thus if either of these objects came to an abrupt stop, hit something for example, that object would feel a whole lot of force! That’s why a bee hitting you on a motorcycle is so dangerous. It’s not the mass of the bee, but the velocity of the bee that gets you in this example. The resulting momentum is huge and can literally throw a 200-pound guy off the bike.

This brings us to conservation of momentum and momentum transfer.

### The Physics of Linear Momentum: Conservation and Transfer

Now that you have an idea about what momentum is, let’s talk briefly about some of the physics involved when an object strikes another. Later I will go into true collision response in more depth, but for now let’s keep it simple.

Remember in the game DOOM when you shot a barrel, it would explode and cause the barrels and/or bad guys in the area to move and/or explode? Wasn’t that cool splattering a bad guy against a wall! That was just momentum transfer, but believe me, doing it correctly is no picnic!

In general, if two objects collide there are two things that can happen: a perfectly elastic collision and a not so perfectly elastic collision. In a perfectly elastic collision, as shown in Figure 13.10, a ball hits a wall with velocity vi, and when it bounces off it still has velocity vi.. Thus, the momentum was conserved. Therefore, the collision was totally elastic. However, in real life this isn’t usually the case. Most collisions aren’t elastic, they are less than perfect. When collisions that are less than perfectly elastic occur, some energy is converted into heat, work to deform the objects colliding, etc. Thus the resulting momentum of the object(s) after collision is less than when the collision started.

Figure 13.10 A perfectly elastic collision of a ball and wall.

However, I’m not interested in this kind of imperfect world. Since we are gods of the virtual world, we might as well make things easy. Hence, I’m going to talk about perfectly elastic collisions in 1-dimension right now, then later we’ll do it in 2D and get medieval with the math! Let’s begin.

Figure 13.11 has two block objects A, B with mass ma and mb and velocity vai and vbi, respectively. The question is what happens after they hit, assuming no friction (we’ll get to that later) and a perfectly elastic collision? Well, let’s start with the conservation of momentum. It states that the total momentum before the collision will be the same as after the collision. Or mathematically:

Figure 13.11 The collision response of two blocks in 1D.

Equation 1: Conservation of momentum

    ma*vai + mb*vbi = ma*vaf + mb*vbf

All right, you know ma, mb, vai, and vbi, but you want the final velocities vaf and vbf. The problem is that you only have one equation and two unknowns. This is obviously a bad thing. If you knew the velocity of one of the masses, you could figure the other one out. But, is there a way to figure out both velocities without any further knowledge? The answer is yes! You can use another property of physics to come up with another equation. The property is the conservation of kinetic energy.

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.