The Metric System

 < Day Day Up > 

If you lived in almost any country other than the United States, you'd probably use metric units more than English units. This section is a quick review of how to work within the metric system, just in case it's been a while for you. I think after using it a bit you'll find that the metric system is much easier to work with because it's based on powers of 10.

When you're programming, the computer cannot distinguish between meters and centimeters. It understands only numbers , so it is up to you as the programmer to be consistent with the units of physical quantities in your program. We'll start with the metric system because it's much easier to work with. Your player will never know if you are working with miles or kilometers, yards or meters, so if you can do your measurements within the metric system, it will save you a lot of headaches . In addition, many licensed add-ins for game engines, such as the Havok physics engine, use metric units, so you might want to consider making it a habit to work with metrics.

Suppose you are tracking the motion of the main character in your game. You might estimate his displacement in meters while he's running, but it might be easier to estimate in centimeters when he's tiptoeing. If he runs for 10 meters and then tiptoes for 75 centimeters, it wouldn't make sense to add those two displacements together. You'd have to convert one of them to the same units as the other before you could add them. It doesn't matter which one you choose, as long as they're the same.

Converting within the metric system is simple because all the units represent powers of 10, so converting between them is as easy as sliding the decimal point. The following is a list in descending order of the metric prefixes. These prefixes would be followed by the word meter or gram.

NOTE

Remember that a meter is almost the same length as a yarda little over 3 feet.

Also, one gram is about the mass of a large thumbtack. A nickel has a mass of about 5 grams.


kilo-

hecto-

deca-

meters, grams

deci-

centi-

milli-

1000

100

10

1

0.1

0.01

0.001


NOTE

These prefixes work the exact same way with grams if you're measuring mass.


Each time you slide to the right along that list, you multiply by 10 or slide the decimal point one slot to the right. For example, if you wanted to convert the 10 meters your character ran to centimeters, you'd slide right twice, so you have to slide the decimal point two places to the right, which would give you 1000 centimeters. Likewise, if you wanted to convert 75 centimeters to meters, that would be two prefixes to the left, so you'd slide the decimal point two places to the left, which yields 0.75 meters. This is the beauty of the metric system. Because it's a base-10 system, each time you slide to the left or right on the list, you multiply or divide the original value by the system's base, which is 10, just like our familiar decimal system.

Example 7.1: Converting Meters to Kilometers

Suppose the main character in your game runs 50 meters and then hops in his car and drives 25 kilometers. How far does he travel altogether in kilometers?

Solution
  1. To add the two displacements, they must have the same units. In this case, you convert the 50 meters to kilometers. Looking at the list of prefixes, kilometers are three prefixes to the left of meters, so you must slide the decimal point three places to the left. This means that 50m = 0.05km.

  2. Now you can add the two together, so the total displacement is 25.05km.

Example 7.2: Converting Kilometers to Meters

Suppose you find out that the rest of your team is programming in meters. How far does the main character in Example 7.1 travel altogether in meters?

Solution
  1. You could start all over and convert the 25km to meters and then add again, or you could just convert the total, 25.05km, to meters.

  2. Let's take the second approach. Meters are three prefixes to the right on the list, so you must slide the decimal point three places to the right, which gives you a total of 25,050 meters.

After stepping through two examples, you can see the beauty of the metric system. Converting within metrics is as simple as sliding the decimal point, because you're multiplying and dividing by powers of 10. The next section looks at the more complicated process of converting within the English system as well as converting between metrics and English units.

Self-Assessment

1.

Convert 35 meters to centimeters.

2.

Convert 35 meters to kilometers.

3.

Convert 4567 millimeters to kilometers.

4.

Convert a mass of 56 grams to kilograms.

5.

Convert a mass of 3 kilograms to grams.


 < Day Day Up > 


Beginning Math and Physics for Game Programmers
Beginning Math and Physics for Game Programmers
ISBN: 0735713901
EAN: 2147483647
Year: 2004
Pages: 143
Authors: Wendy Stahler

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net