Chapter 1. Basic Concepts

As a warm-up, this chapter will cover the most basic of the principles that will be used and referenced throughout the remainder of this book. First, we’ll introduce Newton’s laws of motion, which are very important in the study of mechanics. Then we’ll discuss units and measures, where we’ll explain the importance of keeping track of units in your calculations. You’ll also have a look at the units associated with various physical quantities that you’ll be studying. After discussing units, we’ll define our general coordinate system, which will serve as our standard frame of reference. Then we’ll explain the concepts of mass, center of mass, and moment of inertia, and show you how to calculate these quantities for a collection, or combination, of masses. Finally, we’ll discuss Newton’s second law of motion in greater detail, take a quick look at vectors, and briefly discuss relativistic time.

Newton’s Laws of Motion

In the late 1600s (around 1687), Sir Isaac Newton put forth his philosophies on mechanics in his Philosophiae Naturalis Principia Mathematica. In this work Newton stated the now-famous laws of motion, which are summarized here:

Law I

A body tends to remain at rest or continue to move in a straight line at constant velocity unless acted upon by an external force. This is the so-called concept of inertia.

Law II

The acceleration of a body is proportional to the resultant force acting on the body, and this acceleration is in the same direction as the resultant force.

Law III

For every force acting on a body (action) there is an equal and opposite reacting force (reaction), where the reaction is collinear to the acting force.

These laws form the basis for much of the analysis in the field of mechanics. Of particular interest to us in the study of dynamics is the second law, which is written:

F = ma

where F is the resultant force acting on the body, m is the mass of the body, and a is the linear acceleration of the body’s center of gravity. We’ll discuss this second law in greater detail later in this chapter, but before that there are some more fundamental issues that we must address.

Units and Measures

Over years of teaching various engineering courses, we’ve observed that one of the most common mistakes students make when performing calculations is using the wrong units for a quantity, thus failing to maintain consistent units and producing some pretty wacky answers. For example, in the field of ship performance, the most commonly misused unit is that for speed: people forget to convert speed in knots to speed in meters per second (m/s) or feet per second (ft/s). One knot is equal to 0.514 m/s, and considering that many quantities of interest in this field are proportional to speed squared, this mistake could result in answers that are as much as 185% off target! So, if some of your results look suspicious later on, the first thing you need to do is go back to your formulas and check their dimensional consistency.

To check dimensional consistency, you must take a closer look at your units of measure and consider their component dimensions. We are not talking about 2D or 3D type dimensions here, but rather the basic measurable dimensions that will make up various derived units for the physical quantities that we will be using. These basic dimensions are mass, length, and time.

It is important for you to be aware of these dimensions, as well as the combinations of these dimensions that make up the other derived units, so that you can ensure dimensional consistency in your calculations. For example, you know that the weight of an object is measured in units of force, which can be broken down into component dimensions like so:

F = (M) (L/T2)

where M is mass, L is length, and T is time. Does this look familiar? Well, if you consider that the component units for acceleration are (L/T2) and let a be the symbol for acceleration and m be the symbol for the mass of an object, you get:

F = ma

which is the famous expression of Newton’s second law of motion. We will take a closer look at this equation later.

By no means did we just derive this famous formula. What we did was check its dimensional consistency (albeit in reverse), and all that means is that any formulas you develop to represent a force acting on a body had better come out to a consistent set of units in the form (M) (L/T2). This may seem trivial at the moment; however, when you start looking at more complicated formulas for the forces acting on a body, you’ll want to be able to break down these formulas into their component dimensions so you can check their dimensional consistency. Later we will use actual units, from the SI (le Système international d’unités, or International System of Units) for our physical quantities. Of course, there are other unit systems, but unless you want to show these values to your gamers, it really does not matter which system you use in your games. Again, what is important is consistency.

To help clarify this point, consider the formula for the friction drag on a body moving through a fluid, such as water:

Rf = 1/2 ρ V2 S Cf

In this formula, Rf represents resistance (a force) due to friction, ρ is the density of water, V is the speed of the moving body, S is the submerged surface area of the body, and Cf is an empirical (experimentally determined) drag coefficient for the body. Now rewriting this formula in terms of basic dimensions instead of variables will show that the dimensions on the left side of the formula match exactly the dimensions on the right side. Since Rf is a force, its basic dimensions are of the form:

(M) (L/T2)

as discussed earlier, which implies that the dimensions of all the terms on the right side of the equation, when combined, must yield an equivalent form. Considering the basic units for density, speed, and surface area:

  • Density: (M)/(L3)

  • Speed: (L)/(T)

  • Area: (L2)

and combining these dimensions for the terms, ρ V2 S, as follows:

[(M)/(L3)] [(L)/(T)]2 [L2]

and collecting the dimensions in the numerator and denominator yields the following form:

(M L2 L2) / (L3 T2)

Canceling dimensions that appear in both the numerator and denominator yields:

M (L/T2)

which is consistent with the form shown earlier for resistance, Rf. This exercise also reveals that the empirical term, Cf, for the coefficient of friction must be nondimensional—that is, it is a constant number with no units.

With that, let’s take a look at some more common physical quantities that you will be using along with their corresponding symbols, component dimensions, and units in both the SI and English systems. This information is summarized in Table 1-1.

Table 1-1. Common physical quantities and units

Quantity

Symbol

Dimensions

Units, SI

Units, English

Acceleration, linear

A

L/T2

m/s2

ft/s2

Acceleration, angular

α

radian/T2

radian/s2

radian/s2

Density

ρ

M/L3

kg/m3

slug/ft3

Force

F

M (L/T2)

newton, N

pound, lbs

Kinematic viscosity

ν

L2/T

m2/s

ft2/s

Length

L (or x, y, z)

L

meters, m

feet, ft

Mass

m

M

kilogram, kg

slug

Moment (torque)

M[a]

M (L2/T2)

N-m

ft-lbs

Mass Moment of Inertia

I

M L2

kg-m2

lbs-ft-s2

Pressure

P

M/(L T2)

N/m2

lbs/ft2

Time

T

T

seconds, s

seconds, s

Velocity, linear

V

L/T

m/s

ft/s

Velocity, angular

ω

radian/T

radian/s

radian/s

Viscosity

µ

M/(L T)

N s/m2

lbs • s/ft2

[a] In general, we will use a capital M to represent a moment (torque) acting on a body and a lowercase m to represent the mass of a body. If we’re referring to the basic dimension of mass in a general sense—that is, referring to the dimensional components of derived units of measure—we’ll use a capital M. Usually, the meanings of these symbols will be obvious based on the context in which they are used; however, we will specify their meanings in cases where ambiguity may exist.

Coordinate System

Throughout this book we will refer to a standard, right-handed Cartesian coordinate system when specifying positions in 2D or 3D space. In two dimensions we will use the coordinate system shown in Figure 1-1(a), where rotations are measured positive counterclockwise.

Right-handed coordinate system
Figure 1-1. Right-handed coordinate system

In three dimensions we will use the coordinate system shown in Figure 1-1(b), where rotations about the x-axis are positive from positive y to positive z, rotations about the y-axis are positive from positive z to positive x, and rotations about the z-axis are positive from positive x to positive y.

Vectors

Let us take you back for a moment to your high school math class and review the concept of vectors. Essentially, a vector is a quantity that has both magnitude as well as direction. Recall that a scalar, unlike a vector, has only magnitude and no direction. In mechanics, quantities such as force, velocity, acceleration, and momentum are vectors, and you must consider both their magnitude and direction. Quantities such as distance, density, viscosity, and the like are scalars.

With regard to notation, we’ll use boldface type to indicate a vector quantity, such as force, F. When referring to the magnitude only of a vector quantity, we’ll use standard type. For example, the magnitude of the vector force, F, is F with components along the coordinate axes, Fx, Fy, and Fz. In the code samples throughout the book, we’ll use the * (asterisk) to indicate vector dot product, or scalar product, operations depending on the context, and we’ll use the ^ (caret) to indicate vector cross product.

Because we will be using vectors throughout this book, it is important that you refresh your memory on the basic vector operations, such as vector addition, dot product, and cross product, among others. For your convenience (so you don’t have to drag out that old math book), we’ve included a summary of the basic vector operations in Appendix A. This appendix provides code for a Vector class that contains all the important vector math functionality. Further, we explain how to use specific vector operations—such as the dot-product and cross-product operations—to perform some common and useful, calculations. For example, in dynamics you’ll often have to find a vector perpendicular, or normal, to a plane or contacting surface; you use the cross-product operation for this task. Another common calculation involves finding the shortest distance from a point to a plane in space; you use the dot-product operation here. Both of these tasks are described in Appendix A, which we encourage you to review before delving too deeply into the example code presented throughout the remainder of this book.

Derivatives and Integrals

If you’re not familiar with calculus, or The Calculus, don’t let the use of derivatives and integrals in this text worry you. While we’ll write equations using derivatives and integrals, we’ll show you explicitly how to deal with them computationally throughout this book. Without going into a dissertation on all the properties and applications of derivatives and integrals, let’s touch on their physical significance as they relate to the material we’ll cover.

You can think of a derivative as the rate of change in one variable with respect to another variable, or in other words, derivatives tells you how fast one variable changes as some other variable changes. Take speed, for example. A car travels at a certain speed covering some distance in a certain period of time. Its speed, on average, is the distance traveled over a specific time interval. If it travels a distance of 60 kilometers in one hour, then its average speed is 60 kilometers an hour. When we’re doing simulations, the ones you’ll see later in this book, we’re interested in what the car is doing over very short time intervals. As the time interval gets really small and we consider the distance traveled over that very short period of time, we’re looking at instantaneous speed. We usually write such relations using symbols like the following:

|v| = ds/dt

where v is the speed, ds is a small distance (a differential distance), and dt is a small, differential, period of time. In reality, for our simulations, we’ll never deal with infinitely small numbers; we’ll use small numbers, such as time intervals of 1 millisecond, but not infinitely small numbers.

For our purposes, you can think of integrals as the reverse, or the inverse, of derivatives; integration is the inverse of differentiation. The symbol ∫ represents integration. You can think of integration as a process of adding up a bunch of infinitely small chunks of some variable. Here again, we are not going to deal with infinitely small pieces of anything, but instead will consider small, discrete parcels of some variable—for example, a small, discrete amount of time, area, or mass. In these cases, we’ll use the ∑ symbol instead of the integration symbol. Consider a loaf of bread that’s sliced into uniformly thick slices along its whole length. If you wanted to compute the volume of that loaf of bread, you can approximate it by starting at one end and computing the volume of the first slice, approximating its volume as though it were a very short, square cylinder; then moving on to the second slice, estimating its volume and adding that to the volume of the first slice; and then moving on to the third, and fourth, and so on, aggregating the volume of the loaf as you move toward the other end. Integration applies this technique to infinitely thin slices of volume to compute the volume of any arbitrary shape. The same techniques apply to other computations—for example, computing areas, inertias, masses, and so on, and even aggregating distance traveled over successive small slices of time, as you’ll see later. In fact, this latter application is the inverse of the derivative of distance with respect to time, which gives speed. Using integration and differentiation in this way allows you to work back and forth when computing speed, acceleration, and distance traveled, as you’ll see shortly. In fact, we’ll use these concepts heavily throughout the rest of this book.

Mass, Center of Mass, and Moment of Inertia

The properties of a body—mass, center of mass, and moment of inertia, collectively called mass properties—are absolutely crucial to the study of mechanics, as the linear and angular[5] motion of a body and a body’s response to a given force are functions of these mass properties. Thus, in order to accurately model a body in motion, you need to know or be capable of calculating these mass properties. Let’s look at a few definitions first.

In general, people think of mass as a measure of the amount of matter in a body. For our purposes in the study of mechanics, we can also think of mass as a measure of a body’s resistance to motion or a change in its motion. Thus, the greater a body’s mass, the harder it will be to set it in motion or change its motion.

In laymen’s terms, the center of mass (also known as center of gravity) is the point in a body around which the mass of the body is evenly distributed. In mechanics, the center of mass is the point through which any force can act on the body without resulting in a rotation of the body.

