Beginning Math and Physics for Game Programmers

 <  Day Day Up  >  

Before we can delve into the world of trigonometry, it's imperative that we discuss angles and set standards for working with them. Obviously, angles are used for rotation, which we'll discuss in Chapters 6, "Transformations," and 14, "Rotational Motion,". They can also be used to establish a direction, which you'll see done in Chapter 4 and throughout the physics chapters. Let's identify the standards that will be used in those future chapters.

Every angle consists of two rays that intersect at a point called the vertex . We'll call one ray the initial side and the other ray the terminal side. To place an angle in standard position, we'll use the Cartesian coordinate system. The vertex should be at the origin (0,0), and the initial side always falls on the positive x-axis, as shown in Figure 3.1.

Figure 3.1. An angle in standard position.

From the positive x-axis, measure out positive angles counterclockwise and negative angles clockwise. This determines the position of the terminal side. Remember that a full revolution is 360 °. If the angle happens to be 90 °, or a right angle, the terminal side falls on the positive y-axis, and if the angle is 180 °, the terminal side falls on the negative x-axis. Notice the a symbol in Figure 3.1. Another standard that's widely accepted is to use Greek letters (such as alpha [ a ], beta [ b ], and theta [ q ]) to represent angles, so don't be thrown when you come across these characters in our discussion of angles.

Example 3.1: A Positive Angle in Standard Position

Draw a 60 ° angle in standard position.

Solution

Start with the vertex at the origin and the initial side on the positive x-axis. From there, measure out 60 ° counterclockwise, and draw the terminal side, as shown in Figure 3.2.

Figure 3.2. A 60 ° angle in standard position.

Example 3.2: A Negative Angle in Standard Position

Draw a “100 ° angle in standard position.

Solution

Start with the vertex at the origin and the initial side on the positive x-axis. From there, measure out 100 ° clockwise, and draw the terminal side, as shown in Figure 3.3.

Figure 3.3. A “100 ° angle in standard position.

So far, we've only talked about measuring angles in degrees because that's what you're probably most comfortable with. However, angles can also be measured in radians. Just like you can measure a distance in either feet or meters , you can measure angles in either degrees or radians. They're just two different units. Most likely, you'll estimate an angle in degrees but you'll have to program it in radians, so you need a conversion between the two.

Earlier, I said that a full revolution is 360 °; it's also 2 p R . This means that half a revolution is 180 °, or p R . That's the basis of the conversion.

Degrees to Radians

Angle in degrees * = Angle in radians

NOTE

Don't be thrown by the "R" superscript ( R ); it's just a label for radians, like the degree symbol ( °). Try to get into the habit of always labeling your angles with one of these two symbols ( ° or R ). Otherwise, it won't always be clear to your teammates which unit you're working in.

Example 3.3: Converting Degrees to Radians

Convert 120 ° to radians.

Solution

To convert from degrees to radians, multiply your angle by the

NOTE

The standard for writing an angle in radians is to leave it as a fraction times p R , as shown in Example 3.3. However, if you want to express it as a decimal number, just plug in p 3.141592654.

It is important to note that all the C++ trig functions ”such as sin(), cos(), and tan() ”take input in radians, and all inverse trig functions ”such as asin(), acos(), and atan() ”return angles in radians as well. It is a good idea when using angles to create a #define at the top of your math library which can be used to easily convert from degrees to radians and vice versa.

#define RadToDeg 57.29577951f #define DegToRad 0.017453293f

Multiplying an angle in radians by RadToDeg will convert that number into degrees, while multiplying a number in degrees by DegToRad will convert it into radians.

To go the opposite direction, from radians to degrees, just multiply the angle in radians by the reciprocal of the conversion factor you just used.

Radians to Degrees

Angle in radians * = Angle in degrees.

Example 3.4: Converting Radians to Degrees

Convert to degrees.

Solution

To convert from radians to degrees, multiply your angle by the

NOTE

Notice in Example 3.4 that the p R on the top of the fraction cancels out the p R on the bottom of the fraction. It's very easy to get the two conversion factors mixed up, so use the units as a guide. Make sure that the fraction is flipped in such a way that the original units cancel out the way you want them to.

At this point, we have established standards for discussing angles. Typically, Greek letters are used to represent angles. Also, a direction can be established by expressing an angle in standard position. In addition, you can now convert angles between degrees and radians.

Self-Assessment

Draw the following angles in standard position:

1.

120 °

2.

270 °

3.

“45 °

Convert the following angles from degrees to radians:

4.

60 °

5.

270 °

6.

45 °

Convert the following angles from radians to degrees:

7.

8.

9.

 <  Day Day Up  >  

Категории