Graphics Programs Reference
In-Depth Information
Referring to Figure 5.15, we see that we can construct a right triangle from the origin
(0,0) to the point (x,y). With that, we can apply the definitions of sine and cosine above
to write
sin(angle) = opposite / hypotenuse = y / r
cos(angle) = adjacent / hypotenuse = x / r
-Y
(0,0)
x
-X
+X
angle
y
r
(x, y)
+Y
Figure 5.15 Calculating a point on a circle
If we multiply both sides of each of the equations by r we then get
x = r * cos(angle)
y = r * sin(angle)
and in ActionScript we would write
x = r * Math.cos(angle);
y = r * Math.sin(angle);
There, that wasn't too bad, and in a perfect world, it would be nice to say that we're
done. Unfortunately it's not a perfect world. Why? Because we started out by knowing
our angle in degrees, but ActionScript, like most computer languages, wants to have its
trig function angles in radians. We will need one additional line that converts our angle in
degrees to an angle in radians.
a = angle * Math.PI / 180;
x = r * Math.cos(a);
y = r * Math.sin(a);
 
Search WWH ::




Custom Search