Beginning Math and Physics for Game Programmers
< Day Day Up > |
Now that we've defined the six trigonometric functions, several trig identities (or rules) allow you to algebraically manipulate equations that have the trig functions embedded in them. You never know when these identities might prove useful. Remember that when you're programming, every operation takes additional processing time, so always try to reduce formulas to their simplest terms. Of course, this might involve one or more of these identities. The first identity is the unit circle , which is the circle centered at the origin with a radius of 1. The equation for the unit circle is x 2 + y 2 =1. For any point on the unit circle, you can create a right triangle with one angle in standard position, as shown in Figure 3.15. Figure 3.15. The unit circle.
Notice that the hypotenuse is the radius, which has a length of 1 unit. Now you can apply the definitions of sine and cosine: sin a = y /1 = y and cos a = x /1 = x so y = sin a and x = cos a This is true for any point on the unit circle.
NOTE This is a great trick for remembering the sine and cosine of multiples of 90. At 90, 180, 270, and 360, the unit circle intersects the axes, so it's very easy to pick off the x and y coordinates, which give you sine and cosine. For example, at 90, the unit circle has coordinates (0,1). Therefore, sin90=1 and cos90=0.
Now that you know y = sin a and x = cos a , you can substitute sine and cosine into the equation of the unit circle for x and y . This gives you your first trig identity.
There's also a very interesting relationship among tangent, sine, and cosine. If you look back at the definitions of the first three trigonometric functions, you'll see that sin a = opp/hyp and cos a = adj/hyp This means that, This leads to the next two identities.
There are also a couple interesting negative angle identities. Try plugging a couple angles into your calculator to verify that they're true.
Example 3.12: Verifying One of the Negative Angle Identities
Using a = 30, verify that sin( a ) = sin a . Solution
Next let's look at the sum and difference identities for sine.
Example 3.13: sin(90+ a )
Simplify sin(90+ a ). Solution
Example 3.14: sin(180 a )
Simplify sin(180 a ). Solution
The cosine has very similar sum and difference identities.
Example 3.15: cos(180+ a )
Simplify cos(180+ a ). Solution
Example 3.16: cos(90 a )
Simplify cos(90 a ). Solution
This section contains quite a few trig identities, from the unit circle identity all the way through the sum and difference identities. As a programmer, you should know that the trigonometric functions are fairly expensive (they take more processing power than a simple multiply or add function), so your goal should always be to minimize the number of trig functions called in your code. The next section looks at the syntax for actually using these functions in C++. Self-Assessment
|
< Day Day Up > |