Although most people are familiar with the terms mass and center of gravity, the term moment of inertia is not so familiar; however, in mechanics it is equally important. The mass moment of inertia of a body is a quantitative measure of the radial distribution of the mass of a body about a given axis of rotation. Analogous to mass being a measure of a body’s resistance to linear motion, mass moment of inertia (also known as rotational inertia) is a measure of a body’s resistance to rotational motion.

Now that you know what these properties mean, let’s look at how to calculate each.

For a given body made up of a number of particles, the total mass of the body is simply the sum of the masses of all elemental particles making up the body, where the mass of each elemental particle is its mass density times its volume. Assuming that the body is of uniform density, then the total mass of the body is simply the density of the body times the total volume of the body. This is expressed in the following equation:

m = ∫ ρ dV = ρ ∫ dV

In practice, you rarely need to take the volume integral to find the mass of a body, especially considering that many of the bodies we will consider—for example, cars and planes—are not of uniform density. Thus, you will simplify these complicated bodies by breaking them down into an ensemble of component bodies of known or easily calculable mass and simply sum the masses of all components to arrive at the total mass.

The calculation of the center of gravity of a body is a little more involved. First, divide the body into a finite number of elemental masses with the center of each mass specified relative to the reference coordinate system axes. We’ll refer to these elemental masses as mi. Next, take the first moment of each mass about the reference axes and then add up all of these moments. The first moment is the product of the mass times the distance along a given coordinate axis from the origin to the center of mass. Finally, divide this sum of moments by the total mass of the body, yielding the coordinates to the center of mass of the body relative to the reference axes. You must perform this calculation once for each dimension—that is, twice when working in 2D and three times when working in 3D. Here are the equations for the 3D coordinates of the center of mass of a body:

xc = {∫ xo dm} / m
yc = {∫ yo dm} / m
zc = {∫ zo dm} / m

where (x, y, z)c are the coordinates of the center of mass for the body and (x, y, z)o are the coordinates of the center of mass of each elemental mass. The quantities xo dm, yo dm, and zo dm represent the first moments of the elemental mass, dm, about each of the coordinate axes.

Here again, don’t worry too much about the integrals in these equations. In practice, you will be summing finite numbers of masses and the formulas will take on the friendlier forms shown here:

xc = {Σ xomi} / {Σ mi}
yc = {Σ yomi} / {Σ mi}
zc = {Σ zomi} / {Σ mi}

Note that you can easily substitute weights for masses in these formulas since the constant acceleration due to gravity, g, would appear in both the numerators and denominators, thus dropping out of the equations. Recall that the weight of an object is its mass times the acceleration due to gravity, g, which is 9.8 m/s2 at sea level.

The formulas for calculating the total mass and center of gravity for a system of discrete point masses can conveniently be written in vector notation as follows:

mt = Σ mi
CG =[Σ (cgi) (mi)] / mt

where mt is the total mass, mi is the mass of each point mass in the system, CG is the combined center of gravity, and cgi is the location of the center of gravity of each point mass in design, or reference, coordinates. Notice that CG and cgi are shown as vectors since they denote position in Cartesian coordinates. This is a matter of convenience since it allows you to take care of the x, y, and z components (or just x and y in two dimensions) in one shot.

In the code samples that follow, let’s assume that the point masses making up the body are represented by an array of structures where each structure contains the point mass’s design coordinates and mass. The structure will also contain an element to hold the coordinates of the point mass relative to the combined center of gravity of the rigid body, which will be calculated later.

typedef struct _PointMass
{
   float mass;
   Vector designPosition;
   Vector correctedPosition;
} PointMass;

// Assume that _NUMELEMENTS has been defined
PointMassElements[_NUMELEMENTS];

Here’s some code that illustrates how to calculate the total mass and combined center of gravity of the elements:

int  i;
float TotalMass;
Vector CombinedCG;
Vector FirstMoment;

TotalMass = 0;
for(i=0; i<_NUMELEMENTS; i++)
   TotalMass FAC+= Elements[i].mass;

FirstMoment = Vector(0, 0, 0);
for(i=0; i<_NUMELEMENTS; i++)
{
   FirstMoment += Element[i].mass * Element[i].designPosition;
}
CombinedCG = FirstMoment / TotalMass;

Now that the combined center of gravity location has been found, you can calculate the relative position of each point mass as follows:

for(i=0; i<_NUMELEMENTS; i++)
{
   Element[i].correctedPosition = Element[i].designPosition -
                  CombinedCG;
}

To calculate mass moment of inertia, you need to take the second moment of each elemental mass making up the body about each coordinate axis. The second moment is then the product of the mass times distance squared. That distance is not the distance to the elemental mass centroid along the coordinate axis as in the calculation for center of mass, but rather the perpendicular distance from the coordinate axis, about which we want to calculate the moment of inertia, to the elemental mass centroid.

Referring to Figure 1-2 for an arbitrary body in three dimensions, when calculating moment of inertia about the x-axis, Ixx, this distance, r, will be in the yz-plane such that rx2 = y2 + z2. Similarly, for the moment of inertia about the y-axis, Iyy, ry2 = z2 + x2, and for the moment of inertia about the z-axis, Izz, rz2 = x2 + y2.

Arbitrary body in 3D
Figure 1-2. Arbitrary body in 3D

The equations for mass moment of inertia about the coordinate axes in 3D are:

Ixx = ∫ rx2 dm = ∫ (y2 + z2) dm
Iyy = ∫ ry2 dm = ∫ (z2 + x2) dm
Izz = ∫ rz2 dm = ∫ (x2 + y2) dm

Let’s look for a moment at a common situation that arises in practice. Say you are given the moment of inertia, Io, of a body about an axis, called the neutral axis, passing through the center of mass of the body, but you want to know the moment of inertia, I, about an axis some distance from but parallel to this neutral axis. In this case, you can use the transfer of axes, or parallel axis theorem, to determine the moment of inertia about this new axis. The formula to use is:

I = Io + md2

where m is the mass of the body and d is the perpendicular distance between the parallel axes.

There is an important practical observation to make here: the new moment of inertia is a function of the distance separating the axes squared. This means that in cases where Io is known to be relatively small and d relatively large, you can safely ignore Io, since the md2 term will dominate. You must use your best judgment here, of course. This formula for transfer of axes also indicates that the moment of inertia of a body will be at its minimum when calculated about an axis passing through the body’s center of gravity. The body’s moment of inertia about any parallel axis will always increase by an amount, md2, when calculated about an axis not passing through the body’s center of mass.

In practice, calculating mass moment of inertia for all but the simplest shapes of uniform density is a complicated endeavor, so we will often approximate the moment of inertia of a body about axes passing through its center of mass by using simple formulas for basic shapes that approximate the object. Further, we will break down complicated bodies into smaller components and take advantage of the fact that Io may be negligible for certain components considering its md2 contribution to the total body’s moment of inertia.

Figure 1-3 through Figure 1-7 show some simple solid geometries for which you can easily calculate mass moments of inertia. The mass moment of inertia formulas for each of these simple geometries of homogenous density about the three coordinate axes are shown in the figure captions. You can readily find similar formulas for other basic geometries in college-level dynamics texts (see the Bibliography at the end of this book for a few sources).

Circular cylinder: Ixx = Iyy = (1/4) mr2 + (1/12) ml2; Izz = (1/2) mr2
Figure 1-3. Circular cylinder: Ixx = Iyy = (1/4) mr2 + (1/12) ml2; Izz = (1/2) mr2
Circular cylindrical shell: Ixx = Iyy = (1/2) mr2 + (1/12) ml2; Izz = mr2
Figure 1-4. Circular cylindrical shell: Ixx = Iyy = (1/2) mr2 + (1/12) ml2; Izz = mr2
Rectangular cylinder: Ixx = (1/12) m(a2 + l2); Iyy = (1/12) m(b2 + l2); Izz = (1/12) m(a2 + b2)
Figure 1-5. Rectangular cylinder: Ixx = (1/12) m(a2 + l2); Iyy = (1/12) m(b2 + l2); Izz = (1/12) m(a2 + b2)
Sphere: Ixx = Iyy = Izz = (2/5) mr2
Figure 1-6. Sphere: Ixx = Iyy = Izz = (2/5) mr2
Spherical shell: Ixx = Iyy = Izz = (2/3) mr2
Figure 1-7. Spherical shell: Ixx = Iyy = Izz = (2/3) mr2

As you can see, these formulas are relatively simple to implement. The trick here is to break up a complex body into a number of smaller, simpler representative geometries whose combination will approximate the complex body’s inertia properties. This exercise is largely a matter of judgment considering the desired level of accuracy.

Let’s look at a simple 2D example demonstrating how to apply the formulas discussed in this section. Suppose you’re working on a top-down-view auto racing game where you want to simulate the automobile sprite based on 2D rigid-body dynamics. At the start of the game, the player’s car is at the starting line, full of fuel and ready to go. Before starting the simulation, you need to calculate the mass properties of the car, driver, and fuel load at this initial state. In this case, the body is made up of three components: the car, driver, and full load of fuel. Later during the game, however, the mass of this body will change as fuel burns off and the driver gets thrown after a crash! For now, let’s focus on the initial condition, as illustrated in Figure 1-8.

Example body consisting of car, driver, and fuel
Figure 1-8. Example body consisting of car, driver, and fuel

The properties of each component in this example are given in Table 1-2. Note that length is measured along the x-axis, width along the y-axis, and height would be coming out of the screen. Also note that the coordinates—in the form (x, y)—to the centroid of each component are referenced to the global origin.

Table 1-2. Example properties

Car

Driver (seated)

Fuel

Length = 4.70 m

Length = 0.90 m

Length = 0.50 m

Width = 1.80 m

Width = 0.50 m

Width = 0.90 m

Height = 1.25 m

Height = 1.10 m

Height = 0.30 m

Weight = 17,500 N

Weight = 850 N

Density of fuel = 750 kg/m3

Centroid = (30.5, 30.5) m

Centroid = (31.50, 31.00) m

Centroid = (28.00, 30.50) m

The first mass property we want to calculate is the mass of the body. This is a simple calculation since we are already given the weight of the car and the driver. The only other component of weight we need is that of the fuel. Since we are given the mass density of the fuel and the geometry of the tank, we can calculate the volume of the tank and multiply by the density and the acceleration due to gravity to get the weight of the fuel in the tank. This yields 920.6 N of fuel, as shown here:

Wfuel = ρvg = (750 kg/m3) (0.50 m) (0.90 m) (0.30 m) (9.81 m/s2) = 993 N

Note

Acceleration due to gravity is the acceleration of a falling object as it falls toward the earth. The weight of an object is equal to its mass times the acceleration due to gravity. The symbol g is used to represent the acceleration due to gravity, and on Earth the value of g is approximately 9.8 m/s2 at sea level. Units for weight in the metric system are Newtons, N.

Now, the total weight of the body is:

Wtotal = Wcar + Wdriver + Wfuel
Wtotal = 17,500 N + 850 N + 993 N = 19,343 N

To get the mass of the body, you simply divide the weight by the acceleration due to gravity.

Mtotal = Wtotal/g = 19,343 N /(9.81 m/s2) = 1972 kg

The next mass property we want is the location of the center of gravity of the body. In this example we will calculate the centroid relative to the global origin. We will also apply the first moment formula twice, once for the x coordinate and again for the y coordinate:

Xcg body = {(xcg car)(Wcar) + (xcg driver)(Wdriver) + (xcg fuel)(Wfuel)} / Wtotal
Xcg body = {(30.50 m)(17,500 N) + (31.50 m)(850 N) + (28.00 m)(993 N)} / 19,343 N
Xcg body = 30.42 m
Ycg body = {(ycg car)(Wcar) + (ycg driver)(Wdriver) + (ycg fuel)(Wfuel)} / Wtotal
Ycg body = {(30.50 m)(17,500 N) + (31.00 m)(850 N) + (30.50 m)(993 N)} / 19,343 N
Ycg body = 30.52 m

