Table of Contents
### Calculating Angles with the Math Object

Entire Site

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 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: