Chapter 12
Mechanics 2: Linear and Rotational Dynamics
The Force is what gives a Jedi his power.
It's an energy field created by all living things.
It surrounds us and penetrates us.
It binds the galaxy together.
— Obi-Wan Kenobi in
Star Wars Episode IV: A New Hope (1977)

Chapter 11 was about linear kinematics—how to describe the motion of object, without concerning ourselves with the “cause” of the motion, its orientation, or how we might go about simulating that object on a computer. The main goals of this chapter are to address those three topics.

12.1Newton's Three Laws

Sir Isaac Newton established three simple laws that provide a framework, commonly known as Newtonian mechanics, for understanding such diverse physical systems as an apple falling from a tree, the motion of the planets, and the physical interactions that happen in a video game. Newtonian mechanics is also called classical mechanics, and that name should alert you to the fact that the laws we are about to study are wrong, in the sense that they do not agree with the result of experiments conducted at very high speed (which require relativistic mechanics) or at very small scale (which require quantum mechanics).1 For everyday phenomena (and for the phenomena we need to simulate in a video game), the discrepancy between the results predicted by Newtonian mechanics and the correct results (as correctly predicted by quantum-relativistic mechanics) is generally less than can be detected with the most accurate instruments. The differences in the predictions become significant only at speeds very close to the speed of light and at scales approaching the size of an atom; otherwise, all the theories are in great agreement with each other and with experimental results. It was precisely because Newtonian mechanics has such a long and decorated history of accurate predictions that it was so shocking to find out that the laws were in need of correction. It should be clear that these laws, having been sufficient to describe the motions of the heavenly bodies to a great deal of accuracy, will also be quite sufficient for our purposes here.

12.1.1Newton's First Two Laws: Force and Mass

Chapter 11 noted that mass measures the degree to which an object resists being accelerated. This resistance is called inertia, and the physical quantity needed to overcome it and create an acceleration is called force. In other words, all of those “causes of motion” that we so scrupulously avoided mentioning in the previous chapter actually go by the collective name force.

The idea that objects resist acceleration is summarized by Newton's first law.

Newton's First Law
Every body persists in its state of being at rest or of moving uniformly straight forward, except insofar as it is compelled to change its state by force impressed.

This seems like quite a simple statement, even in the anachronistic translation of Newton's original Latin. But consider how audacious it was for Newton to assert this, when it so clearly is at odds with the commonsense observations we all have from our daily lives! A more “commonsense” way to think about force is to assume that force is needed not only to start an object in motion, but also to maintain its motion. (This is the rule under so-called Aristotelian dynamics.) After all, once we stop applying the force, eventually the object will stop moving, right? According to Newton, once an object is set in motion, it does not require any force to continue this motion. In fact, Newton claims that the force is required to stop the object, and absent this stopping force, the object will continue on indefinitely.

Of course, the reason Newton's first law seems counterintuitive is that in our everyday experience, when we set objects in motion, they are always brought to a stop by the ubiquitous force of friction. But we can argue that Newton's law is correct, even though objects always come to a stop through friction, with a simple thought experiment. Imagine we apply a certain amount of force and set an object in motion across a surface. The object will travel a certain distance and eventually come to a stop. Did it stop due the lack of continued pushing force, or due to some force that acted to slow it down? If we perform the same experiment on different surfaces, performing the initial push in the same manner in each case, we find that the object travels farther on a smoother surface, and less distance on a rougher surface. You probably aren't surprised at these ”commonsense” results, but notice how they actually contradict the notion that a force is required to keep the object in motion and validate Newton's laws.

Newton clarified the precise relationship among mass, acceleration, and net force in his second law.

Newton's Second Law
The acceleration of a body is proportional to (and in the same direction as) the net external force acting on the body, and inversely proportional to the mass of the body:
(12.1) f =m a .

This simple equation is the most important one in this chapter. You should certainly memorize it. It basically says that whenever a particle with mass m is seen accelerating at a rate a , you can be sure that there is a net force f acting on the particle. Likewise, whenever there is a net force, the object will accelerate, because net force and acceleration always go together. There are no exceptions to this rule. The acceleration of an object is always proportional to the net force acting on it at that moment.

Now this does not mean that when there are any forces on an object, it will necessarily accelerate. Nor does it mean that if an object is not accelerating, then there are no forces acting on it. The f in f =m a is the net force. Consider the tremendous forces exerted on the beams at the bottom of a skyscraper. Clearly there is a force that wants to accelerate the beam downward. However, since the beams do not in fact accelerate downward, we know by Newton's second law that this downward force must be exactly opposed by some other force acting in the opposite direction.

What sort of quantity is force? First of all, force has magnitude and direction, and so it is a vector quantity, just like acceleration (although at times it is easier to study force in a one-dimensional setting, just like we did with acceleration). And force must have the same dimensions (1D, 2D, or 3D, depending on the “world” in which we are working) as the acceleration a for Equation (12.1) to make sense, because m is a scalar quantity.

Let's use dimensional analysis to determine the physical units that we should use to measure force. Mass is one of our fundamental quantities, denoted M , and from the previous chapter we know that acceleration has units L / T2 . Therefore (dropping the bold to indicate vector quantities), force must have units

Dimensional analysis of force
f=ma=(M)(L / T2).

When measuring with the SI units—mass in kilograms, length in meters, and time in seconds—force has the units of “kilogram meter per second squared.” This is quite a mouthful, so it goes by a special name, the Newton, denoted N:

The Newton is an SI unit of force
1  N =1  kg m s 2.

If you're having trouble grasping just what a “kilogram meter per second squared” is, just remember that a Newton is the amount of force required to accelerate a mass of 1 kg at a rate of 1 m/ s 2 .

There's a common misunderstanding that we'd like to cut off as early as possible. Force creates an acceleration on a body, and it acts over time. For example, the question, “How much force does it take to get a 100 lb object to go 100 mi/hr?” does not make sense. Force doesn't produce velocity directly, it causes the velocity to change over time. This can be especially confusing when you consider collisions, such as a ball bouncing on the floor or being struck by a bat. Although the velocity appears to have changed instantaneously, what is really happening is that a very large force is acting for a very short (but finite) duration. We study collisions in more detail in Section 12.3. Typically in digital simulations impulsive forces are handled differently from more persistent forces that act over several simulation steps, so for now, don't think of a force as an impact; instead, think of it as more of a gradual push or pull that could be provided by, for example, a spring, the wind, or gravity.

We said that Equation (12.1) is the traditional way to express the relationship among force, mass, and acceleration. However, written in that way, with force on the left-hand side, you might get the idea that the common situation is for us to know the mass and acceleration, and use Newton's laws to compute the force. In fact, especially in digital simulations, the more common scenario is that we have calculated the forces acting on a body, and we wish to predict the body's response to those forces. In other words, we'll usually use Newton's second law in the form

We usually use this form of Newton's second law
(12.2) a = f / m.

Most physics textbooks teach the important conceptual tool known as a free-body diagram. Newton's second law, especially as expressed in Equation (12.2), is at the heart of this exercise. The basic procedure is as follows, starting with a representation of the object.

  1. Draw and label all the forces acting on it.
  2. Sum up those forces (using vector addition) to compute the net force.
  3. Use Newton's second law (Equation (12.2)) to compute the acceleration of the object.
  4. Integrate the acceleration to determine the motion of the object. When solving problems analytically, this means solving differential equations. We don't use any differential equations in this book because there are only a few simple cases that we will look at analytically. Numerical methods of integration must be used. Later, we examine Euler integration, which is the most simple method imaginable, but also the one used by most real-time rigid body simulators.

The above procedure is a very important tool that we use several times in Section 12.2; it's also essentially how most digital physics simulations work inside a computer. Of course, the simplicity with which we've described this 4-step process hides many troublesome difficulties. The forces in Equation (12.2) may vary continuously over time; be dependent on time, position, and velocity; exhibit nonlinearities or discontinuities; and in general be difficult to compute exactly or express and integrate in closed form. Section 12.6 deals with physics simulations, but for now the key point that we want to emphasize is that Newton's second law is the fundamental driving equation.

12.1.2Inertial Reference Frames

If we take the special case where f = 0 , then according to Newton's second law, a = 0 . This is a restatement of his first law. So we see that if Newton had been just a bit more clever, he could have said the same thing in only two laws instead of three. Of course, Newton not only broke through the barrier of “common sense” to create elegant formulas that explain the workings of every physical system in the entire universe, he also simultaneously invented a complete branch of the mathematics needed to fully explore these ideas—calculus. So perhaps he was a clever guy after all. We assume he had a good reason for keeping his first law; we interpret it as a statement about reference frames.

The vectors a and f are specified in some reference frame, and if we choose a bad reference frame, the equation does not hold. Reference frames in which the basic mechanical laws hold (especially f =m a ) are known as inertial reference frames. Coordinate spaces for which this law does not hold unless we invent fictional forces are called noninertial frames.

Figure 12.1 A robot in a falling elevator is in a non-inertial frame. He must invent a fictitious upward force to counteract gravity to explain why his herring sandwich doesn't fall.

For example, imagine a robot eating a herring sandwich in an elevator. Someone cuts the elevator cables, and the elevator, robot, and sandwich begin to fall. Now, this robot has been programmed with the knowledge that it likes to eat herring sandwiches,2 but without any general sense of self-preservation, so it does not panic. It looks at the herring sandwich floating in mid-air instead of falling to the elevator floor, as it would reasonably expect. The robot, having also been programmed with an incomplete understanding of Newton's laws, thinks to itself, “My goodness, this is quite unusual! I know gravity must be pulling this sandwich downwards and I know f =m a , and since the sandwich is not accelerating downwards, the net force acting on it must be zero. Therefore, there must be some upward force acting on this sandwich. Quite fascinating! What might be the source of this force? Now, if I calculate…” CRASH!

Figure 12.2 An alien watching the elevator fall as Earth moves past will not see anything to contradict Newton's three laws, assuming the time period is short enough so that Earth's rotation and curved path are not significant factors.

A viewer on the ground would not see any need to invent a fictitious force to explain the sandwich's behavior. Using a reference frame with the origin fixed at the bottom of the building, the viewer sees the sandwich as accelerating downward, and has no reason to think anything is amiss.3 The person driving by in a car also doesn't see any problems. In the reference frame of the car, the sandwich appears to travel in a parabolic motion. But the relation f =m a seems to hold, and so the driver observes that Newton's laws are valid in her reference frame. Likewise for the advanced alien civilization watching from their cloaked spaceship as Earth whizzes past (see Figure 12.2). From their4 perspective, everything seems to be obeying Newton's laws. To the alien, Earth is moving with a constant linear velocity and the elevator's trajectory is parabolic, just as we would predict using the projectile equations developed in Section 11.6. (Actually, we are ignoring some finer points, such as Earth's rotation, the curved path it takes as it orbits the sun, and the do-si-do it does with the moon. These deviations from constant linear velocity are the exceptions that prove the rule: they are the reason why a reference frame fixed to Earth's surface is not quite an inertial frame. Experiments such as Foucault's pendulum can detect the difference, even though it is slight.)

In summary, if a reference frame is accelerating or rotating, the motion of objects described using that reference frame will not be consistent with mechanical laws. An inertial reference frame must be stationary or moving at a constant linear velocity.

12.1.3Newton's Third Law

Newton's third law is often misunderstood in spite of being the one most often quoted. It has a certain zen-like justice to it.5

Newton's Third Law
To every action there is always an equal and opposite reaction. Or, the forces of two bodies on each other are always equal and are directed in opposite directions.

This law basically says that there is no such thing as a single unilateral force. If object A pushes or pulls on object B , then object B always pushes or pulls back on object A with a force of the same magnitude but opposite direction. If gravity is pulling me towards Earth, it's also pulling Earth towards me! A force is always part of an interaction between two bodies.

In diagrams, we often draw a force as an arrow, since it is a vector. But really, these diagrams would be more accurate if both ends of the arrow had arrowheads. When we leave off the other side of the arrow, it's because it is acting on an object in which we have no interest. When you see a single-sided arrow that represents a force in a diagram, you can always fill in the other half in your mind.

One source of misunderstanding of Newton's third law is the word “reaction.” The purpose of this word is to describe the forces as being in opposition to one another. It is not meant to imply a causal link between them; neither force is a “cause” or “effect.” The two opposing forces act simultaneously and, so far as the laws of physics are concerned, have equal status.

But aside from this mistaken inference of cause and effect, the third law is just plain counterintuitive. Let's say a guy named Moe pushes a box forward on the ground. The box weighs twice as much as Moe, and he has placed it on a cart that rolls with very little friction. According to Newton's third law, the box pushes back on Moe. But then why does the box accelerate and Moe doesn't? It doesn't look like there are “equal and opposite actions” happening here.

Conundrums such as these are always resolved by considering all the forces acting on both bodies. In the example just discussed, Moe is not floating in midair, or else he would have been accelerated backwards just as Newton's third law predicts he would. (Consider what would happen if Moe and the box were on ice.) No, Moe is standing on the ground. Through the force of friction, Moe pushes against the Earth and the Earth pushes back on Moe. In fact, if we assume that Moe makes some forward progress instead of just being stuck there grunting, then the force of the Earth pushing against him must exceed the force of the box pushing back against him, and he accelerates forward. This is illustrated in Figure 12.3.

Figure 12.3The four forces involved in Moe pushing the box

An inquisitive reader might wonder about the previous scenario, “Why doesn't the Earth then accelerate?” The short answer is, “It does!” A medium-length answer is, “It does, in the short run.” For the full length answer, we have to wait until Section 12.3, which tells us a little bit about momentum.

Of course, these theoretical questions are certainly interesting to ponder, but what practical application is there for Newton's third law? The most important application, for our purposes, is the justification to simplify a rigid body and treat it as a single particle. For example, earlier we considered the forces acting on a large beam in a skyscraper. What if the beam is not a single solid piece, but instead it is really two beams that have been bolted together? Then really what is happening is that forces push down on the top part of the beam, which pushes down on the bottom part of the beam, which pushes down on the Earth. Likewise, the Earth is pushing back up on the bottom part of the beam, which pushes up on the top part of the beam.

But why stop there? Isn't any object actually composed of not just two or three pieces, but trillions of molecules? How can we possibly calculate all these complicated quantum-electrical forces? This is where Newton's third law comes in. We are justified in the treatment of this spliced beam as a single rigid body, and we can ignore all the internal forces, provided that the body stays rigid, which means that all pairs of points within the object maintain a fixed distance from each other. In this situation, the parts are not accelerating relative to each other, and this means that the internal forces must be exactly balanced. In other words, all the internal forces cancel each other out and thus make no contribution to the net force, which is why we can ignore them. Of course, to the extent that the pieces do accelerate relative to each other, any calculations we make ignoring the internal forces will be inaccurate. If the bending or compression of the object is very slight, then our calculations will not be perfect, but they will be very close; if the object breaks apart, then our calculations will be meaningless.

We can generalize arguments such as this even further to the case where the parts are moving relative to each other. Of course, an object with moving internal parts is the opposite of a rigid body; however, we'll see that in many respects we are still able treat these complicated systems as “particles.” Section 12.3 discusses this idea and how it allows us to resolve the conundrum of Moe and his box.

12.2Some Simple Force Laws

Many different types of forces are at work in our universe.6 In a real-time simulation, we often ignore certain forces, make approximations to them, and even invent fictional7 forces to achieve a desired effect (such as forcing a trajectory to obey an animator's constraints, or helping the AI or the player hit the target). Although our guiding principle is always f =m a , the methods used to define f can vary greatly.

This section discusses three important forces that exist in the real world and are often used in physics simulations. Gravity, friction, and springs are the subjects of Section 12.2.1, Section 12.2.2, and Section 12.2.3, respectively. Of course, a computer simulation may need to consider many more real-world forces, such as buoyancy, drag, or lift. The goal of this book is to give an overview of the most important topics and not to be exhaustive; however, sources that cover these types of forces are listed in the suggested reading in Section 12.7.

One other extremely important force that appears in physics simulations is the contact force, also known as a normal force. This is the force that prevents objects from penetrating each other. When a box is resting on a table, the force the table exerts on the box, counteracting the force of gravity and preventing the box from accelerating downwards, is called a contact force. Contact forces in a physics engine are inherently tied up with the engine's method for resolving collisions and are usually handled in a way that forms a compromise between the stability of the simulation and physical reality. As such, the details for how contact forces are computed can vary from one physics engine to another; indeed, resolving collisions is a very active area of research.

12.2.1Gravitational Force

In Principia, Newton stated all sorts of laws in addition to the three for which he is the most famous. One such law, which he discovered through analysis of the motions of the planets, is the law of universal gravitation, which states that all objects in the universe feel an attractive force to each other. This force is proportionate to the product of their masses and inversely proportionate to the square of the distance between the objects and can be calculated by Equation (12.3).

Law of Universal Gravitation
(12.3)f=G m1m2 d2.

In this equation, f is the magnitude of the force, m1 and m2 are the masses of the two objects, and d is the distance between their centers of mass. (We'll have more to say about exactly what the center of mass is in Section 12.3.2.) G is a physical constant of the universe, approximately equal to 6.673×10 11   N   m 2  kg 2 .

The law of universal gravitational attraction is very helpful if you want to understand planetary motion or the tides, or just need a cheesy pick-up line.8 However, most simulations are confined to a fairly small region close to Earth's surface. When we make the typical assumption that one Cartesian axis points “down,” we are ignoring the curvature of Earth and also locking in the direction of the force of gravity to a constant. It's also common to ignore the slight decrease in the strength of gravity that occurs at higher altitudes, and assume a constant value for d . Thus, if we let m1 stand for Earth's mass, then the only variable in Equation (12.3) is m2 , the mass of the object being simulated. In most video games, the force of gravity is computed using Equation (12.4).

Video Game Gravity
(12.4) f =m g .

In Equation (12.4), m is the mass of the object and g is a constant vector pointing in the downward direction. Notice that the force of gravity is proportional to the mass, but Newton's second law says that the acceleration due to any force is inversely proportional to mass. Therefore, g specifies the acceleration due to gravity for all objects in free fall. (Notice the similarity between Equation (12.4) and Newton's second law, f =m a .)

Chapter 11 told you what the magnitude of g is in the real world, but let's see if we can derive it from the universal law of gravitation. Earth's mass is approximately m1=5.98×10 24   kg , and its mean radius is 6,371 km:

Calculating the force of gravity near Earth's surface from the law of universal gravitation
f=G m1m2 d2= (6.673×10 11 N   m 2 kg 2 ) (5.98×10 24   kg )m2 (6.371×106  m )2 (9.83  N )m2 kg (9.83  m s 2) m2.

But wait, this value is larger than the value of 9.81 quoted earlier! The reason for the difference is that, while Earth's gravity provides a centripetal force, its rotation creates an apparent centrifugal force, which partly counteracts gravity. We calculated the magnitude of the acceleration required to keep objects from spinning out into space in Section 11.8. At the equator, Earth's rotation requires that gravity provide a centripetal acceleration of 0.03369  m   s 2 . Thus a small part of the force of gravity that makes objects feel heavy is being counteracted by the spinning of Earth, which makes them feel lighter.

Subtracting this apparent centrifugal force from the force of gravity gives us 9.830.033699.796 , but now the value is too small, not the 9.81 we were looking for. The reason is that gravity exhibits variations in magnitude over Earth's surface. The biggest source of this variation is the centripetal acceleration we have just calculated; it varies with latitude. We computed its magnitude assuming r was Earth's radius; the resulting value for gravity of 9.796 is actually the correct strength of gravity at the equator. As the latitude increases and we move towards the poles, the radius r of the circular path (which has constant latitude) decreases. At the poles, the radius shrinks to zero, and objects rotate but do not move in a circular path. Thus there is no apparent centrifugal force at the poles, and the force of gravity is equal to the 9.83 value we computed above. The value 9.81 is known as the “standard value,” and is the average force of gravity at sea level at a latitude of about 45°.

Now that we've discussed at some length the strength of gravity in the real world, let's talk about how this number is often completely irrelevant in video games. In certain genres, such as racing or flight simulators, realism is important. However, in most other video games, the first law of video game physics applies. (Hey, Newton made up some laws, so why can't we?)

First Law of Video Game Physics
Reality is overrated.

For example, first-person shooters are notorious for poor jumping mechanics. The most important reason is probably the fundamental fact that you cannot see your feet, yet some first-person games have for some reason added jumping puzzles. But even many third-person shooters that adopt an over-the-shoulder camera also have jumping mechanics that just don't feel right. Why? In most first-person shooters, when you jump, you are given an initial burst of upward velocity, and then your position is simulated just like every other airborne object in the world, using gravity, which causes your motion to be parabolic. Compare this to the jump mechanic in most third-person action games. Most of these games do not simulate jumps using a constant acceleration. Instead, your character will spring up almost instantaneously after you hit the button, and reach a maximum height very quickly. In many games, the character will hover at that maximum height for a duration, and then slam back down on the ground as quickly as it rose up, perhaps leaving a crater behind. This is clearly not physically accurate, but then again, neither is being able to jump two or three times your own height, steer in midair, or double jump. When it comes to jumping in video games, reality is not just overrated, it's completely ignored. It just doesn't feel right.

If simulating a jump mechanic using gravity makes for a bad jump mechanic, simulating a jump mechanic using a value of 9.8  m / s 2 is even worse. The basic problem is that most players expect a jump to take a certain amount of time but also expect to be capable of jumping to unrealistic heights. When real-world gravity is used to attain these heights, the player is in the air too long, and it feels “floaty.” Many arcade racing games also increase gravity to get the car back on the ground more quickly. Whether it be racing games or character games, the player wants to be in full control again as quickly as possible, and waiting for real-world gravity to get them back down usually takes too long. And then there are other racing games that use a value of gravity that is less than the real world value, to facilitate unrealistic jumps at realistic vehicle speeds.

There are also reasons to fiddle with gravity for non-player-character objects as well. Sometimes real-world gravity can create an “objects made of styrofoam” feeling for simulated objects in general,9 so gravity is increased to get an object to tip over and come to rest more quickly. In other situations, an artificially low value of gravity can make a large object seem even more massive (especially when accompanied by the right sound effects), because acceleration on Earth is constant and is one of a few cues humans instinctively use to establish an absolute scale for objects in the distance.10

Hopefully, while reading the preceding design discussion you absorbed a general message rather than focusing on our specific opinions. What “feels right” is a subjective matter; furthermore—and this is the key point—it is based more on player expectation than physical reality. In the end, what matters most in a video game is not what's going on in the CPU or even on the screen, but what is going on in the player's mind. And the human mind is highly susceptible to suggestion. When creating video games, always remember that the quest for realism should never be an end unto itself, but rather a successful video game will harness realism only where it serves the ultimate goal, which is entertainment. In fact, realism is quite often opposed to this goal. Video game makers (especially programmers!) often get these priorities confused and end up creating an impressive technical demo that isn't any fun.

12.2.2Frictional Forces

If we take an object such as a bowl of petunias and slide it along a surface, we know that it will eventually come to a stop. We also know that if we place this bowl on a surface that isn't quite level, it won't necessarily slide downhill unless the angle of inclination exceeds a certain threshold. These two phenomena are slightly different aspects of the force of friction. We are accustomed to thinking of friction as an onerous enemy of productivity, the evil cause of wear on machines and more frequent trips to the gas station. But keep in mind that without friction, we wouldn't be able to walk across a room or pick up a child (or a bowl of petunias). Without friction, our cars might have better fuel efficiency, but the transmission wouldn't work and the tires would spin in place instead of propelling the car forward.

Here we consider the two modes of the standard dry friction model, which is sometimes called Coulomb friction. Although several thinkers contributed to our understanding of friction, Charles-Augustin de Coulomb (1736–1806) is the guy who got his name to stick. When an object is at rest on top of another object, a certain amount of force is required to get it unstuck and set it in motion. If any less force is applied to the object, the force of friction will push back with a counteracting force up to some maximum amount. This type of friction is known as static friction, and it prevents bowls of petunias sitting on slightly inclined tables from sliding off. Once static friction is overcome and the object is moving, friction continues to push against the relative motion of the two surfaces, but the magnitude of this force, known as kinetic friction, is less than that of static friction. Kinetic friction is what causes a bowl of petunias to eventually come to a stop after we set it in motion.

Friction is the result of complicated interactions at the microscopic level, and so it is somewhat surprising that its macroscopic behavior can be described by relatively simple equations. Let's consider static friction first. Like any force, static friction is a vector. The direction of static friction is always in the direction that opposes any forces that would otherwise cause objects to move relative to each other. This might seems a bit like cheating (“How does the friction always know the correct direction to push?”), but remember that the force is actually the aggregate result of many electrical forces acting at the microscopic level. The forces are the result of molecular bonds that have formed between the objects as they came in contact, and these bonds need a force to pull them apart.

A good approximation for the maximum magnitude of static friction is computed with Equation (12.5).

Static Friction

The dimensionless constant μs is known as the coefficient of static friction, and n is the magnitude of the normal force. Let's talk about each of these in more detail.

From our perspective, μs is certainly the easier of the two to deal with: just look it up in a table! Table 12.1 shows just such a table. Note that we are jumping ahead a bit and showing coefficients for both static and kinetic friction. Ignore the kinetic friction column for now.

Material 1 Material 2 μs (Static) μk (Kinetic)
Aluminum Steel 0.61 0.47
Copper Steel 0.53 0.36
Leather Metal 0.4 0.2
Rubber Asphalt (dry) 0.9 0.5–0.8
Rubber Asphalt (wet) 0.25–0.75
Rubber Concrete (dry) 1.0 0.6–0.85
Rubber Concrete (wet) 0.30 0.45–0.75
Steel Steel 0.80
Steel Teflon 0.04
Teflon Teflon 0.04
Wood Concrete 0.62
Wood Clean metal 0.2–0.6
Wood Ice 0.05
Wood Wood 0.25–0.5
Wood (waxed) Dry snow 0.04
Table 12.1Static and kinetic coefficients of friction

Of course, somebody actually has to fill out these tables! The methods for obtaining these data are interesting and rather elegant but they are not our primary concern here. What is very important for us is that the coefficients of static and kinetic friction depend on the properties of both interacting surfaces. In other words, Table 12.1 is indexed not by a single surface type, but by a pair of interacting surfaces. So, for example, although using this table we can find the coefficient of static friction for rubber against asphalt, we cannot use this information to say anything about, for example, rubber against ice, or wood against asphalt. The coefficient of static friction for each pair of surfaces has to be measured experimentally because of the complexity of the microscopic interactions.

Also, note that Equation (12.5) tells us the maximum strength of the static friction force. The actual force exerted at any instant will meet the magnitude of any forces acting on the objects that tend to induce lateral relative motion, up to this maximum. Once this maximum is exceeded, the static friction ceases to operate, and kinetic friction takes over.

The other factor in Equation (12.5) is the magnitude of the normal force, which is the force acting perpendicular to the surfaces that prevent them from penetrating each other. One common situation occurs when an object (such as a bowl of petunias) is resting on top of another object (such as a table). The normal force in this case is simply the force required to counteract gravity. To be more precise, it is the force required to counteract the component of gravity that acts perpendicular to the surfaces and wants to smash them together. If the table is at an incline, then we can separate gravity into a normal component and a lateral component, as shown in Figure 12.4. (Inside a computer, we'd probably describe the orientation of the table with a normal vector, and use the dot product to separate gravity into the relative and normal components, as we described in Section 2.11.2.) Since the bowl and the table do not accelerate relative to each other, we know that the normal force of the table pushing against the bowl must be exactly equal to the normal component of the force of gravity pulling the bowl towards the table.

Figure 12.4 Free-body diagrams of a bowl of petunias on a table at various angles of inclination.

Figure 12.4 shows several free-body diagrams of identical bowls of petunias resting on tables at various angles of inclination. Notice that in each figure, the force of gravity acting on the bowl, labeled g , is the same. The normal and lateral components of gravity have been broken out in blue. The actual force of static friction is the black vector labeled f s . On the left, the maximum amount of friction available is labeled “max f s ,” in the middle and right-hand images the maximum amount of friction is being applied.

In the first scenario, there is more friction available than necessary to stop the sliding. However, as the angle of inclination increases, the normal component of gravity decreases, which reduces the amount of friction available. Meanwhile, as the perpendicular component of gravity is decreasing, the lateral component is increasing, which makes the bowl want to slide. The force of static friction must counter this lateral component if the bowl is to remain in equilibrium. The center image shows the critical angle at which the lateral force of gravity is exactly equal to the to the maximum amount of friction. On the right, we imagine that we have tilted the table while holding the bowl in place, and then let go of the bowl. The maximum available friction is being applied, but it's less than was available in the center picture due to the decrease in the normal force and isn't enough to overcome the increased lateral component of gravity. Just after this picture was taken, friction switched from static mode into kinetic mode, the bowl slid off the table and shattered, and a cartoon cleaning robot scurried in through a little door in the wall to clean up themess.

Calculating kinetic friction is essentially identical to static friction. The only difference is that we replace the subscript s with a k .

Kinetic Friction

The direction of the force of kinetic friction is always opposed to the relative motion of the surfaces. (Remember, according to Newton's third law, there are actually two forces, one pushing against the bowl, and the other against the table, and they are in opposite directions.) As we said earlier, the coefficient of kinetic friction is usually less than the coefficient of static friction. Thus, if we increase the angle of the table ever so slowly so that static friction is just overcome, the petunias will begin to accelerate, based on this difference between kinetic and static friction. Coulomb's primary contribution to the theory, sometimes called Coulomb's law of friction, was that the force of kinetic friction does not depend on the relative velocities of the surfaces, so, unlike static friction, there is no distinction between the effective force and the maximum force.

Notice that the amount of area that the two objects are in contact does not appear in Equations (12.5) or (12.6). For example, let's say we repot the petunias in a taller bowl with a smaller footprint but the same weight. We have reduced the surface area where the bowl and table are in contact, but all of the forces depicted in the free-body diagrams in Figure 12.4 remain the same. Doing this would not change the angle at which the bowl would begin to slide! Although it might seem like a larger surface area would give the objects more to “grab” with, this is offset by the decrease in pressure, since the same total normal force is now distributed over a smaller contact area. Now, a very tall bowl may begin to tip over before it begins to slide. But this is a matter of rotation, the increase in the tendency to rotate being caused by an increase in the lever arm resulting in a greater torque. We cover these issues in Section 12.5.

12.2.3Spring Forces

There's one more class of force that is important enough to discuss in its own section: the forces exerted by a spring disturbed from its equilibrium position. Why do we discuss this admittedly peculiar class of force? Have springs suddenly become prominent features in video games and their accurate simulation an important gameplay feature? Actually, yes. Even if you don't see very many literal springs in a video game, there are likely very many “virtual springs” at work. Springs exhibit a general behavior that is very useful for enforcing constraints, preventing objects from penetrating, and the like.

This section presents the classic equations of motion for damped and undamped oscillation. It covers undamped oscillation first, and then damped. It's often the case in a video game that programmers use a virtual spring (often in the form of a spring-damper system) when really what they are using is a control system. There are certain advantages to be had when the physical nature of the problem is dropped and we think of it purely in mathematical terms. (Indeed, many times the problem was never really physical to begin with, and was only recast in physical terms so that the spring-damper apparatus could be applied.)

Like the friction law, the force law for springs is a surprisingly accurate approximation to the macroscopic behavior that is the result of complicated microscopic interactions. Consider a spring with one end fixed and the other end free to move in one dimension. When the spring is at equilibrium with no external forces on it, it has a natural length, called the rest length. If we stretch the spring, then it will pull back to try to regain its rest length. Likewise, if we compress the spring, it will push back. But how do we know the strength of the force in each case? That's what the force law tells us.

The force law for springs is known as Hooke's law, and it basically says that the magnitude of the restorative force is proportional to the difference from the current length and the rest length (provided the force does not exceed a value called the elastic limit, which varies with the material used to construct the spring). If we let l be the current length of the spring and l rest denote the rest length, then the magnitude of the restoring force f r is calculated by Equation (12.7).

Hooke's Law for Spring Forces
(12.7)f r =k(l rest l).

The constant k is known as the spring constant and essentially describes how “stiff” the spring is. The constant is not dimensionless. In order for Equation (12.7) to make sense, we must have

[ML / T2]=k[L],[ML / T2] / [L]=k,[M / T2]=k,

or you can just think of k as having units of “unit force per unit length.”

The really interesting thing about springs is how they behave over time. To see this, let's restate Hooke's law in a way that focuses on the kinematics of a particle that is being acted on by restorative forces. Specifically, we're interested in functions for the position, velocity, and acceleration of a particle.

Things get easier if we adopt a reference frame where the position x=0 designates the “rest” position, where there are no restorative forces. Furthermore, since we are interested in the acceleration of the particle rather than the forces acting on it, we will introduce a constant K=k / m , and since K contains both the spring constant k and the mass of the particle m , it measures the spring's ability to accelerate the specific particle of interest to us. With those notational changes, we can rewrite Equation (12.7) as

Acceleration due to Hooke's law

You should convince yourself that this is equivalent to Equation (12.7) before continuing.

Equation (12.8) makes a statement about the relationship between the position function and the acceleration function; but what we really want is the function x(t) itself. Equations like this are called differential equations; they describe the relationship between some unknown function (in this case, x(t) ) and one or more of its derivatives (remember that acceleration is the second derivative of position). To “solve” a differential equation is to find the unknown function x(t) that satisfies the equation. We have been able to just barely scratch the surface of basic differential and integral calculus in this book, so we're not going to be able to cover the techniques of solving differential equations. Luckily, you don't need to know differential equations in order to verify that a proposed function x(t) is a solution—that requires only the ability to differentiate the function x(t) . As it turns out, this will be sufficient in the few cases in which we bump up against differential equations in this book.

We can make a pretty good guess at the form of x(t) by looking at a graph. We are not engaging in circular logic here; we don't need to know x(t) in order to get a graph, all we need is a spring with some sort of marking device attached to it.11 Such a graph is shown in Figure 12.5.

Figure 12.5 The graph of the motion of a spring. Hey, that looks familiar…

This function ought to look familiar to you: it's the graph of the cosine function. Let's see what happens if we just try x(t)=cos(t) as our position function. Differentiating twice to get the velocity and acceleration functions (remember, we learned about the derivative of the sine and cosine functions in Section 11.4.6), we get

Close, but not quite right
x(t)=cos(t), x˙ (t)=sin(t), x¨ (t)=cos(t),

which is very close, but we're missing the factor of K .

To understand where K should appear in x(t) , consider what happens to the graph of x(t) when we change the value of K . In other words, we repeat our physical experiment and vary the stiffness of the spring or the mass of the marking device attached to the end of the spring. The result is that larger values of K (stiffer springs or less massive marking devices) result in a graph that is horizontally “compressed”: the frequency of oscillation is increased. Likewise, smaller values of K cause the spring to oscillate more slowly, and the graph is expanded. Furthermore, we observe that the frequency is proportional to the square root of K —when we increase K by a factor of four, the frequency doubles. This gives us a hint as to where K should appear, since all we are doing is scaling the time axis.

A solution, but is it the only one?
x(t)=cos(Kt), x˙ (t)=Ksin(Kt), x¨ (t)=Kcos(Kt).

One verifies that this is a solution to the differential equation by plugging it into Equation (12.8). Remembering that a(t)= x¨ (t) , we have


The quantity K is the angular frequency and comes up often enough that we find it helpful to introduce the notation

Angular frequency
ω=K=k / m,

and we can write the solution as


hence the reason for the name “angular frequency” becomes apparent.

So we have found the kinematics equation for the spring. Or, perhaps we should say that we have found a solution to the differential equation. There are some degrees of freedom inherent in the motion of the spring that are not accounted for in Equation (12.9). First, we are not accounting for the maximum displacement, known as the amplitude of the oscillations and denoted A . Our equation always has an amplitude of 1. Second, we are assuming that x(0)=A , meaning the spring was initially stretched to the maximum displacment A and released with zero initial velocity. However, in general, we could have pulled it to some displacement x0A and then given it a shove so it has some initial velocity v0 .

It would appear that we have three more variables which need to be somehow accounted for in our equation if it is going to be completely general. As it turns out, the three variables we have just discussed—the amplitude, initial position, and initial velocity—are interrelated. If we pick any two, the value for the third is locked in. We'll keep A as is, but we'll replace x0 and v0 with the phase offset θ0 , which describes where in the cycle the spring is at t=0 . Adjustments to the phase offset have the simple effect of shifting the graph horizontally on the time axis. Adding these two variables, we arrive at the general solution, the equations of simple harmonic oscillation.

Simple Harmonic Motion
(12.10)x(t)=Acos(ωt+θ0), x˙ (t)=Aωsin(ωt+θ0), x¨ (t)=Aω2cos(ωt+θ0).

Now let's make some observations. First, remember that the sine and cosine functions are just shifted versions of each other: sin(t+π / 2)=cos(t) . Thus we could have written x(t) using sine instead of cosine, the choice being mostly a matter of preference and an adjustment in the phase by π / 2 . The term “sinusoidal” can be used to refer to the shape of the sine and cosine functions, and we use it when either function will do.

Second, consider the frequency of oscillation. The sine and cosine functions have a period of 2π ; thus the oscillator will complete one cycle in the time it takes for ωt to increase by 2π . The angular frequency ω is measured in radians per unit time, but we can also measure the frequency F , which is in cycles per unit time, as

Frequency of simple harmonic motion
F= ω 2π = K 2π = 1 2π km .

Notice that the frequency of oscillation depends only on ratio of the spring stiffness to the mass. In particular, it does not depend on the initial displacement x0 : if we stretch the spring farther before letting it go, the amplitude increases, but the frequency will not change.

In many situations, the frequency is the important number we wish to control. This is especially the case for “virtual springs,” which are really control systems in disguise. In these situations, we don't need to bother with spring constants or masses, and we can write the equation of motion directly in terms of frequency, as

Simple harmonic motion in terms of frequency

So far, we have been studying a physically nonexistent situation in which the restorative force is the only force present, and the spring will oscillate forever. In reality, there are usually at least two more interesting forces. The first of these forces is an external force, sometimes called the driving force, that acts as the “input” to the system and causes the motion to begin in the first place. The other force is the friction that any real spring experiences, which eventually causes the motion to cease. The general term used to describe any effect that tends to reduce the amplitude of an oscillatory system is damping, and we call oscillation where the amplitude decays over time damped oscillation. Damping forces are particularly important for our purposes, so let's discuss them in more detail.

The most common model for the damping force is a simple one that acts proportional to velocity but in the opposite direction, similar to the friction law. (Unlike the friction laws from the previous section, we don't have any of the business concerning the normal force.) The force is simply

Damping force
f d =c x˙ ,

where f d indicates the instantaneous magnitude and direction of the damping force, x˙ is the instantaneous velocity, and c is a constant that describes the viscosity, roughness, etc.

The damping force has an extremely simple form, but just as with the restorative force, things get interesting when we study the motion over time. Qualitatively, we can make some basic predictions about how damped oscillation of a spring would differ from undamped oscillation of the same spring. The more obvious prediction is that we would expect the amplitude of oscillation to decay over time, meaning the maximum displacement at the crest of each cycle is a bit less than the previous one. Like the force of friction, damping tends to remove energy from the system. The second observation is only slightly less obvious: since damping in general slows the velocity of the mass on the end of the spring, we would expect the frequency of oscillation to be reduced compared to undamped oscillation. Those two intuitive predictions turn out to be correct, although, of course, to be more specific we will need to analyze the math.

Combining the restorative and damping forces, the net force can be written as

f net =f r +f d =kxc x˙ .

To derive the equation of motion, we will need accelerations, not forces. Applying Newton's second law and dividing both sides by the mass, we have

(12.11) x¨ = f net m = km x cm x˙ ,

Next we rewrite this in terms of two new quantities. The first quantity, ω0 , is the undamped angular frequency and is not really new. It is identical to the ω=k / m introduced earlier; we are adding the zero subscript just to emphasize that it is the frequency that would occur without the damping rather than the actual frequency. (Remember, our prediction is that the actual frequency will be slower in some way.)

The second quantity is called the damping ratio, not to be confused with the damping coefficient c . The damping ratio is traditionally denoted by ζ , the Greek letter zeta, which looks weird and takes some practice to write by hand. The damping ratio is related to the damping coefficient, mass, and undamped angular frequency by the formula

Damping ratio
ζ= c 2mk = c 2mω0 .

In just a moment, when we explain the qualitative meaning of ζ , the utility in using this arbitrary formula will become apparent.

Substituting the undamped frequency ω0 and damping ratio ζ into Equation (12.11), we have

Differential equation for damped harmonic oscillation
(12.12) x¨ =ω02x2ζω0 x˙ .

Readers with training in differential equations should recognize Equation (12.12) as a second-order linear homogenous differential equation with constant coefficients, which is one of the very nicest differential equations we could hope for, meaning we can actually solve it with pencil and paper. Readers without this training shouldn't worry, because it won't be needed to understand the answer, to which we now fast forward, skipping the derivation. There are three distinct cases: underdamping, critical damping, and overdamping.

When 0ζ<1 , we say that the system is underdamped. In this case, as we have been predicting, the motion will continue to oscillate indefinitely with an amplitude that decays exponentially over time. The equation that describes this motion is

Kinematic equation for underdamped system
(12.13)x(t)= (k1cos(ωdt)+k2sin(ωdt)) e ζω0t ,

where ωd is the actual frequency of the damped oscillation and is related to the undamped frequency ω0 by

Damped angular frequency

The constants k1 and k2 are determined by the initial position and velocity:

k1=x(0),k2= ζω0x(0)+ x˙ (0) ωd.

Using ζ=0 produces undamped oscillation, and Equation (12.13) is equivalent to Equation (12.10).

Your common sense tells you that as we increase the damping ratio, the frequency of oscillation decreases; consulting Equation (12.14), we see that at ζ=1 the frequency completely vanishes. At this threshold, known as critical damping, the behavior of the system changes qualitatively. The system no longer oscillates, but instead decays exponentially. The kinematic equation in this situation is

Equation of motion at critical damping
(12.15)x(t)= (k1+k2t) e ω0t ,

where k1 and k2 are again determined by the initial conditions:

k1=x(0),k2=ω0x(0)+ x˙ (0).

Critical damping is just the right amount such that the system decays as quickly as possible without oscillation. If the damping is decreased, the system is underdamped, as previously described, and will oscillate. If the damping is increased, the system is overdamped; it will not oscillate, and the rate of decay will be slower than the rate at critical damping. Figure 12.6 shows how the damping value affects the behavior of a system.

Figure 12.6Undamped, underdamped, and critically damped systems.

Now that we've reviewed the classic equations that may be found in any physics textbook or on, let's say a few words about how spring-damper systems are used in video games as control systems. In

general, a control system12 takes as input a function of time that represents some target value. For example, our camera code might compute a desired camera position based on the player's position each frame; some AI code might determine an exact targeting angle for an enemy; we may have a desired player character velocity based on the instantaneous amount of control stick deflection; or we might have a desired screen-space position for some highlight effect, based on the currently selected choice in a menu. In any case, the current value of the input signal is known as the set point in control system terminology. The set point is essentially the rest position of the spring, and the input signal is like somebody taking the other end of the spring and yanking it around. (So it's similar to a driving force, only usually what we have is a function describing a position rather than a force or acceleration.)

The job of any control system is to take this input signal and produce an output signal. To go back to our earlier examples, the output signal might be the actual camera position to use for each frame, or the actual animated targeting angle the enemy will use to aim the weapon, the actual player character velocity, or the actual screen-space position of the highlight. For many control systems, the actual position and set point are not used; rather, only the error is needed. Of course, an obvious question is, if we know the “desired” value, why don't we just use that directly? Because it's too jerky. In the same way that the shocks and springs on a car (a classic example of a spring-damper system) don't just pass along the elevation of the road directly to the car, a control system in a video game is often designed to “smooth out the bumps” caused by sudden state changes that might make the camera snap to a new position or the player jerk into motion. The camera or screen-space highlight are nonphysical examples in which the quantity of “mass” is not really appropriate and is dropped. But the differential equations are still the same, and they have the same solution. Stripped of the spring metaphor, we are left with what is known as a PD controller. The P stands for proportional, and this is the spring part of the controller, since it acts proportional to the current error. The damper is the D part, which stands for derivative, because the action of the damper at any given instant is proportional to the derivative (the velocity). PD controllers (and their more robust cousin, the PID controller, where the I stands for integral and is used to remove steady-state error) are broadly applicable tools; they have been standard engineering tools for decades (centuries?) and are well understood. Nevertheless, they are one of the most frequently reinvented wheels in video gameprogramming.

In practice, the simulation code is a very simple Euler integration of Equation (12.11). As shown in Section 12.6.3, this is a fancy way of describing code that looks like Listing 12.1.

struct SpringDamper {
    float value;    // current value
    float setPoint; // "desired" value
    float velocity; // current ``velocity'' (derivative of value)
    float c;        // damping coefficient
    float k;        // spring constant

    // Update the current value and velocity, stepping forward
    // in time by the given time step
    void update(float dt) {

        // Compute acceleration
        float error = value - setPoint;
        float accel = -error*k - c*velocity;

        // Euler integration
        velocity += accel*dt;
        value += velocity*dt;

Different cars have suspensions that are tuned differently; sports cars are “tighter” and the cars retirees like to drive are smoother. In the same way, we tune our control systems to get the response we like. Notice that the simulation uses the k and c from Equation (12.11). However, most people don't find those to be the most intuitive dials to have for tweaking. Instead, the damping ratio and frequency of oscillation are used for the designer interface, while k and c are computed as derived quantities. To tune the frequency, we might adjust either the damped or undamped version, using either angular frequency or simply Hertz; the units and absolute value are often not important because the value that feels good will be determined experimentally anyway. For many systems in video games, oscillation is undesirable, so it's common to assume a critically damped system and fix ζ=1 , leaving just the “frequency” (we put it in quotes since the system doesn't oscillate) as the only tunable value. A higher frequency is the sports car (more responsive, but jerkier), and a lower frequency is smoother, but can feel “laggy.”

Notice that the kinematic equations (12.13) and (12.15) are not needed directly by the simulation, nor do we need to explicitly distinguish between underdamped, critically damped, or overdamped.

Before we leave this discussion, we must mention that the second-order systems we have described here are certainly not the only type of control system, nor even the simplest, but they do behave nicely under a very broad set of circumstances and are easy to implement and tune. Another commonly used control system is a simple first order lag, x˙ =kx , under which the error decays exponentially. This is similar to a critically damped second-order system, but with a bit jerkier response to a sudden change in the set point. Another important and common technique is to “chase” the set point at a fixed velocity. A filter is another broad class of control system, in which the output is computed by taking some linear combination of set points or values on previous frames.


Let's say that Moe's box from Section 12.1.3 has a mass m , and at a certain instant we observe it moving with a velocity v . Coming in late to the story, we cannot tell what magnitude of forces were used to achieve that motion, or how long the forces were applied, or what the history of the box's velocity was. For example, it could have been that the box was accelerated as a result of a constant net force f being applied over a duration Δt . But we have no way of knowing the values of f and Δt . Was a large force used for a small duration, or a small force for a longer duration? In fact, we have no reason to assume that the force was constant at all! Moe could have given the box a good shove and set it in motion, and then gave it another shove to speed it up.

While we don't know the exact history of Moe's pushes, we do know what the “total” was, in the sense about to be described. Assume that Moe did make one push with a constant force f applied for a duration Δt . Then according to Newton's second law, the acceleration was a = f / m . Assuming the initial velocity was zero, we know that

v = a Δt.

Substituting a = f / m and rearranging, we get

Two ways to think of momentum
v =( f / m)Δt,(12.16)m v = f Δt.

The left- and right-hand sides of Equation (12.16) illustrate two different ways of thinking about the important concept of momentum. Momentum is the correct quantity to track in order to quantify the “total amount of pushing.”

Let's do dimensional analysis on Equation (12.16), first just to verify that it makes physical sense—it isn't intuitively obvious that these two products would bear the same physical meaning—and also to see what the units of momentum should be:

m v = f Δt,M(L / T)=(ML / T2)T,ML / T=ML / T.

Note that momentum is a vector quantity, having both magnitude and direction.

To understand what momentum is, let's look at the two sides of Equation (12.16). First consider the left side, which interprets momentum as a product of mass and velocity. In fact, somewhere in almost every physics textbook you can find Equation (12.17).

Momentum as Product of Mass and Velocity
(12.17) P =m v .

The variable P is the traditional variable used to represent momentum. (Despite the capital letter, P is a vector quantity. We use capital P to avoid confusion with the notation p , which we sometimes use to refer to the position of a particle.)

Equation (12.17) makes it clear that the momentum of an object is an instantaneous property of an object. By saying this, we mean that we can define its value knowing only its instantaneous state, without worrying about how it got into that state. Furthermore, if you think of momentum as the “total amount of pushing” required to stop a moving object, then it certainly is intuitively appealing that it should be the product of mass and velocity. If the object is small and moving slowly (a pencil rolling on a desktop), only a small total force will suffice. If it's fast (a bullet) or heavy (a car that somebody left parked on an incline without the emergency brake set), a larger amount will be needed. If it's fast and heavy (an airplane coming in for a landing), then you'd better get out of the way. The equation P =m v quantifies the idea of “hard to stop.”

Although the memorable equation P =m v from the left-hand side of Equation (12.16) is perhaps the more common way of explaining momentum, the right-hand side actually provides the most insight. The relation P = f Δt shows that momentum, as the product of force and time, is what results when force acts over time. This is what was meant by the sloppy phrase “total amount of pushing.” We don't mean that the magnitude of the force pushing itself is changing or accumulating, but rather that the continued application of a net force always results in a buildup of momentum (or a reduction of momentum, when the directions of the force and momentum are opposed).

In fact, if we generalize the equation P = f Δt , we can discover an even deeper relationship between force and momentum. What if, instead of pushing the box with a constant force, Moe pushed it with a force that varied over time? Then we can express the acceleration at any given time t as

(12.18) a (t)= f (t) / m,

which is just Newton's second law to which we've added the notation “ (t) ” to be more explicit that a and f vary with time. We learned in Chapter 11 that if we integrate acceleration over time, we get the velocity as a function of time:

Velocity is the time integral of acceleration, remember?
(12.19) v (t)= a (t) dt.

Substituting Equation (12.18) into Equation (12.19), assuming that the mass does not vary over time, we have

v (t)= f (t) / m dt,m v (t)= f (t) dt.

Finally, if we let P (t) be the momentum of a body as a function of time, then by substituting P (t)=m v (t) , we arrive at the important relation

Momentum as force accumulated over time
(12.20) P (t)= f (t) dt.

Since integration is a “summing up” process, Equation (12.20) confirms our interpretation of momentum as the result of continued application of force over time. (Note: in the preceding integrals we omitted the constant of integration, essentially assuming the initial velocity was zero.)

Remember that integration and differentiation are inverse operations. By taking the derivative of both sides with respect to t , we state the flip side of the relationship between momentum and force.

Force as the Derivative of Momentum
(12.21)d dt   P (t)= f (t).

The net external force on a system is equal to the rate of change of momentum of the system.

Equation (12.21) is not just an interesting observation about force and momentum, it's a completely valid way to define force. In fact, although the modern presentation of Newton's laws is in terms of forces and masses, when Newton himself first expressed the laws, he wrote in terms of momentum. He used the word “motion,” but from his writings we understand that he used that word in a very particular sense, and he really was talking about momentum. (The word momentum hadn't been attached to that concept yet. Remember, he was the guy laying down all the ground rules.) Newton's second law was originally expressed in a form that more closely resembles Equation (12.21) than the f =m a form you will more commonlysee.

12.3.1Conservation of Momentum

Let's return to our investigation into what happens when Moe pushes against the Earth to get his box moving. Newton's law tells us that the Earth, not having anything else to push back on, receives a net force, and thus an acceleration (and a torque, which we discuss later). Yes, you cause the Earth to accelerate when you push boxes as well as when you take each and every step! Of course, the Earth's mass is so large compared to Moe's force that this acceleration is small. Not only that, but Moe's force pushing the box to the east might be canceled out by Joe's force in North Dakota pushing his box to the west at the same time. An issue even more important than these two facts involves the “accounting laws” of physics: “there is no such thing as free momentum.” Moe doesn't need Joe to balance out his force; as it turns out, he can't help but do it all byhimself!

Observe that once Moe sets the box in motion, he will need to eventually stop it. According to Newton's first law, the only way to stop a moving box is through a force, and according to the third law, this can happen only if there is some other object involved to receive the opposite force. Perhaps the box bumps into a tree and comes to a stop. (We consider the tree to be part of the Earth. Remember that Newton's third law justifies our treatment of connected objects as a single object, provided that they remain rigidly connected.) To stop the box, the Earth must push against it with a force that is in the opposite direction that Moe pushed to start it moving. However, we know that the “total amount” of pushing must be the same, meaning the Earth must push back with a strong enough force, or for a long enough duration (perhaps Moe's box rolls into a patch of tall grass) to bring the momentum of the box down to zero. So you see that whatever acceleration the Earth received as a result of getting Moe's box in motion must always be exactly canceled by the force required to bring the box to a stop.

But perhaps Moe's box does not come to a stop by pushing directly against the Earth. Let's say it bumps up against Joe's box. Voila! We have stopped Moe's box, and no force has been applied to the Earth. But now, by Newton's third law, Joe's box must begin accelerating, and we are back to where we started with a moving box that will continue moving unless it receives a force to bring it to a stop. Eventually, the only way we can stop this chain reaction started by Moe's push against his box is for something, eventually, to push against the Earth.

We can generalize this idea even further. We are justified in treating the entire Earth, and all of its moving parts, as a single particle with all of its mass centered at some location known as the center of mass. (We talk more about this special point in Section 12.3.2.) The pushing against the Earth of people like Moe results in transfers of momentum between the objects in the system. Each part will move around within this very complicated system relative to the other parts and relative to the center of mass of the system. However, the total amount of momentum of the entire system is always a constant, unless there are external forces acting on the system. This is known as the law of conservation of momentum.

The Law of Conservation of Momentum
The momentum of a system is constant unless external forces act on that system.

The conservation of momentum is precisely what Equation (12.21)is saying. It's certainly an experimentally verified fact, but it also follows naturally as a result of Newton's laws. Section 12.4 discusses how to use this important law to simulate the collision of objects. However, before we get to that, we need to take a closer look at the center ofmass.

12.3.2The Center of Mass

Our discussion of momentum has led us to consider the center of mass of an object. Let's say a few more words concerning this important concept. For everyday purposes, the center of mass is equivalent to the center of gravity, which is essentially the point around which the object is perfectly balanced. If we balance an object on the tip of a very thin rod or hang it from a wire, then the rod or wire will be in a line that contains the center of mass.

Before we discuss how to compute the center of mass mathematically, let's see how we can measure it experimentally. Imagine that we have some object with an odd shape, or of an irregular density. We can determine its center of gravity by hanging the object from any arbitrary point on the surface of the object. This defines a vertical line upon which the center of gravity must lie. By repeating the experiment with a different point on the object and finding the intersection of those two lines, we can locate the center of gravity.

The authors performed this experiment on a piece of particle board, as shown in Figure 12.7. First, the board was cut into a purposefully asymmetric shape. Next, we chose three arbitrary locations from which to hang the board, and when the board had finished swinging around, we drew a heavy line on it, coincident with the string by which the board was suspended. Sure enough, physics worked, and the third line passed right through the intersection of the first two lines, at the board's center ofmass.

Figure 12.7Experimentally measuring the center of mass of a odd-shaped piece of particle board

To compute the center of mass mathematically, we imagine the object being divided up into a very large number of small “mass elements.” If there are n such elements, and we denote the mass and position of the i th element as mi and r i , respectively, then the center of mass r c is simplify the weighted average of the positions of all the mass elements.

Calculating the Center of Mass
(12.22) r c=1Minmi ri .

In Equation (12.22), M is the total mass of the object


For our purposes, the most important property of the center of mass is that if the object rotates, it will rotate about its center of mass. This assumes, of course, that the object is freely rotating and there isn't a constraint compelling it to rotate about some other point.

As an example, consider a sledge hammer. Clearly, the center of mass of the sledge hammer is close to the heavy end of the sledge, not in the middle of the handle. Assume we throw the hammer across the room. As it tumbles through space, any arbitrary point on the hammer will trace out a complicated spiraling shape. The center of mass, however, moves in a parabola, in perfect agreement with the kinematics equations we learned in Chapter 11.

The authors couldn't resist the opportunity to chuck big objects around, so we verified this hypothesis experimentally, and you can, too.13 We started with the odd-shaped piece of particle board, whose center of mass had been experimentally located and clearly marked. Next, the fun part:

we threw it in the air and took a series of pictures of its trajectory with a camera mounted on a tripod. Finally, we merged these frames together into a single image, and used least-squares to fit a parabola through the points marking the center of mass. The result of the experiment is Figure 12.8.

Figure 12.8 The center of mass is the special point that obeys the simple kinematic equations from Chapter 11. Any other point traces out a spiraling path as the object rotates.

One small note: When fitting the parabola, we did not include the first frame in the data set. As you can see, on the first frame the board is still in the assistant's hand, and thus has not yet begun its (parabolic) free fall trajectory.

Because an object will rotate about its center of mass when allowed to rotate freely, in a physics simulation is it highly advantageous to select the origin of your object to be at its center of mass. Of course, you may have good reasons to put the origin of the object elsewhere. For example, you may have a graphical representation of an object with the origin placed somewhere that made sense to the artist who made that model. In general, if you place the origin somewhere other than the center of mass, then you will likely have to deal with two “positions” of the object: one position within the physics system that describes the world coordinates of the center of mass, and another, perhaps in the rendering system, for the origin of your

graphical model. The code that translates between these two conventions is likely to be found either in the interface with the physics engine (for example, the code that updates the position of the objects after the physics simulation has run), or the code that sets up the reference frame for the object during rendering.

The center of mass is fixed for a rigid body such as a sledge hammer; this assumption has been implicit in the whole discussion; otherwise, it wouldn't make sense to advise setting the origin at the center of mass. However, for a general system with moving parts, such as Earth, the center of mass is a dynamic property, not a constant. The center of mass shifts around within the object as the parts are reconfigured.

For example, imagine if all of the people in the world decided to visit the North Pole at the same time. Assuming we would all fit and there were enough earmuffs to go around, the Earth's center of mass would shift towards the North Pole. This new center of mass, however, would trace out the exact same trajectory as the old one would have. In other words, while the trajectory of the Earth's geometric center would be slightly “southward” from where it would have been if we all stayed at home, the trajectory traced out by the center of mass is the same in either case.

Or, let's say that instead of visiting the North Pole, we all decided to go to the Galapagos Islands, which is very near the equator. Would Earth's rotation suddenly get all “wobbly” like an out-of-balance ceiling fan? No! Instead, the center of mass would shift towards the Galapagos Islands, and the Earth would rotate about this new center of mass. So although the rotation, when viewed from above, might appear asymmetrical, since the rotation would not be about the center of the spherical Earth (assuming the Earth were perfectly spherical), the rotation would be smooth. An unbalanced ceiling fan is wobbly because it is not free to choose its axis of rotation, and so it must be balanced in order to align the center of mass with the fixed axis of rotation. Earth, however, is not connected to anything, and it is free to rotate about its center of mass, wherever that center of mass may be.

Of course, all the people on Earth put together have less mass than our moon, so our discussion has been misleading. The point that traces an ellipse as we orbit the sun isn't the Earth's center of mass at all! It is the center of mass of the entire Earth-moon system. This point isn't really close to Earth's geometric center, although it is beneath the surface, but only because Earth is so much more massive than the moon. As the moon orbits the Earth, the center of mass of the system shifts around within Earth. It is this imaginary point that orbits the sun, not the center of mass of Earthitself.

12.4Impulsive Forces and Collisions

In video games, things are always ramming into each other, so it seems appropriate for us to spend some time talking about collisions. As we've mentioned, in the real world, momentum does not change instantaneously; rather, a large force acts over a very small period of time. However, despite reality (remember the first law of video game physics), it is frequently the case that the interval during which these forces act is below the resolution of our physics time step, and for practical purposes we can consider the change in momentum to have happened instantaneously. The most important and common scenario is when the object is involved in a collision. Since the mass of most objects is constant, an instantaneous change in momentum usually boils down to an instantaneous change in velocity.

Consider two objects traveling towards each other in one dimension, with masses m1 and m2 and velocities v1 and v2 , as illustrated in Figure 12.9.

Figure 12.9A collision

Using the momentum relation p=mv , we can calculate the momentum of the two objects (denoted p1 and p2 ) and the system as a whole (denoted as simply p ) before and after the collision. We assume that the masses remain constant and put primes on the symbols that refer to the values after the collision:


The change in momentum of each object, according to the law of conservation of momentum, is actually the result of a force acting over time. However, we think of the collision here as producing an instantaneous change in momentum of the two objects. A force that is treated in this way is known as an impulsive force, or more simply, an impulse. Since an impulse is an immediate change in momentum, it has the same units as momentum: ML / T . Note that an impulse is a very different beast from a regular force, which has units ML / T2 . It is very common programmer mistake to use impulses and forces incorrectly, so be sure to watch your units.

When two objects collide, many things can happen, even if we assume they remain intact. A likely scenario is for them to bounce off of each other, changing the signs of both v1 and v2 . Or they may stick together. The former is known as an elastic collision and the latter an inelastic collision. (Actually, only a “perfect bounce” is considered truly elastic. The terms “perfectly inelastic” and “perfectly elastic” are used to refer to the two extremes, while an intermediate collision is described as simply “inelastic.” Section 12.4.2 defines these terms a bit more precisely by using the coefficient of restitution, but to fully understand the distinction requires an understanding of kinetic energy. As we mentioned at the beginning of Chapter 11, energy is certainly an important concept in physics, but it actually doesn't play a central role in the Newton-Euler dynamics used by most real-time simulations, and it isn't discussed much in this book.) The velocity (and momentum) of each object is likely to change, but the law of conservation of momentum says that the total momentum of the system of both objects must remain constant. That is, p=p .

In general, we cannot predict the individual velocities v1 and v2 using just the law of conservation of momentum, since the conservation of momentum law gives us one equation ( p=p ) and there are two unknowns. Before we consider what other bit of information we need, let's look at some simpler cases of collisions and conservation of momentum. Assume for the moment that the collision is perfectly inelastic, that is, the objects stick together upon impact. This gives us the other equation we needed to solve the system of equations: v1=v2 .

12.4.1Perfectly Inelastic Collisions

A classic example of an inelastic collision is a gun firing a bullet into a block. Assume that, as illustrated in Figure 12.10, a block of wood weighing 2.00 kg is at rest, hanging from a wire whose mass is neglected. We fire a gun at the block, and the bullet, which has a mass of 10 g, strikes the block with a speed of 350 m/s. The bullet remains stuck in the block. What is the horizontal speed of the block immediately after the impact?

Figure 12.10 A bullet fired into a block suspended by a wire (in other words, a typical episode of MythBusters)

First, we compute the initial momentum of the system, which is all contained in the bullet:

p=m1v1+m2v2=(2.00  kg )(0)+(10.0  g )(350  m / s )=3.50  kg m / s .

Now we look for the resulting common velocity, which we'll denote simply as v , using the law of conservation of momentum, p=p , and the knowledge that this is an inelastic collision, v=v1=v2 :

p=m1v1+m2v2,3.50  kg m / s =(2.00  kg )v+(10.0  g )v,3.50  kg m / s =(2.00  kg +10.0  g )v,(3.50  kg m / s ) / (2.01  kg )=v,1.74  m / s =v.

Let's look at one more example of an inelastic collision, this time in 2D. Consider a driver who runs a red light and crashes into a car crossing the intersection. Let's say that Grant is the safe driver, and at the time of the collision, Grant and his fuel-efficient hybrid have a combined mass of 1,500 kg and are traveling west at 35 km/hr. Kari,14 who is not paying attention, sees Grant's car too late, and swerves to the left. She and her car have a combined mass of 2,500 kg. At impact, she is traveling at 65 km/hr, heading 25° west of north, as shown in Figure 12.11. Assume that we can treat the collision as inelastic. What is the velocity of the crash just after the collision?15

Figure 12.11A car crash

To solve this problem, let's set up a 2D coordinate space where +x is east and +y is north. We compute the total momentum before the crash as

P =m1 v 1+m2 v 2=(1,500  kg )(35  km / hr ) [ 1 0 ] +(2,500  kg )(65  km / hr ) [ cos115 o sin115 o ] =(52,500  kg km / hr ) [ 1 0 ] +(162,500  kg km / hr ) [ 0.423 0.906 ] = ( [ 52,500 0 ] + [ 68,700 147,000 ] )   kg km / hr = [ 121,200 147,000 ]   kg km / hr .

The resulting velocity of the glob of two cars is simply the momentum we have just computed divided by the total combined mass:

v = P / (m1+m2)= ( [ 121,200 147,000 ]   kg km / hr ) / (1,500  kg +2,500  kg )= ( [ 121,200 147,000 ]   kg km / hr ) / (4,000  kg )= [ 30.3 36.8 ]   km / hr .

12.4.2General Collision Response

Simple inelastic collisions can be solved by using the principle of conservation of momentum, but how do we compute the velocities in the general case? Before we can fully answer that question, we need to consider the context in which it is asked. Dealing with collisions is typically a two-step process. First, we must detect that a collision has occurred, meaning the objects are already penetrating, or that a collision is about to occur in this time step. The second step is to take measures to resolve or prevent the collision. The former task is known as collision detection, and the latter as collision response. Our purpose at this time is to discuss collisions in theoretical terms (we touch on a few practical issues related to how physics simulations really work in Section 12.6), so for now let us merely attempt a general explanation of how the momentum of rigid bodies changes in response to collision. We assume that we already know that two objects have collided, and we wish to predict their behavior after thecollision.

To do this, either in the abstract in a physics problem, or in collision response code in a digital simulation, we typically need to know not just that two objects have collided, but also where they collided, and how the two objects were oriented relative to each other at the point of contact. For example, in the car crash between Grant and Kari, we need to know that Grant's car was hit near the left door, and Kari's in her right front fender. Of course, a collision doesn't necessarily happen at a single point. Often an edge of one object may touch a surface of another, or perhaps entire surfaces are in contact. At the time of this writing, most real-time collision detection systems do not return collisions in such a descriptive manner, nor are collision response systems really capable of making use of that extra information. The closest we get is for the detection system to locate several points of contact (or penetration) and then to process that list in some way (for example, by finding their convex hull or looking for an average surface normal). In any case, the best way to do this quickly is very much at the forefront of research, and as such doesn't belong in an introductory book like this. Here we just consider the principles involved in a single point of contact. More advanced techniques build upon these principles.

Figure 12.12 shows some example collision results that might be returned from a collision detection system. Note that each collision result (black arrow) has a point of contact (at the tail of the arrow), and a surface normal, usually assumed to be a unit vector. An arbitrary convention is chosen for which way the normal will point; in Figure 12.12 it points away from the “first” object. Furthermore, the two objects may be arbitrarily assigned the roles of “first” and “second” objects, perhaps by the luck of the draw that the objects happened to be in some space-partitioning structure. These assignments can even vary frame-by-frame, so the response calculation must be symmetric. What is not depicted in the diagram is that a penetration depth is often returned if the objects are already penetrating.

Figure 12.12 Examples of the types of results returned by collision detection.

And always, we should bear in mind the first law of video game physics. Not all collisions in video games must be between “real” objects, meaning those objects that are represented in the physics system. For example, consider a game with a kick mechanic. It may be helpful to treat a kick as a “collision” with an object, even if the character's foot is not in the physics system or if this collision was determined by simple proximity tests or raycasting that were designed based on gameplay goals and not reality. (The player character may have been too far away or too close for the kick to really have hit the target; but that is irrelevant.) It might be highly useful for the response to this action to be handled in a manner similar to ordinary collisions. For example, a sound and particle effect plays, the object receives a reduction in hit points, and its visual appearance changes, etc. In this case, in order to use the same collision response code for both ordinary collisions and “virtual” collisions such as player kicks (even if it is just to get the cosmetic effects right), you may need to synthesize values ordinarily provided by the collision detection system for your “virtual” collisions, such as the mass and velocity of the foot, and the point of contact and surface normal.

One final caveat is that we are concerned only with linear momentum for now; our objects do not rotate. This means that the explanation we give in this section will be incomplete. However, it will be helpful to cover the general principles here in a context free of the extra complexity that comes with rotation.

Now to the heart of the matter. Assuming we have somehow detected a collision and obtained a position and normal, how do we determine the resulting velocities for the collision response? Here we show the usual method, following an article by Chris Hecker [7]. We start by reviewing our guiding principles.

Our first guiding principle is that, although we know that in reality a very large force acts for a short period of time, the period of time is so short relative to our time step that we will consider the collision response to occur instantaneously. That is, we will not be calculating a force, but rather an impulse, which will result in an instantaneous change in momentum of the objects.

The second guiding principle is given to us by Newton's third law: whatever (impulsive) force is applied to one object, the opposite force must be applied to the other object. The conservation of momentum law essentially says the same thing: if we change the momentum of one object, we must make the opposite change in momentum to the other object so that the total momentum of the system after the collision is the same as the total momentum before the collision.

Thus, to resolve a collision between two objects, the game plan is to compute an impulse with the proper magnitude and apply that impulse to both objects, but in opposite directions. An impulse is a vector quantity, and so we need to know its magnitude and direction. The direction is given to us already: it is the surface normal provided by the collision detection system. The details of selecting a surface normal is a matter of collision detection, not response, and will not be discussed here. But notice that if the objects move parallel to this normal, they are either making the problem worse (penetrating further) or better (moving apart and resolving the penetration). In contrast, if we assume the penetration distance is relatively small and the surfaces are locally flat and perpendicular to the normal near the point of contact, then any motion perpendicular to the surface normal does not cause the penetration distance to change. So the surface normal is really the only direction that matters.

In summary, our task is to determine the proper magnitude of an impulse that will be directed along the surface normal and will resolve (or prevent) the penetration. To merely prevent a penetration that has not yet occurred, we need only remove any relative velocity acting parallel to the surface normal. This portion of the relative velocity is the velocity that, if applied to move the objects forward in time, would result in penetration. Any relative velocity acting perpendicular to the normal is OK and does not need to be counteracted, according to our assumption that the surfaces are locally flat near the point of contact. As illustrated in Figure 12.13, the velocity of m1 relative to m2 is computed as v rel = v 1 v 2 , and the length of this projection onto the normal is given by n v rel .

Figure 12.13 Computing the amount of relative velocity acting parallel to the surface normal

Canceling the relative velocity will prevent penetration, but it's not always the correct response. When objects collide, they don't just come to a stop next to each other—they bounce off each other. So we're missing an ingredient that describes the difference in the collision responses of a dropped beanbag and a dropped SuperBall. A simple and popular collision law (though not the only one) that can be used to discriminate between these cases is Newton's collision law. This law introduces the coefficient of restitution, denoted e , which is a fractional number that relates the magnitude of the relative velocity along the surface normal after the collision with the same value measured just before the collision. When e=0 , the post-collision velocity along the normal is zero, and we have a perfectly inelastic collision. Using e=1 produces a perfectly elastic collision, where the relative velocity along the normal has the same magnitude (but opposite sign) as before the collision. Dropping a beanbag onto carpet is a close example of an inelastic collision, whereas dropping a SuperBall is a highly elastic collision. Using the formulas from Section 11.6, we can also show that, if an object is dropped and allowed to bounce multiple times, the coefficient of restitution gives the ratio of apex heights at successive bounces.

Let's denote the magnitude of the collision response impulse as k . The first mass, m1 , will receive the (vector) impulse k n , while m2 undergoes the opposite change in momentum of k n . The signs are based on our arbitrary choice of the direction of the surface normal. Now that we know what we want, calculating the proper k to cancel the relative velocity is a straightforward algebraic exercise. As before, we denote the post-collision values with primes. An impulse is an instantaneous change of momentum, so the post-collision momentum of the first object is P 1= P 1k n . Dividing by the mass and remembering P =m v , we express the post-collision velocities as

Post-collision velocities
v 1= v 1k n / m1, v 2= v 2+k n / m2.

The post-collision relative velocity is simply their difference, v rel = v 1 v 2 . We solve for k by expressing the resulting relative velocity along the normal as the desired multiple of the relative velocity along the normal before impact.

Solving for k , the magnitude of the impulse
v rel n =e v rel n ,( v 1 v 2) n =e v rel n ,[( v 1k n / m1)( v 2+k n / m2)] n =e v rel n ,[( v 1 v 2)(k n / m1+k n / m2)] n =e v rel n ,[ v rel k(1 / m1+1 / m2) n ] n =e v rel n , v rel n k(1 / m1+1 / m2) n n =e v rel n ,k(1 / m1+1 / m2) n n =(e+1) v rel n ,(12.23)k= (e+1) v rel n (1 / m1+1 / m2) n n .

Equation (12.23) can be simplified slightly in the common case that n is known to have unit length. If n is not a unit vector, then the change to k as a result of the length of n is balanced by the calculation of the (vector) impulse k n . Thus k is the true magnitude of the impulse only when n is a unit vector.

Let's work through a few examples of Equation (12.23). First, let's see how the coefficient of restitution can be used to describe the difference between dropping a beanbag and a SuperBall. We'll be dropping these objects onto a concrete floor, which is an enlightening example because it shows how immovable objects can be easily handled in most physics engines by acting as if they have infinite mass. As it turns out, the inverse mass is the quantity we usually work with in calculations involving such special objects (as illustrated in Equation (12.23)). Furthermore, the inverse mass (and its analog, the inverse inertia tensor, to be discussed later) are derived quantities that are needed so frequently that they are often precomputed. This means that physics code can often work with immovable16 objects without treating them as a special case, simply by setting the inverse mass equal to zero. When one of the inverse masses is zero, we could actually deal directly with velocities and bypass Equation (12.23), since k will be proportional to the mass but the velocity change as a result of applying k is inversely proportional to the mass. Later, we solve a general case example where no such simplifications are possible.

Let's say we have one SuperBall and one beanbag, each weighing 50 grams. To avoid making the solution to our example completely obvious without Equation (12.23), we will arrange for the point of impact to occur on an inclined surface, so that n is not a trivial cardinal axis. Since we are not bound to use a unit vector, let's say that n =[1,3] . In our imagination, we throw both objects in exactly the same way, such that the impact velocity in both cases is v 2=[4,4] . This is illustrated in Figure 12.14.

Figure 12.14 Bouncing a beanbag or SuperBall off of an inclined surface

To determine the resulting velocity, we first solve for k , the scale factor for the impulse. To do this, we must choose a coefficient of restitution. For the SuperBall collision, we'll use e=0.9 , which is near the advertised value. Solving for k (remember that v rel = v 1 v 2 ) we get

Calculating the impulse multiplier k for the SuperBall
k= (e+1) v rel n (1 / m1+1 / m2) n n = (0.9+1) [ 4  m / s 4  m / s ] [ 1 3 ] (0+1 / (50  g )) [ 1 3 ] [ 1 3 ] = 1.9(16  m / s ) 10 / (50  g ) =152  g   m / s .

To compute the post-collision velocity, we add an impulse of k n to the momentum of the SuperBall. Since momentum is mass times velocity, the change in velocity is equal to this impulse divided by m2 , the mass of the SuperBall:

Calculating the post-impulse velocity for the SuperBall
v 2= v 2+ k n m2 = [ 4  m / s 4  m / s ] + (152  g   m / s ) [ 1 3 ] 50  g = [ 4  m / s 4  m / s ] + [ 3.04  m / s 9.12  m / s ] = [ 0.96  m / s   5.12  m / s ] .

Before we show this velocity graphically, let's look at the beanbag. We treat the beanbag collision as almost completely inelastic and use e=0.01 . Other than the change to e , the procedure is the same as for the SuperBall:

Calculating the impulse multiplier k and post-impulse velocity for the beanbag
k= (e+1) v rel n (1 / m1+1 / m2) n n = 1.01(16  m / s ) 10 / (50  g ) =80.8  g   m / s , v 2= v 2+ k n m2 = [ 4  m / s 4  m / s ] + (80.8  g   m / s ) [ 1 3 ] 50  g = [ 2.38  m / s   0.85  m / s ] .

Notice that the reduced coefficient of restitution caused the beanbag to receive a smaller impulse scale, and the resulting bounce velocity was also lower. This difference is shown graphically in Figure 12.15. For comparison, we've also included a perfectly inelastic collision ( e=1 ). The perfectly inelastic collision ( e=0 ) is very close to the beanbag result and is not depicted.

Figure 12.15 Post-impact velocities for different values of e , the coefficient of restitution

It is obvious from the beanbag trajectory in Figure 12.15 that an important aspect of collisions is not captured by the model: friction. The velocity perpendicular to the normal is the same before and after the collision. We would expect an object like a beanbag to scrub off a great deal of horizontal velocity as a result of the collision—in fact, it might come to a stop completely. The correct thing to do is to add in a perpendicular component to the impulse. However, correct handling of friction is, in general, a tricky business, and it remains at the forefront of real-time simulation research. Many current methods for calculating the horizontal impulse (especially for sliding contact) fall under the category of “completely fudged.”

In the previous example, we only had one “live” object and the other object was inert. This is a special case, and the equations could be simplified. (As we mentioned earlier, the mass of the projectile cancels itself out and is not needed.) In Exercise 9, we ask you to consider what would happen if Grant and Kari's collision were not perfectly inelastic; the full power of this law is needed in this case. We show how to handle collisions where the objects are free to rotate in Section 12.5.4.

We have been assuming thus far that the objects are in contact, but are not yet penetrating. This might not be the case, depending on the overall strategy used to resolve collisions. One technique is to attempt to reverse the simulation in time back to the point of contact. This can be difficult to do efficiently because there are frequently many, many collisions that happen at different times within a single time step. Furthermore, defining “exactly in contact” is difficult when using floating point math. Another strategy is to simply allow penetration, and apply the impulse to objects that are already penetrating. In this case, the impulse must do more than remove the relative velocity to prevent (further) penetration. The resulting relative velocity must be sufficiently large to separate the objects by the end of the time step, after it has been integrated into the position. In other words, the positions of the objects will be advanced at a rate according to the calculated velocities; after this update, the penetration needs to be resolved. Or at least it needs to be mostly resolved. There are some advantages to allowing some small penetration. All of these issues are a bit outside the realm of established principles and fall more under the heading of current research,17 and they will not be discussed here.

12.4.3The Dirac Delta

Before we leave linear dynamics and talk about rotational dynamics, let's mention briefly one bit of mathematical notation you might see, especially in the context of impulses. As we've said, many natural phenomena (such as momentum) do not change instantaneously in theory, but for practical purposes we treat them as changing instantaneously. Furthermore, it is often the case where a body of mathematical tools exists to handle continuous functions (or, equivalently, “signals”), and we wish to apply those tools to signals with discontinuities. There is a handy mathematical kludge that can be used to encode a discontinuity in a function such that it can be integrated. It is known as the Dirac delta, and is usually denoted with the lowercase letter delta, for example δ(a) .

The symbol δ(t) is a special sort of function, which is a spike, or impulse. Its value is zero everywhere except at t=0 , where it is infinite. But the actual values of the Dirac delta are not to be taken too literally—what is more important is that its integral (the “area” of this infinite spike) is equal to 1. The best way to think about the Dirac delta is as a box centered at 0 with width w and height 1 / w . (Other shapes may be chosen, but the important point is that the shape must have unit area.) The Dirac delta is defined as the limit of such a function, as the width approaches zero, and the height approaches infinity, all the while maintaining the unit area. We like the advice of Bracewell [2], which is to avoid using the term “function” when referring to special, uh, functions such as the Dirac delta, and instead use the word “symbol.” This is because whenever we see the Dirac delta symbol, the entire surrounding expression should be interpreted as a limit. We are considering the limit as the width approaches zero of some shape with unit area centered at the origin.

Armed with the Dirac delta, we can differentiate functions with discontinuities. For example, let's say the velocity of a baseball being struck by a bat at time t=2 is approximated by the discontinuous function

v(t)= {130  ft / s t<2,130  ft / s t2.

We can differentiate this expression by using the Dirac delta as


which can be read as “an impulse of magnitude 260 at 2.” Remember that the δ symbol is not an ordinary function, and so we interpret the above as “the limit of a total change in velocity of 260 ft/s that takes place over an interval of duration Δt surrounding the time t=2 , as Δt approaches zero.”

The Dirac delta comes up in a variety of contexts where tools from continuous math are applied to discontinuous signals. For example, in graphics, the screen-space image is a signal with inherent discontinuities, and we need to sample this signal and reconstruct it. The user's input via the controller is another signal that exhibits discontinuities. The Dirac delta and other related symbols (such as the ramp function and Heaviside's step function) are helpful in discussing and manipulating such signals.

12.5Rotational Dynamics

We are now ready to extend the ideas we have learned about particles to rigid bodies. Particles have position, but until now we have not concerned ourselves with orientation. Likewise, particles have mass, but until now we have not thought about the size or shape of a particle and how that mass was distributed. The key linear quantities and laws each have rotational analogs, and there is a certain beautiful correspondence between them. This correspondence is certainly pedagogically convenient and will be leveraged in our discussion. As we did for linear dynamics, we first define the basic kinematics quantities and consider those issues related to describing the rotation without worrying about the causes of the rotation. We then examine the rotational analogs to mass, force, and momentum, although we will discuss these topics in a different order.

You might notice that this section is surprisingly brief, both compared to our discussion of linear matters, and also similar presentations of other sources. There are two reasons for this. First, we spent considerable time in the previous chapter building up intuition about derivatives and linear dynamics, and these ideas need not be repeated here—though there will be some important differences concerning integration of angular displacement. Second, there are certain prerequisites that are usually bundled in this discussion in traditional physics books; in this book, it has been more appropriate to place these prerequisites elsewhere. You should make sure you have read and understood these prerequisites before reading the rest of this section. In particular, we use the cross product, which we covered in Section 2.12, and basic methods for describing rotation in three dimensions, which were the subject of Chapter 8.

12.5.1Rotational Kinematics

Chapter 11 was about linear kinematics: we considered a function p (t) that described the position of a particle as a function of time. We also considered its first and second derivatives, the velocity and acceleration functions, which we denoted v (t)= p˙ (t) and a (t)= p¨ (t) , respectively. The rotational analog of position is, of course, orientation. Several methods can be used to describe the orientation of a body. A considerable number of pages were spent explaining and comparing these methods in Chapter 8, and in this chapter we assume you are familiar with the basics. In a rigid body simulator, it's common to keep on hand redundant copies of the orientation in alternate formats. Typically, both a quaternion and rotation matrix are maintained. We will adopt a similar policy here with our notation. We let R (t) be the object-to-upright rotation matrix at time t ; it is the orientation of the body expressed in matrix form. We also use q (t) to refer to that same rotation as a quaternion. Although both functions express the same value, they are different “data types.”

The analog of linear velocity and acceleration are called angular velocity and angular acceleration. We denote them as ω ω (t) and α α (t) , respectively, and both of these quantities are 3D vectors, or infinitesimal exponential maps (see Section 8.4) if you will. We were able to define linear velocity as the time derivative of position, but things are a bit more complicated with orientation. In general, ω ω (t) is not the derivative of the orientation in any format (even exponential map). We have more to say on this when we look at what the derivatives of angular values really arein Section 12.6.4.

So our first order of business is to understand how to express and measure angular velocity. This is tricky, not just because rotation in 3D is more complicated than position, but also because there are two slightly different types of angular velocity. The first is known as spin angular velocity, and the second is orbital angular velocity. Spin angular velocity describes the rate of change of orientation of an object and is not affected by translation of the object. Orbital angular velocity is actually not concerned with orientation at all; instead, it measures the rate at which the position of an object traces out an orbit around some other point. We already introduced orbital angular velocity in Section 11.8.2, so if you skipped that section, now would be a good time to review it.

To see the relationship between spin angular velocity and orbital angular velocity, let's look at an example. Consider an object that is rotating about its center of mass c , which is fixed in space. To describe this rotation, we must specify two things. First, we describe the direction of the rotation; we choose to do this by naming n ^ , a unit vector parallel to the axis of rotation whose sign (in combination with the left hand rule) establishes a direction of positive rotation. Note that n ^ tells us only the direction of the axis; the position comes from our assumption that the axis passes through the center of mass c . The other element necessary to describe the rotation is, of course, the rate of rotation, which we measure in radians per unit time and denote by the scalar ω . Now, we can define the spin angular velocity of the rigid body by the angular velocity vector ω ω (note the boldface), which is simply the multiplication of the rotation rate with the axis:

ω ω =ω n ^ .

These ideas should be familiar to you, if you read Section 8.4, which talked about exponential maps, and Section 11.8.2, which discussed uniform circular velocity of a particle and defined orbital velocity. If so, then you can probably already see the connection between spin angular velocity and orbital angular velocity.

Spin and Orbital Angular Velocity
The spin angular velocity of a rigid body is equal to the orbital angular velocity of every point on the rigid body.

When talking about orbital angular velocity, we must be clear about what point o we are measuring the angular velocity relative to. We do not measure the orbital angular velocity relative to the center of mass c ! We measure the orbital angular velocity relative to the point that is actually being orbited, and only those points on the “equator” of the object are actually orbiting around c . Given any other arbitrary point, it will orbit a point o that lies on the axis of rotation, as shown in Figure 12.16.

Figure 12.16 The spin angular velocity of the robot is the same as the orbital velocity of every point on the robot, provided that we choose o carefully.

Now, the astute reader may have noticed some circularity in the definitions just given. We said that the spin angular velocity of the rigid body is equal to the orbital angular velocity of each and every point, provided that the orbital velocity is measured relative to the closest point on the axis of rotation. But how did we know the axis of rotation in the first place? The question is typically moot because, both in analytical kinematics equations and in a digital simulation in a computer, the angular velocity vector ω ω is simply one of the fundamental state variables that we track, so we do not need to infer it from the point velocities. Still, it is worth pointing out that this axis is uniquely determined (up to the reversal of signs). Remember that the axis of rotation is perpendicular to the velocity an orbiting particle. (We must measure the velocity of the particle relative to the center of mass of the rigid object, if the center of mass is moving.) There is only one direction that is simultaneously perpendicular to all the velocities of all the particles, and this direction is the axis of rotation.

We started with “a simple example” of an object rotating about an axis that passes through its center of mass, but, as it turns out, this is the general case, at least if we consider instantaneous velocity. The only simplification we made is to fix the center of mass, but, in general, an object can translate as well as rotate. It is somewhat surprising to realize, when you imagine an object tumbling through space, that it will always rotate about an axis passing through the center of mass (though the axis can be arbitrarily oriented). When an object receives a force that induces rotation (known as a torque, to be discussed shortly), the induced rotation will always occur about the center of mass. In fact, to rotate an object about an axis that does not pass through the center of mass requires continual application of some sort of constraint force. In the absence of any external torque (say, the constraint force is removed), the object will rotate about an axis passing through its center of mass, and the angular velocity will be constant—the axis of rotation will not change direction, and the rate of rotation will not change. We are getting a bit ahead of ourselves talking about torques, but we wanted to make it clear that this situation of angular velocity is, in fact, the only situation we need to understand.

Of course, if torques are acting on the object, then the axis and rate of rotation will change over time. This leads us to consider angular acceleration, which is a vector quantity that we denote α α . Angular velocity was not simply the derivative of orientation, as one might naïvely expect by analogy with the linear counterparts. However, the analogy does work for angular acceleration, which is the vector time derivative of angular velocity:

α α (t)= ω ω ˙ (t).

The analogy to the linear equation a (t)= v˙ (t) is clear.

12.5.22D Rotational Dynamics

Now that we've defined the simple kinematics quantities involved—which was primarily an exercise in notation and reusing the ideas developed elsewhere—let's consider the dynamics of rotation. We first simplify the situation to the case of rotation in the plane (or alternatively, we can think about this as fixing the axis of rotation). In this situation, the angular velocity and acceleration are scalar rather than vector quantities, since there is only one degree of freedom. After we develop some basic ideas in two dimensions in this section, we extend these ideas into three dimensions in Section 12.5.3.

Imagine a point with mass m that is attached to a rigid disk whose mass is neglected. The center of the disk is fixed at a pivot, and this constrains the mass to a circular path. Let r be the vector from the pivot to the mass. Thus the orbital radius of the mass is r= r . We draw a line on the disk outward from its center, and we assume that we can affix the mass to the disk at any distance r along this line. Note that the radius of the disk itself (being massless) is not relevant, so try to shut off your intuition that a really big disk would be hard to rotate. The only source of resistance to the rotation—the only source of inertia—is the point mass. We are neglecting the inertia of the disk.

Consider what happens when a force f is applied directly at m . According to Newton's second law, the mass wants to accelerate in the direction of f . However, any portion of f parallel to r will be repelled by a contact force from the disk and will have no effect on the mass. In contrast, the portion of f perpendicular to r , tangential to the orbit of the mass, will cause the point mass to accelerate. Let F denote the magnitude of f , and F denote the amount of f that is perpendicular r . This is depicted in Figure 12.17.

Figure 12.17 A disk is constrained to rotate about o . A mass m is attached to the disk at a radius r , and a force f is applied on the mass.

With a bit of trig, we can compute F from ϕ , which is the angle between f and r :

F / F=sin(πϕ),(πϕ  is the interior angle )F / F=sinπcosϕcosπsinϕ,(using \refeqlongch{cartesianspace_sin_diff_identity})F / F=(0)cosϕ(1)sinϕ,F=Fsinϕ.

By applying Newton's second law, we can compute the magnitude of the tangential acceleration as

a=F / m.

(Don't confuse tangential acceleration, which causes a change in the rate of rotation, with centripetal acceleration, which is created by contact force with the disk and maintains the orbital path.)

By definition, the linear tangential acceleration a = p ¨ is simultaneously an angular acceleration α= θ¨ about the pivot, and they are related by

α=a / r.

To understand where this comes from, remember from Section 11.8.1 the relationship between linear speed and angular velocity: v=s=rω .

Figure 12.18 Applying a force at an arbitrary point on the disk with lever arm l .

Now imagine that we keep the mass fixed at r , but instead of applying our force directly onto the mass, we push against a peg that sticks up out of the disk at some other location, at a distance l= l . The vector l goes from the fulcrum o to the point where the force is applied and is known as the lever arm. This is shown in Figure 12.18.

Allow us to clarify a point which is potentially confusing. Earlier, in Figure 12.17, the vectors r and l were the same, since we were applying the force directly onto the (one and only) point mass. But in general, mass is distributed around the disk, so there are many m 's and r 's. The portion of the applied force that is effective at rotating the disk is perpendicular to the lever arm, not the radius vector r , as you might infer from Figure 12.17.

Let's consider how changes to the lever arm affect the resulting accelerations. First, we note that if we apply the force anywhere on the circle with the same radius as the mass, meaning l=r , then the whole apparatus gains angular momentum, just as if we had pushed against the mass directly. In other words, the only thing that matters about l is the distance from the fulcrum l= l and the angle ϕ between the lever arm and the applied force. Rotating both the lever arm and the applied force does not change the resulting angular acceleration.

If the peg is closer to the fulcrum than the mass ( l<r ), then we must push harder in order to produce the same acceleration of the mass. If l>r , a smaller force will accomplish the job. Thus, increasing the lever arm l has a proportionate effect on the tangential acceleration a of the mass. This is the basic principle of mechanical advantage of a lever, which Archimedes discovered. But what effect does changing l have on α , the angular acceleration of the apparatus? It, too, is directly proportional: if we push on the disk at a point twice as far out, the angular acceleration is twice as much. This is clear from the relation α=a / r . If this seems too obvious to bother pointing out, then keep reading.

Let's summarize what we've found out. When a force is applied to an object, it has a tendency to rotate that object. This “cause” of angular acceleration is known as torque, which we denote by using the Greek letter tau:18 τ τ . Although the linear acceleration of a body as a result of an applied force does not depend on where the force is applied, the amount of torque that results from an applied force depends on how effectively the force is applied. The effectiveness of the force to create rotational acceleration—the magnitude of the torque—depends on several factors:

In two dimensions, we can state this succinctly by

Torque in two dimensions

The dimensions of torque are not the same as force. Torque has units of “force times length.” The SI unit for torque is the Newton meter. (This is dimensionally equivalent to the joule, but torque and energy are distinct concepts, and the joule is not really the proper unit to use fortorque.)

In might not be intuitively obvious that torque increases with the length of the lever arm. For example, your intuition might be inclined to tell you that it would be more difficult to push at an increased radius because you have to push faster just to keep up. If so, your intuition is wrong, but don't feel bad. Our experience with force is often via an everyday type of physical push like we might make with our hands against some object. But this is not necessarily a good example because the push must move faster and faster as the object accelerates in order to maintain contact. But the speed of some source of force has nothing to do with the magnitude of the force itself. So try replacing the physical push with either a gust of wind or a quick “thump” (an impulse). You can conduct this experiment on a door. If you blow on the door or whack it close to the hinge (shorter lever arm), your action won't cause the door to rotate as easily if you do the same thing nearer to side with the handle (longer lever arm). That's exactly why we put door handles on the side opposite the hinge: to make it easier to open the door!

The relationship between torque and force is an important one to understand. Any force applied to a body can produce both a linear acceleration and a torque. Of course, it is the net force and torque that determine the acceleration(s) of the body. Two key examples in Figure 12.19 illustrate this point. On the left, a force is acting along a line that passes through the center of mass, resulting in no torque. In this case, sinϕ=0 since the line of action of the force is parallel to the lever arm. The right side of Figure 12.19 shows a different extreme case: two forces with equal magnitudes but opposite directions are acting on opposite lever arms. A pair of forces coordinated like this are known as a couple, and they result in a net torque, but zero net linear force. When you turn a bolt with a wrench, what you are really doing is supplying two or more contact forces. The direction and lever arms of these contact forces are coordinated in a circular pattern to produce torque, but (nearly) zero net linear force.

Figure 12.19 On the left, the line of action passes through the center of mass, resulting in linear acceleration but no torque. On the right, a couple produces a torque but no linear acceleration.

In a digital simulation, torques can come from multiple sources. One common source is an applied (linear) force at some lever arm, with collisions being the most common source of torques of all. An impulsive force applied to an object can result in an angular impulse (also known as impulsive torque). Similar to a linear impulse, an angular impulse is an instantaneous change in angular momentum, and we can think of this as the result of a large torque acting for a small duration. We might also instruct the physics engine to automatically apply torques (perhaps limited to some maximum magnitude) on an object in order to enforce some angular constraint. Angular springs and motors are examples of this. Finally, we might have a reason to add a torque at will to any object without there being any corresponding linear force.

Back to our thought experiment with the mass attached to the rotating disk. What if we fix the lever arm l , and instead vary r , the radial distance between the mass and the pivot? The same principle of the lever is at work, but in reverse. The force (and therefore the tangential acceleration a ) experienced by the mass will be inversely proportional to r . Said another way, the effective inertia of the mass—its resistance to linear acceleration—is proportional to r . But what about the ability of the apparatus to resist angular acceleration? How does its moment of inertia change as we vary r ? The moment of inertia is not proportional to r , it is proportional to r2 ! To see why, consider that if we increase l and r by the same factor, then the tangential acceleration a experienced by the mass is unchanged. However, at this increased radius, the same tangential acceleration now corresponds to a reduced angular acceleration, due to the relation α=a / r .

In summary, the moment of inertia of an object, which must be measured relative to some particular pivot (in this case, it's the fixed pivot point, but for a rigid body we usually measure it relative to its center of mass), quantifies the degree to which the object will resist angular acceleration about that pivot. The moment of inertia J of a point mass is proportional to its mass and proportional to the square of the distance from the mass to the pivot.

Moment of Inertia of a Point Mass in the Plane

Now imagine that the disk in our thought experiment has multiple masses placed on it. Each of these masses contributes to the disk's resistance to rotation, and their contribution is the same, regardless of where any force is applied. To compute the moment of inertia of an arbitrary rigid body, we break up the object into “mass elements” such that for each element we know the mass mi and radial distance to the center of mass ri . We then sum up the moments of inertia of each individual mass element:

Moment of inertia of a rigid body

Let's work through a few instructive examples.

Figure 12.20 Distribution of mass can affect the moment of inertia. Each of the examples above has the same total mass.

Consider the four disks in Figure 12.20. Since each disk has three masses, we start by expanding the sum in Equation (12.25) to J=m1 r1 2+m2 r2 2+m3 r3 2 :

  1. (a) J=232+222+212=18+8+2=28 ;
  2. (b) J=232+232+232=18+18+18=54 ;
  3. (c) J=332+222+112=27+8+1=36 ;
  4. (d) J=132+222+312=9+8+3=20 .

Aside from the rote practice this example provides, it highlights a crucial fact: the distribution of mass within the object can have a profound effect on the moment of inertia. Notice the widely differing moments of inertia, despite the fact that each of these disks has a total mass of 6. Compare this to linear inertia, where shifting the mass around will not make the object any easier or harder to accelerate. The only thing that matters for linear acceleration is the total mass. Furthermore, in three dimensions, although linear mass can still be quantified with a scalar, the moment of inertia cannot be described by a single number, due to its dependence on the distribution of mass.

When we take the limit as the number of mass elements reaches infinity, Equation (12.25) turns into an integral. Luckily, formulas for the moments of inertia for many common shapes, such as spheres, cylinders, rings, and so forth, can be found on the Internet.

Newton's second law, F=ma , has a straightforward rotational equivalent.

Rotational Equivalent of Newton's Second Law

For rotation in a plane, all of the variables in Equation (12.26) are scalars. In three dimensions, however, τ and α become vector quantities, and J becomes a matrix. Section 12.5.3 discusses this.

We've considered torque, the rotational analog to linear force. Now let's turn our attention to momentum. Remember that linear momentum is the “quantity of motion” contained in an object. Its analog, angular momentum, has a similar interpretation. Intuitively, angular momentum describes how hard it will be to stop the rotation of the object. If the angular momentum is large, then the magnitude of the applied torque, or the duration for which it is applied, or both, must be large.

In our discussion of linear momentum, we encountered two ways of thinking about momentum. The first was to interpret momentum in an “instantaneous respect” as the product of mass and velocity by using P=mv . The rotational equivalent is shown in Equation (12.27).

Spin Angular Momentum

Angular momentum ( L ) is the product of the moment of inertia J and angular velocity ( ω ):


Alternatively, we can compute the angular momentum for an individual point mass directly from its linear momentum by

Relationship between linear and angular momentum

where P is the linear momentum. The purpose of the sinϕ term is the same as in the computation of torque: it isolates the tangential motion. If the trajectory is known to be orbital, this term can be omitted since it will always be unity. Notice that since Equation (12.28) contains a factor r , it really is only for orbital angular momentum. Equation (12.27) can also be used for orbital angular momentum, provided that J and ω are both measured relative to the same pivot, but Equation (12.27) is probably more appropriate for spin angular momentum of a rigid body, where J measures the moment of inertia of the entire body. In any case, the spin angular momentum of a rigid body can be computed by breaking the object into mass elements and taking the sum of the orbital angular momenta of these elements. Here are several ways in which the sum could be accomplished:

Spin angular momentum of a rigid body
L=ωJ=ω (iJi) =iJiω=i( ri 2mi)ω=irimi(riω)=irimivi=iriPi=iLi.

Here the subscripted variables refer to values for a particular particle. Note that we dropped the sinϕ term under the assumption that each particle is in an orbital trajectory.

The second interpretation of linear momentum that we discussed is that of momentum as the time integral of force. When we apply force over time, linear momentum is accumulated. A similar relationship exists between angular momentum and torque. As torque is applied over time, it builds up angular momentum; equivalently, torque is equal to the rate of change (derivative) of angular momentum. As with linear momentum, this can be interpreted as a conservation law.

Torque and the Conservation of Angular Momentum
L=τ dt,τ= dL dt .

In the absence of external torque, angular momentum is conserved.

12.5.33D Rotational Dynamics

Now let's extend the basic principles developed in Section 12.5.2 into three dimensions. First, let's review the 3D rotational kinematics quantities. The single angle θ is replaced by a rotation tensor of some kind, with a rotation matrix R or a quaternion q being the most common methods of describing orientation in general rigid body simulations. The angular velocity ω and acceleration α become vector quantities and get bolded as ω ω and α α , respectively.

To extend the dynamics principles into three dimensions, we start with torque. Not surprisingly, torque becomes a vector quantity denoted τ τ , and the direction of this vector indicates the axis about which the torque is tending to induce rotation. (Later we consider what happens if the object is already rotating about a different axis.) The formula for computing the torque for an applied force f and lever arm l is actually simpler in 3D than the corresponding 2D formula!

Torque in Three Dimensions
(12.29) τ τ = l × f .

Compare Equation (12.29) to τ=Flsinϕ (Equation (12.24)), and notice that the cross product has the magnitude and sinϕ terms built in.

Angular momentum likewise becomes a vector L , with a similar formula for its relation to the linear quantity:

Orbital angular momentum of a particle in three dimensions with radial vector r
L = r × P .

Compare this to Equation (12.28).

A reader who is paying attention might note that Equation (12.28) is only one of two equations we gave for angular momentum in the plane—the one we deemed to be more appropriate for orbital angular velocity of a particle—and wonder about the other formula, Equation (12.27), which was more appropriate for spin angular velocity. That formula was L=Jω , and to get its three-dimensional equivalent, we must understand how to extend J , the moment of inertia, into three dimensions. Luckily, the link between the two momentum equations is an excellent way to get this understanding. Let's start by expanding L = r × P , with the goal of ending up with something that looks like L=Jω :

L = r × P = r ×(m v )=(m r )× v =(m r )×(ω× r )=m [ rx ry rz ] × [ ωyrzωzry ωzrxωxrz ωxryωyrx ] =m [ ry(ωxryωyrx)rz(ωzrxωxrz) rz(ωyrzωzry)rx(ωxryωyrx) rx(ωzrxωxrz)ry(ωyrzωzry) ] =m [ ryωxryryωyrxrzωzrx+rzωxrz rzωyrzrzωzryrxωxry+rxωyrx rxωzrxrxωxrzryωyrz+ryωzry ] =m [ (ry2+rz2)ωxryrxωyrzrxωz rxryωx+(rz2+rx2)ωyrzryωz rxrzωxryrzωy+(rx2+ry2)ωz ] = (m [ry2+rz2ryrxrzrxrxryrz2+rx2rzryrxrzryrzrx2+ry2] ) [ ωx ωy ωz ] .

The key point is in the last line, which bears a striking resemblance to L=Jω . In fact, the quantity in parenthesis is the three-dimensional moment of inertia.

Inertia Tensor
The inertia tensor of a mass m with radial vector r is
(12.30) J =m [ry2+rz2ryrxrzrxrxryrz2+rx2rzryrxrzryrzrx2+ry2] .

Notice that this quantity is a matrix, not a vector. In recognition of this, in three dimensions we sometimes refer to the moment of inertia as the inertia tensor. This mathematical artifact is a result of the physical fact that an object's resistance to rotational acceleration is anisotropic: it can be easier to rotate an object about one axis compared to another. For example, compare the torque required to spin a piece of rebar around like a helicopter versus rolling it about its lengthwise axis.

Notice that J is a symmetric matrix. One trivial (but thankful) consequence of this is that we can be sloppy with row and column vectors, while ordinarily we must be very careful in order to avoid transposed results.19 Before we look at some other properties of J , let's finish extending the basic formulas in three dimensions with perhaps the most important one.

In the plane, the rotational equivalent of Newton's second law, F=ma , is τ=Jα . Extending this into three dimensions is straightforward.

3D Rotational Analog of Newton's Second Law
τ τ = α α J .

As we've said before, in computer simulations it's often the case that the force and mass are known, and we compute the acceleration using a=F / m . A similar situation exists for rotational dynamics, where division by m is replaced with multiplication by J 1 :

α α = τ τ J 1 .

As it turns out, the inverse inertia tensor is needed more frequently in digital simulations than is J , and it is usually precomputed and stored.

Equation (12.30) tells us how to compute the inertia tensor for a point mass, but what about more complicated shapes? In a manner similar to how we computed the center of mass, we can imagine breaking up a compound object into a large number of mass elements and taking the sum of their individual moments of inertia. Taking the limit as the volume of the largest element approaches zero, this sum becomes a multidimensional integral. Such integrals are typically difficult or impossible to solve analytically, except for abstract primitives such as boxes, disks, cylinders, spheres, cones, and the like. Fortunately, such primitives arise commonly in practice and can make adequate approximations. Even more fortunate for us is the fact that the hard work of solving the integral has already been done for a large variety of primitives. For such primitives, the best method for obtaining the moment of inertia is to look up the formula in a table. (At the time of this writing, such a table can be found on under “List of moment of inertia tensors.”)

More complicated objects are typically approximated by breaking down the object into primitives with known formulas, calculating their moments of inertia individually, and then summing together the results. There is just one complication. The formulas for these primitives assume the origin of the coordinate space is at some auspicious location, such as at the center of the sphere. But imagine we are computing the moment of inertia of a human body and approximating the head by a sphere. Odds are low that we chose to place the origin in the center of the head. Luckily the parallel axis theorem tells us how the moment of inertia changes if we translate a mass.

Assume that J cm is the inertia tensor of some object with mass m , measured relative to its center of mass. The inertia tensor J of the mass measured relative to some arbitrary pivot that has a displacement [x,y,z] from this center of mass is given by Equation (12.31).

Parallel Axis Theorem
(12.31) J = J cm +m [y2+z2xyxzxyx2+z2yzxzyzx2+y2] .

12.5.4Collision Response with Rotations

Now let us complete the collision response calculation we started in Section 12.4.2. At that time we did not consider rotational effects, but now we know better. We continue, following Hecker [8].

Remember the basic strategy:

  1. Compute the relative velocities at the point of contact.
  2. Project the relative velocities onto the surface normal. This is the velocity that must be counteracted in order to prevent (further) penetration.
  3. Compute k , the magnitude of an impulse, such that when we apply the impulse to both objects (in opposite directions) parallel to the surface normal, the post-collision velocities, measured along the surface normal, have the desired magnitude according to some collision law. This discussion will be based upon Newton's collision law and the coefficient of restitution e .
  4. Apply the impulse k n to one object and k n to the other.

Dealing with objects that can rotate adds a few complications. First, we earlier referred to “the” velocity of an object. But when an object is rotating, the different points on the object have different linear velocities. The velocity we need is not the velocity of the object's center of mass, but rather the velocity at the point of contact. So we must extend our velocity calculation to account for the angular velocity. Likewise, our prediction of the post-impulse velocities at the points of impact must also take into consideration rotational effects. Application of an impulse at the point of contact will create an angular impulse, which will change the rate of rotation. In general, when objects are free to rotate, a smaller impulse will suffice to resolve the collision, since the impulse has two ways by which to reduce the point velocities. The change in angular velocity will cause the points of contact to move away from each other faster than their centers of mass do. Indeed, the centers of mass may still be moving towards each other after the collision.

In Section 12.4.2, we started with the equation

v rel n =e v rel n

and then expanded the math and solved for k , the magnitude of the impulse. (It's hidden in the left hand side.) The same strategy works here, only we need to derive new expressions for the point velocities before and after the impulse that take into consideration the rotational effects. First, let's check the notation. We use r i to denote the position of the point of impact on object i relative to its center of mass, ω ω i for the angular velocity of the object, mi for the mass, and J i for the inertia tensor. For linear velocity, we need to introduce some new notation to distinguish between the linear velocities at the point of contact, which we denote as u i , and the linear velocities of the center of mass, denoted v i . As before, primes on the quantities refer to their values after the collision.

With this notation, we compute the point velocity of each object by adding the velocity due to the motion of the center of mass, plus that portion caused by the rotation, according to Equation (11.31):

Computing the point velocities
u 1= v 1+ ω ω 1× r 1, u 2= v 2+ ω ω 2× r 2.

The velocities after the collision depend on the change in linear velocity of the center of mass, and also the change in angular velocity. These are computed by

Post-impulse linear and angular velocities of the bodies
v 1= v 1k n / m1, v 2= v 2+k n / m2, ω ω 1= ω ω 1( r 1×k n ) J 1 1 , ω ω 2= ω ω 2+( r 2×k n ) J 2 1 ,

where the sign conventions are determined by our arbitrary choice to have the collision normal n point from the first object to the second. Combining the equations above, we get the post-impulse point velocities:

u 1= v 1+ ω ω 1× r 1= v 1k n / m1+( ω ω 1( r 1×k n ) J 1 1 )× r 1= v 1k n / m1+ ω ω 1× r 1k(( r 1× n ) J 1 1 )× r 1=( v 1+ ω ω 1× r 1)k n / m1k(( r 1× n ) J 1 1 )× r 1= u 1k n / m1k(( r 1× n ) J 1 1 )× r 1, u 2= u 2+k n / m2+k(( r 2× n ) J 2 1 )× r 2.
Post-impulse velocities at the point of contact

Defining u rel = u 1 u 2 as the relative point velocity, we are now ready to grind through the algebra:

e u rel n = u rel n ,e u rel n =( u 1 u 2) n ,e u rel n =[ ( u 1k n / m1k(( r 1× n ) J 1 1 )× r 1)( u 2+k n / m2+k(( r 2× n ) J 2 1 )× r 2) ] n ,e u rel n =[ ( u 1 u 2)k n / m1k n / m2k(( r 1× n ) J 1 1 )× r 1)k(( r 2× n ) J 2 1 )× r 2) ] n ,e u rel n = u rel n k[ (1 / m1+1 / m2) n +(( r 1× n ) J 1 1 )× r 1)+(( r 2× n ) J 2 1 )× r 2) ] n ,(e + 1) u rel n =k[ (1 / m1+1 / m2) n +(( r 1 × n ) J 1 1 )× r 1)+(( r 2 × n ) J 2 1 )× r 2) ] n .

With one more step, we have the formula we're seeking.

Collision Response with Rotation
The magnitude of the collision impulse can be calculated from the relative point velocity, masses, moments of inertia, surface normal, and coefficient of restitution, by
k= (e + 1) u rel n [(1 / m1+1 / m2) n +(( r 1 × n ) J 1 1 )× r 1)+(( r 2 × n ) J 2 1 )× r 2)] n .

Equation (12.32) assumes that all vectors are measured in the same coordinate space and that the inverse inertia tensors operate on vectors in that same space. However, the inverse inertia tensor is a constant only in body space, and the same matrix in world space may not be updated continually as the object rotates. Our convention is to describe the orientation of the object by using R , a rotation matrix that transforms row vectors on the left from body space to upright space. Under these assumptions, in Equation (12.32) we would replace J 1 with R T J 1 R .

12.6Real-Time Rigid Body Simulators

This section presents an overview of real-time rigid body simulators such as PhysX, Havok, Bullet Physics, and the Open Dynamics Engine. Few game programmers will work directly on the physics engine, and certainly far fewer will write one from scratch. Most of us just need to know how to use the thing. Luckily, in this regard the physics engines previously listed have much in common. However, a physics engine is like many other programming tools: even if you don't intend to write one, you can use it more effectively if you have a basic understanding of how things work under the hood.

We regret that we won't be able to go into great detail, for a few reasons. First, any attempt to describe “how a physics engine works” is complicated by the fact that currently there is still great diversity and rapid innovation in the field. Second, the math quickly becomes more advanced than is appropriate for this introductory book. Frankly, your authors simply do not have enough expertise to succinctly summarize the state of the art from top to bottom. However, from a user's perspective, there are many similarities between physics engines that can be covered in an introductory manner, so we start with an overview of a typical physics engine interface. There are also a few choice mathematics that are discussed near the end of this chapter.

12.6.1Physics Engine State Variables

An old computer science adage attributed to Fred Brooks says, “Show me your flow charts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowcharts; they'll be obvious.” Despite the image of a banner printed on Z-fold paper using The Print Shop that is evoked by the arcane terminology, the essence of the message is still true today: to write or understand software, a good place to start is a description of the data that are being operated on. From the perspective of the user of a physics engine, there are three main types of data objects within a rigid body simulator: the dynamics bodies, collision geometry data, and constraints. Let's examine each of these in turn.

Dynamics body state. Perhaps the most fundamental type of data object within a real-time rigid-body simulator is the dynamics body. You can think of the dynamics body as the “soul” of a rigid body: it tells it where to go, but it has no outward appearance, so you can see it only indirectly via the effects it has. The collision geometry (to be discussed later) is what gives a rigid body its “earthly form,” meaning its shape. The part of a rigid body that we see is usually some sort of graphical model, which doesn't have anything to do with the physics engine and is not discussed here.

At this point, it's probably important to discuss the relationship between a dynamics body and an “object” in the nontechnical (and nonprogramming) sense of the word. A simple rigid object, such as the ubiquitous video game crates Old Man Murray was so fond of reporting sighting, can be simulated by using a single dynamics body. A more complicated object with moving parts, such as a car or human body, is not a rigid body and thus cannot be simulated with a single dynamics body. Instead, the object must be broken down into rigid parts, and then the dynamics bodies corresponding to those parts connected via joint constraints, to be discussed later. Of course, the graphical representation for such a compound object like this need not be “rigid,” but within the physics simulation, each dynamics body is a rigid body.

Another way that a dynamics body is like a soul is that it's easier to just list its properties rather that attempt a precise definition. So let's enumerate the variables that comprise a dynamics body. We classify these variables by their life cycle, meaning when those variables are initialized and how often their values change. Certain properties are (mostly) constant, some change continuously over the life of the object, and some are working variables, coming into existence (or reset) at the start of a simulation time step and being thrown away at the end of the time step.

The first class of properties are those that are initialized when the body is instantiated by the application, and typically (but not necessarily) remain constant during the simulation.

The second class of variables that define the state of the dynamics body are those that evolve over time, and contain some “history” in them and must be carried forward from one frame to the next. If we need to save the complete state of the simulation and resume it later (for example, in a save game), these variables cannot be derived from any other source and must be serialized:

This list reflects a choice to make velocities the primary state variables, in which case the momentums are easily derived quantities. An alternate strategy is to use the momentum as the primary state variable and velocity as the derived quantity. The former approach has an advantage in dealing with kinematically controlled objects, whose inertia (and therefore momentum) is considered infinite. The latter can more elegantly deal with the situation in which the mass changes over time, since conservation of momentum is automatically enforced.

Finally, each dynamics body has certain properties that are stored in working variables. These quantities change over time but do not inherently have “history” integrated into them. These sorts of variables are often reset at some point within the simulation step. If we wanted to save the state of the simulation and resume it later, it is usually not necessary20 to include these variables in the state description:

We use the word “accumulators” here to reflect what often happens in practice. These values are often reset to zero at some point within the frame, and then different sources of external forces are polled, and the net result stored in these variables.

Listing 12.2 is a structure that summarizes the essentials of a dynamics body state and hints at how it might be implemented in C++. These variable names are used in the pseudocode later in this chapter. You should compare this to the corresponding class in a real physics engine implementation to see what additional data that engine chose to keep on hand, or what different choices were made.

struct DynamicsBody {

    // Primary quantities

    // Position of center of mass
    Vector3 pos;

    // Orientation in quaternion format
    Quaternion rotQuat;

    // Mass
    float mass;

    // Moment of inertia, expressed in body space.
    Matrix3x3 jBody;

    // Velocities
    Vector3 linVel;
    Vector3 angVel;

    // Derived quantities

    // Orientation, in matrix form
    Matrix3x3 rotMat;

    // Inverse mass and inertia tensor
    float oneOverMass;
    Matrix3x3 invJBody;

    // Temporary / working variables

    // Force accumulators.  Cleared to zero each time step
    Vector3 force;
    Vector3 torque;
    Vector3 linImpulse;
    Vector3 angImpulse;

    // Collision and constraint lists
    vector userConstraints;
    vector collisionShapes;

Collision Geometry. If the dynamics body is the soul of a rigid object, the collision geometry is its earthly manifestation. The collision geometry is used to define the shape of dynamics bodies, and also of other “soulless” or static objects. Typically, a physics engine will support a number of different primitives. In order of complexity, these are

The simpler shapes have advantages in both speed and stability, which is why it's often best to build up a concave or complicated shape from multiple primitives. These primitives are allowed to penetrate each other; only their union matters, since two geometry objects attached to the same dynamics body will not collide with each other. Indeed, it's important for the physics engine to provide flexibility in deciding which pairs of geometry objects collide; for example, on a character, the thigh part might not collide with the connected torso and shin parts, but it might collide against every other part in the body. Or, under the auspices of the first law of video game physics, we might create a barrier that enemies can pass through but the player character cannot.

A collision geometry object either will be associated with a single dynamics body, to which it has a fixed relative position and orientation, or will not be associated with any dynamics body and is part of the static “world.”

Constraints. The third and final main type of object within a rigid body simulator is a constraint. Constraints are used to enforce relationships between pairs of rigid bodies, or between a rigid body and the world. Applications can create two types of user constraints: joints and motors. A third type of constraint is the contact constraint, which is involved in collision response.

User constraints are the “regular” kind of constraints that are specified by the application in order to maintain some desired relationship. The more common and easily understood type of constraint maintains a spatial relationship between two parts and is known as a joint. Some examples of the types of joints that come built-in to most physics engines are the following.

As an example, in a human skeleton, each “bone” may be simulated as a separate