Notice that we used weight in these equations instead of mass. Remember we can do this because the acceleration due to gravity built into the weight value is constant and appears in both the numerator and denominator, thus canceling out.

Now it’s time to calculate the mass moment of inertia of the body. This is easy enough in this 2D example since we have only one rotational axis, coming out of the paper, and thus need only perform the calculation once. The first step is to calculate the local moment of inertia of each component about its own neutral axis. Given the limited information we have on the geometry and mass distribution of each component, we will make a simplifying approximation by assuming that each component can be represented by a rectangular cylinder, and will thus use the corresponding formula for moment of inertia from Figure 1-5. In the equations to follow, we’ll use a lowercase w to represent width so as to not confuse it with weight, where we’ve been using a capital W.

Io car = (m/12) (w2 + L2)
Io car = ((17,500 N / 9.81 m/s2) / 12 ) ((1.80 m)2 + (4.70 m)2) = 3765.5 N − s2 − m
Io driver = (m/12) (w2 + L2)
Io driver = ((850 N / 9.81 m/s2) / 12) ((0.50 m)2 + (0.90 m)2) = 7.7 N − s2 − m
Io fuel = (m/12) (w2 + L2)
Io fuel = ((993 N / 9.81 m/s2) / 12) ((0.90 m)2 + (0.50 m)2) = 8.9 N − s2 − m

Since these are the moments of inertia of each component about its own neutral axis, we now need to use the parallel axis theorem to transfer these moments to the neutral axis of the body, which is located at the body center of gravity that we recently calculated. To do this, we must find the distance from the body center of gravity to each component’s center of gravity. The distances squared from each component to the body center of gravity are:

d2car = (xcg car − Xcg)2 + (ycg car − Ycg)2
d2car = (30.50 m − 30.42 m)2 + (30.50 m − 30.53 m)2 = 0.01 m2
d2driver = (xcg driver − Xcg)2 + (ycg driver − Ycg)2
d2driver = (31.50 m − 30.42 m)2 + (31.25 m − 30.53 m)2 = 1.68 m2
d2fuel = (xcg fuel − Xcg)2 + (ycg fuel − Ycg)2
d2fuel = (28.00 m − 30.42 m)2 + (30.50 m − 30.53 m)2 = 5.86 m2

Now we can apply the parallel axis theorem as follows:

Icg car = Io + md2
Icg car = 3765.5 N − s2 − m + (17,500 N / 9.81 m/s2) (0.01 m2) = 3783.34 N − s2 − m
Icg driver = Io + md2
Icg driver = 7.7 N − s2 − m + (850 N / 9.81 m/s2) (1.68 m2) = 153.27 N − s2 − m
Icg fuel = Io + md2
Icg fuel = 8.9 N − s2 − m + (993 N / 9.81 m/s2) (5.86 m2) = 602.07 N − s2 − m

Notice how the calculations for the Icg of the driver and the fuel are dominated by their md2 terms. In this example, the local inertia of the driver and fuel is only 2.7% and 2.1%, respectively, of their corresponding md2 terms.

Finally, we can obtain the total moment of inertia of the body about its own neutral axis by summing the Icg contributions of each component as follows:

Icg total = Icg car + Icg driver + Icg fuel
Icg total = 3783.34 N − s2 − m + 153.27 N − s2 − m + 602.07 N − s2 − m = 4538.68 N − s2 − m

The mass properties of the body—that is, the combination of the car, driver, and full tank of fuel—are shown in Table 1-3.

Table 1-3. Example summary of mass properties

Property

Computed value

Total mass (weight)

1972 kg (19,343 N)

Combined center of mass location

(x,y) = (30.42 m, 30.53 m)

Mass moment of inertia

4538.68 N – s2 – m

It is important that you understand the concepts illustrated in this example well because as we move on to more complicated systems and especially to general motion in 3D, these calculations are only going to get more complicated. Moreover, the motion of the bodies to be simulated are functions of these mass properties, where mass will determine how these bodies are affected by forces, center of mass will be used to track position, and mass moment of inertia will determine how these bodies rotate under the action of noncentroidal forces.

So far, we have looked at moments of inertia about the three coordinate axes in 3D space. However, in general 3D rigid-body dynamics, the body may rotate about any axis—not necessarily one of the coordinate axes, even if the local coordinate axes pass through the body center of mass. This complication implies that we must add a few more terms to our set of I’s for a body to handle this generalized rotation. We will address this topic further later in this chapter, but before we do that we need to go over Newton’s second law of motion in detail.

Newton’s Second Law of Motion

As we stated in the first section of this chapter, Newton’s second law of motion is of particular interest in the study of mechanics. Recall that the equation form of Newton’s second law is:

F = ma

where F is the resultant force acting on the body, m is the mass of the body, and a is the linear acceleration of the body center of gravity.

If you rearrange this equation as follows:

F/m = a

you can see how the mass of a body acts as a measure of resistance to motion. Observe here that as mass increases in the denominator for a constant applied force, then the resulting acceleration of the body will decrease. You could say that the body of greater mass offers greater resistance to motion. Similarly, as the mass decreases for a constant applied force, then the resulting acceleration of the body will increase, and you could say that the body of smaller mass offers lower resistance to motion.

Newton’s second law also states that the resulting acceleration is in the same direction as the resultant force on the body; thus, force and acceleration must be treated as vector quantities. In general, there may be more than one force acting on the body at a given time, which means that the resultant force is the vector sum of all forces acting on the body. So, you can now write:

F = ma

where a represents the acceleration vector.

In 3D, the force and acceleration vectors will have x, y, and z components in the Cartesian reference system. In this case, the component equations of motion are written as follows:

∑ Fx = max
∑ Fy = may
∑ Fz = maz

An alternative way to interpret Newton’s second law is that the sum of all forces acting on a body is equal to the rate of change of the body’s momentum over time, which is the derivative of momentum with respect to time. Momentum equals mass times velocity, and since velocity is a vector quantity, so is momentum. Thus:

G = mv

where G is linear momentum of the body, m is the body’s mass, and v is velocity of the center of gravity of the body. The time rate of change of momentum is the derivative of momentum with respect to time:

