• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 11. Manipulating Information > Calculating Angles with the Math Class

Calculating Angles with the Math Class

The angle that an object makes relative to the Stage or to another object is useful information for creating many game interactions, as well as for creating dynamic animations and interfaces based purely in ActionScript. To create a dial that controls the sound volume, for example, you need to compute the angle at which your viewer drags the dial relative to the horizontal or vertical axis and then change the dial’s rotation and the sound’s volume accordingly. Calculating the angle also requires that you brush up on some of your high-school trigonometry, so a review of some basic principles related to sine, cosine, and tangent is in order.

The mnemonic device SOH CAH TOA can help you keep the trigonometric functions straight. This acronym stands for Sine = Opposite over Hypotenuse, Cosine = Adjacent over Hypotenuse, and Tangent = Opposite over Adjacent (Figure 11.1). Knowing the length of any two sides of a right triangle is enough information for you to calculate the other two angles. You will most likely know the lengths of the opposite and adjacent sides of the triangle because they represent the y and x coordinates of a point (Figure 11.2). When you have the x and y coordinates, you can calculate the angle (theta) by using the following mathematical formulas:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint