Graphics Programs Reference
In-Depth Information
Tip: How would you change the script so that a different random answer comes up
each time you click the pendulum? Use the relationship between the answer to this
movie and its frequency angle update to guide you.
The Inverse Trig Functions
Sine, cosine, and tangent have inverse functions called arcsine, arccosine and arctan-
gent. In general, you use sine, cosine, and tangent when you know an angle and want
to calculate lengths or distances. You use arcsin, arccos, and arctan when you know
lengths or distances and want to calculate the corresponding angle in radians. The arctan
is generally used more than the other two functions. In fact, ActionScript has a special
second arctan function, Math.atan2(y,x) , that comes in handy most often. This gives
the angle whose tangent (opposite/adjacent) is y/x.
-Y
(0,0)
x
-X
+X
angle
y
r
(x, y)
+Y
Figure 5.28 Calculating the angle of a point on a circle
Let's quickly look at how we might use atan2 . Suppose we know that we are at some
point (x,y) on a circle as shown in Figure 5.28. We might want to know some informa-
tion about that circle such as the angle, in degrees, that we are at on the circle. Here's
what we need.
a = Math.atan2( y, x )
angle = a * 180 / Math.PI
Figure 5.29 Formula for the angle of a point on a circle
 
Search WWH ::




Custom Search