dG/dt = d/dt (mv)

Assuming that the body mass is constant (for now), you can write:

dG/dt = m dv/dt

Observing that the time rate of change of velocity, dv/dt, is acceleration, we arrive at:

dG/dt = ma

and:

F = dG/dt = ma

So far we have considered only translation of the body without rotation. In generalized 3D motion, you must account for the rotational motion of the body and will thus need some additional equations to fully describe the body’s motion. Specifically, you will require analogous formulas relating the sum of all moments (torque) on a body to the rate of change in its angular momentum over time, or the derivative of angular momentum with respect to time. This gives us:

Mcg = d/dt (Hcg)

where Mcg is the sum of all moments about the body center of gravity, and H is the angular momentum of the body. Mcg can be expressed as:

Mcg = r × F

where F is a force acting on the body, and r is the distance vector from F, perpendicular to the line of action of F (i.e., perpendicular to the vector F), to the center of gravity of the body, and × is the vector cross-product operator.

The angular momentum of the body is the sum of the moments of the momentum of all particles in the body about the axis of rotation, which in this case we assume passes through the center of gravity of the body. This can be expressed as:

Hcg = ∑ ri × mi (ω × ri)

where i represents the ith particle making up the body, ω is the angular velocity of the body about the axis under consideration, and (ri × mi (ω × ri)) is the angular momentum of the ith particle, which has a magnitude of miωri2. For rotation about a given axis, this equation can be rewritten in the form:

Hcg = ∫ ω r2 dm

Given that the angular velocity is the same for all particles making up the rigid body, we have:

Hcg = ω ∫ r2 dm

and recalling that moment of inertia, I, equals r2 dm, we get:

Hcg = Iω

Taking the derivative with respect to time, we obtain:

dHcg/dt = d/dt (Iω) = I dω/dt = Iα

where α is the angular acceleration of the body about a given axis.

Finally, we can write:

Mcg = Iα

As we stated in our discussion on mass moment of inertia, we will have to further generalize our formulas for moment of inertia and angular moment to account for rotation about any body axis. Generally, M and α will be vector quantities, while I will be a tensor[6] since the magnitude of moment of inertia for a body may vary depending on the axis of rotation (see the sidebar Tensors).

We need to mention a few things at this point regarding coordinates, which will become important when you’re writing your real-time simulator. Both of the equations of motion have, so far, been written in terms of global coordinates and not body-fixed coordinates. That’s OK for the linear equation of motion, where you can track the body’s location and velocity in the global coordinate system. However, from a computational point of view, you don’t want to do that for the angular equation of motion for bodies that rotate in three dimensions.[7] The reason is because the moment of inertia term, when calculated with respect to global coordinates, actually changes depending on the body’s position and orientation. This means that during your simulation you’ll have to recalculate the inertia matrix (and its inverse) a lot, which is computationally inefficient. It’s better to rewrite the equations of motion in terms of local (attached to the body) coordinates so you have to calculate the inertia matrix (and its inverse) only once at the start of your simulation.

In general, the time derivative of a vector, V, in a fixed (nonrotating) coordinate system is related to its time derivative in a rotating coordinate system by the following:

(dV/dt)fixed = (dV/dt)rot + (ω × V)

The (ω × V) term represents the difference between V’s time derivative as measured in the fixed coordinate system and V’s time derivative as measured in the rotating coordinate system. We can use this relation to rewrite the angular equation of motion in terms of local, or body-fixed, coordinates. Further, the vector to consider is the angular momentum vector Hcg. Recall that Hcg = and its time derivative are equal to the sum of moments about the body’s center of gravity. These are the pieces you need for the angular equation of motion, and you can get to that equation by substituting Hcg in place of V in the derivative transform relation as follows:

Mcg = dHcg/dt = I (dω/dt) + (ω × (I ω))

where the moments, inertia tensor, and angular velocity are all expressed in local (body) coordinates. Although this equation looks a bit more complicated than the one we showed you earlier, it is much more convenient to use since I will be constant throughout your simulation (unless your body’s mass or geometry changes for some reason during your simulation), and the moments are relatively easy to calculate in local coordinates. You’ll put this equation to use in Chapter 15 when we show you how to develop a simple 3D rigid-body simulator.

Inertia Tensor

Take another look at the angular equation of motion and notice that we set the inertia term, I, in bold, implying that it is a vector. You’ve already seen that, for two-dimensional problems, this inertia term reduces to a scalar quantity representing the moment of inertia about the single axis of rotation. However, in three dimensions there are three coordinate axes about which the body can rotate. Moreover, in generalized three dimensions, the body can rotate about any arbitrary axis. Thus, for three-dimensional problems, I is actually a 3×3 matrix—a second-rank tensor.

To understand where this inertia matrix comes from, you must look again at the angular momentum equation:

Hcg = ∫ (r × (ω × r)) dm

where ω is the angular velocity of the body; r is the distance from the body’s center of gravity to each elemental mass, dm; and (r × (ω × r))dm is the angular momentum of each elemental mass. The term in parentheses is called a triple vector product and can be expanded by taking the vector cross products. r and ω are vectors that can be written as follows:

r = x i + y j + z k
ω = ωx i + ωy j + ωz k

Expanding the triple vector product term yields:

