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

### Real 2D Object-to-Object Collision Response (Advanced)

I put this section off a bit and moved it down here because I wanted you to really get a handle on momentum and collision and the mathematics needed to work with both. But like Dr. Brown said in Back to the Future, “Roads? Where we’re going, we don’t need roads…” Alas, object-to-object collisions with a fairly realistic collision response aren’t the easiest thing in the world to figure out. The final results aren’t bad, but coming up with them is no picnic. Anyway, let’s get started.

Figure 13.33 depicts the general problem that we want to solve. There are two objects modeled by 2D circles or 3D spheres, and each has a mass and an initial trajectory. When they make contact we want to compute the final trajectory or velocity after the collision. We’ve touched on this already in the section “The Physics of Linear Momentum: Conservation and Transfer” when we came up with the following equations:

Figure 13.33 The central impact of two masses problem.

Conservation of linear momentum:

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

Conservation of kinetic energy:

After combining them and solving for the final velocities, we get

    vaf = (2*mb*vbi + vai*(ma – mb))/(ma + mb)

    vbf = (2*ma*vai - vbi*(ma – mb))/(ma + mb)

These equations are true for perfectly elastic collisions. However, there’s a little problem—as they stand they are only 1-dimensional. What we need to do is come up with the 2D solution to the problem (something like a pool table) and this is a bit more complex. Let’s start with what we know.

We know that each ball (2D representation) has some mass m; furthermore, the balls are made of the same material throughout, so the center of mass is at the center of the ball body. Next, we know that when real balls hit each other, the balls deform for a moment, some of the kinetic energy is converted to heat, and mechanical work to deform the balls, then the balls separate. This is called the impact event, which is shown in Figure 13.34.

Figure 13.34 The phases of the impact event.

The impact event consists of two separate phases. The first phase: Deformation, occurs when the balls make first contact and the balls move at the same velocity. At the end of the deformation phase the restoration phase begins and continues until the balls separate. The bottom line is that during the collision event a lot of really complex physics happen that we can’t possibly model with a computer, so we have to make some assumptions about the collision. The cool thing is that even with the assumptions, when you see the simulation it will look pretty real! The assumptions are the following:

  1. The time it takes for the collision event is very small; call it dt.
  2. During the collision the positions of the balls do not change.
  3. The velocity of the balls may change significantly.
  4. There are no frictional forces acting during the collision.

Assumption 3 is the only one I need to clarify since I think the others are easy to swallow. For assumption 3 to be true, a force has to be applied during the collision that is almost instantaneous. This type of force is called an impulse force. This is the key to solving the problem. When the balls hit there will be a very large, short timed force that is created—an impulse. We can compute the impulses and from them come up with another equation to help solve the problem in 2D. The math is advanced and calculus based, so I will forgo it. The results are the generation of a coefficient that models all the physics during the impact event:

Equation 1: Coefficient of restitution

Equation 1 is referred to by e and called the coefficient of restitution. It models the velocity before and after the collision and the loss of kinetic energy. If you set e=1 then the model is a perfectly elastic collision. On the other hand, e < 1 models a less than perfect collision and the velocity of each ball after the collision and the linear momentum will be less. Now where do you get e? e is something you set or look up. The interesting thing is that if you combine the equation for e along with the conservation of momentum equation:

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

you get the following results:

Equation 2: Final Velocities

    vaf = ((e+1)*mb*vbi + vai*(ma – e*mb))/(ma + mb)

    vbf = ((e+1)*ma*vai - vbi*(ma – e*mb))/(ma + mb)

Math My notion is simple; (a,b) refers to the ball, (i,f) refers to initial or final, and (n,t) refers to the component along the n or t axes.

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.