Hcg = ∫ {[(y2 + z2x − xyωy - xzωz] i +
[ −yxωx + (z2 + x2y − yzωz] j +
[−zxωx − zyωy + (x2 + y2)ωz] k} dm

To simplify this equation, let’s replace a few terms by letting:

Ixx = ∫ (y2 + z2) dm
Iyy = ∫ (z2 + x2) dm
Izz = ∫ (x2 + y2) dm
Ixy = Iyx = ∫ (xy) dm
Ixz = Izx = ∫ (xz) dm
Iyz = Izy = ∫ (yz) dm

Substituting these I variables, some of which should look familiar to you, back into the expanded equation yields:

Hcg = [Ixx ωx − Ixy ωy − Ixz ωz] i +
[−Iyx ωx + Iyy ωy − Iyz ωz] j +
[−Izx ωx − Izy ωy + Izz ωz] k

Simplifying this a step further by letting I be a matrix:

Ixx −Ixy −Ixz
I = −Iyx Iyy −Iyz
−Izx −Izy Izz

yields the following equation:

Hcg = I ω

You already know that I represents the moment of inertia, and the terms that should look familiar to you already are the moment of inertia terms about the three coordinate axes, Ixx, Iyy, and Izz. The other terms are called products of inertia (see Figure 1-9):

Ixy = Iyx = ∫ (xy) dm
Ixz = Izx = ∫ (xz) dm
Iyz = Izy = ∫ (yz) dm
Products of inertia
Figure 1-9. Products of inertia

Just like the parallel axis theorem, there’s a similar transfer of axis formula that applies to products of inertia:

Ixy = Io(xy) + m dx dy
Ixz = Io(xz) + m dx dz
Iyz = Io(yz) + m dy dz

where the Io terms represent the local products of inertia (that is, the products of inertia of the object about axes that pass through its own center of gravity), m is the object’s mass, and the d terms are the distances between the coordinate axes that pass through the object’s center of gravity and a parallel set of axes some distance away (see Figure 1-10).

You’ll notice that we did not give you any product of inertia formulas for the simple shapes shown earlier in Figure 1-3 through Figure 1-7. The reason is that the given moments of inertia were about the principal axes for these shapes. For any body, there exists a set of axes—called the principal axes—oriented such that the product of inertia terms in the inertia tensor are all zero.

Transfer of axes
Figure 1-10. Transfer of axes

For the simple geometries shown earlier, each coordinate axis represented a plane of symmetry, and products of inertia go to zero about axes that represent planes of symmetry. You can see this by examining the product of inertia formulas, where, for example, all of the (xy) terms in the integral will be cancelled out by each corresponding −(xy) term if the body is symmetric about the y-axis, as illustrated in Figure 1-11.

Symmetry
Figure 1-11. Symmetry

For composite bodies, however, there may not be any planes of symmetry, and the orientation of the principal axes will not be obvious. Further, you may not even want to use the principal axes as your local coordinate axes for a given rigid body since it may be awkward to do so. For example, consider the airplane from the FlightSim discussion in Chapter 7, where you’ll have the local coordinate design axes running, relative to the pilot, fore and aft, up and down, and left and right. This orientation is convenient for locating the parts of the wings, tail, elevators, etc. with respect to one another, but these axes don’t necessarily represent the principal axes of the airplane. The end result is that you’ll use axes that are convenient and deal with the nonzero products of inertia (which, by the way, can be either positive or negative).

We already showed you how to calculate the combined moments of inertia for a composite body made up of a few smaller elements. Accounting for the product of inertia terms follows the same procedure except that, typically, your elements are such that their local product of inertia terms are zero. This is the case only if you represent your elements by simple geometries such as point masses, spheres, rectangles, etc. That being the case, the main contribution to the rigid body’s products of inertia will be due to the transfer of axes terms for each element.

Before looking at some sample code, let’s first revise the element structure to include a new term to hold the element’s local moment of inertia as follows:

typedef struct _PointMass
{
   float mass;
   Vector designPosition;
   Vector correctedPosition;
   Vector localInertia;
} PointMass;

Here we’re using a vector to represent the three local moment of inertia terms and we’re also assuming that the local products of inertia are zero for each element.

The following code sample shows how to calculate the inertia tensor given the component elements:

float   Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
Matrix3x3 InertiaTensor;

Ixx = 0;  Iyy = 0;  Izz = 0;
Ixy = 0;  Ixz = 0;  Iyz = 0;

for (i = 0; i<_NUMELEMENTS; i++)
{
   Ixx += Element[i].LocalInertia.x +
      Element[i].mass * (Element[i].correctedPosition.y *
      Element[i].correctedPosition.y +
      Element[i].correctedPosition.z *
      Element[i].correctedPosition.z);

   Iyy += Element[i].LocalInertia.y +
      Element[i].mass * (Element[i].correctedPosition.z *
      Element[i].correctedPosition.z +
      Element[i].correctedPosition.x *
      Element[i].correctedPosition.x);

   Izz += Element[i].LocalInertia.z +
      Element[i].mass * (Element[i].correctedPosition.x *
      Element[i].correctedPosition.x +
      Element[i].correctedPosition.y *
      Element[i].correctedPosition.y);

   Ixy += Element[i].mass * (Element[i].correctedPosition.x *
      Element[i].correctedPosition.y);

   Ixz += Element[i].mass * (Element[i].correctedPosition.x *
      Element[i].correctedPosition.z);

   Iyz += Element[i].mass * (Element[i].correctedPosition.y *
      Element[i].correctedPosition.z);
}

// e11 stands for element on row 1 column 1, e12 for row 1 column 2, etc.
InertiaTensor.e11 = Ixx;
InertiaTensor.e12 = -Ixy;
InertiaTensor.e13 = -Ixz;

InertiaTensor.e21 = -Ixy;
InertiaTensor.e22 = Iyy;
InertiaTensor.e23 = -Iyz;

InertiaTensor.e31 = -Ixz;
InertiaTensor.e32 = -Iyz;
InertiaTensor.e33 = Izz;

Note that the inertia tensor is calculated about axes that pass through the combined center of gravity for the rigid body, so be sure to use the corrected coordinates for each element relative to the combined center of gravity when applying the transfer of axes formulas.

We should also mention that this calculation is for the inertia tensor in body-fixed coordinates, or local coordinates. As we discussed earlier in this chapter, it is better to rewrite the angular equation of motion in terms of local coordinates and use the local inertia tensor to save some number crunching in your real-time simulation.

Relativistic Time

To allow for a thorough understanding of how advanced space vehicles work as well as give you a mechanism by which to alter time in your games, we would like to offer a brief introduction to the theory of relativity, and particularly its effect on time. In our everyday experience, it is safe to assume that the clock on your wall is ticking at the same rate as the clock on our wall as we write this. However, the reason we all know the name Albert Einstein is that he had the foresight to abandon time as a constant. Instead he postulated that light travels at the same speed regardless of the motion of the source.

That is to say, if you shine a flashlight in a vacuum, the electromagnetic radiation it emits in the form of visible light travels at a set velocity of c (299,792,458 m/s). Now, if you take that same flashlight and put it on the nose of a rocket traveling at half that speed directly at you, you might expect that light is traveling at you with a velocity of 1.5c. Yet, the rocket-powered flashlight would still be observed as emitting light at a velocity of c. As Einstein’s theory of special relativity matured, the postulate has been reformulated to state that there is a maximum speed at which information can be transferred in the space-time continuum, a principal called locality. As electromagnetic radiation has no mass,[8] it travels at this maximum speed in a vacuum.

The most startling consequence of the theory is that time is no longer absolute. The postulate that the speed of light is constant for all frames of reference requires that time slow down, or dilate, as velocity increases. It is actually fairly easy to demonstrate this result.

The following example depicts a conceptual clock. A beam of light is bouncing between two mirrors. The time it takes for the beam of light to start from one mirror, bounce off the second, and return to the first constitutes one “tick” of this clock. That tick can be calculated as:

Δt = 2L/c

Where L is the distance between the mirrors and c is the speed of light. Figure 1-12 shows what the clock would look like if you were above it traveling at its velocity.

Traveling with the clock
Figure 1-12. Traveling with the clock

Now suppose that you are above the mirrors as they speed past you to the right. Then the clock would look something like Figure 1-13.

Stationary with respect to the clock
Figure 1-13. Stationary with respect to the clock

One tick of the clock is now defined as twice the distance of the hypotenuse over the speed of light. Clearly H must be larger than L, so we see that the clock with the relative velocity will take longer to tick than if you were moving with the clock.

If this isn’t clear, we can also come to the same conclusion a different way. If we define the speed of light as the amount of time it takes for the light beam to travel the distance between the mirrors divided by the time it took to travel that distance, we see that:

c = 2L/Δt

but because the speed of light must be held constant in all frames of reference via locality, we also have:

c = 2H/Δt

For the two preceding equations to be equivalent, Δt must be different for each system.

This means that if I were in a rocket moving at high velocity past you as you read this book, you would look at the clock on my rocket wall and see it ticking more slowly than your clock. Now, it may seem as though I would look out of my rocket and see your clock running fast, but in fact the opposite is true. I would consider myself at rest and you speeding past me such that I would say your clock is running slowly. This may seem counterintuitive, but think of it in the same way as visual perspective. If you are at a great distance from me, then you appear to be small. That doesn’t imply that I would appear to be huge to you!

Now the amount of dilation for a given velocity v is given by the Lorentz transformation:

Δt’ = γΔt

where:

Stationary with respect to the clock

is called the Lorentz factor.

For velocities approaching the speed of light, the effect of time dilation is dramatic. Imagine if you had a twin sister. She boards a spaceship and is accelerated to three-fourths the speed of light relative to you on Earth. Upon her return, according to her clock, 20 years have elapsed since she left. However, due to time dilation you will have aged 30 years. While this seems paradoxical given that you both will have observed each other’s time as running slowly compared to your own, the paradox is resolved by the fact that special relativity claims only that inertial frames of reference are identical. For the spaceship to return to Earth, it must accelerate by changing directions or, in other words, become a noninertial frame of reference. Once the ship is no longer an inertial frame of reference, there will appear to be a jump in the stay-at-home twin’s age. Strange but true!

In addition to time dilation due to relative velocity, time also slows down in the presence of strong gravitational fields as a result of Einstein’s theory of general relativity. This sort of time dilation is not relative in the sense that if I were closer to a black hole than you, we’d both agree that my clock is ticking less often than yours. However, given that all physical processes would be slower, there is no way to establish which clock is “faster” and which is “slower.” It is all relative!

As some games require a way to speed up or slow down time, the applications of time dilation allow for a physical phenomenon to enable time manipulation. Imagine your character needing to be sent to the future to complete some task. That character could be put into a centrifuge and accelerated near the speed of light. Upon exiting the centrifuge, he would essentially have time-traveled into the future. However, if you plan to stay within the limits of physics, then it is a one-way trip: there is no way to reverse time in relativity! Additionally, if you would like to send a character to a nearby star, you can do so within the limits of physics as well. By accelerating a spaceship, a human being would be able to travel a great distance in a lifetime. In fact, with a constant acceleration of 9.8 m/s2, which would make the astronauts feel like they were on Earth, you could travel the entire visible galaxy. However, you would have essentially time-traveled billions of years into the future. We are sure that you can imagine any number of scenarios where such a mechanism might make your game more interesting while always remaining in the realm of the physically possible!

Now, besides those implications to games involving space flight or high-velocity travel, time dilation is also important to some surprising digital electronic applications. For instance, the Global Positioning System (GPS), described in detail in Chapter 22, must take relativistic time dilation into account when calculating position. The satellite’s high speed slows the clock compared to your watch on Earth; however, being farther up the Earth’s gravity causes it to tick faster than a terrestrial clock. The specifics of this combined effect are discussed in Chapter 22.

Another point you might find interesting is that it is now easy to see how the “you can’t travel faster than light” rule is a result of the theory of relativity. Should you accelerate such that your velocity, v, is equal to c, the Lorentz transformation attempts to divide by zero. For games where faster-than-light travel is a practical necessity, you will have to imagine a mechanism to prevent this but be able to break the rules with style.



[5] Linear motion refers to motion in space without regard to rotation; angular motion refers specifically to the rotation of a body about any axis (the body may or may not be undergoing linear motion at the same time).

[6] In this case, I will be a second-rank tensor, which is essentially a 3×3 matrix. A vector is actually a tensor of rank one, and a scalar is actually a tensor of rank zero.

[7] In two dimensions, it’s OK to leave the angular equation of motion as it’s shown here since the moment of inertia term is simply a constant scalar quantity.

[8] Photons, the particle form of electromagnetic radiation, can have relativistic mass but are hypothesized to have no “rest mass.” To avoid getting into quantum electrodynamics, here we’ll just consider them without mass.

Get Physics for Game Developers, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.