Knowing the length of any two sides of a right triangle is enough information to calculate the other two sides of the right triangle. This is useful when you need to find the cosine, sine, and tangent of a triangle. So, why do you need to find the cosine, sine, and tangent of a triangle. The answer is simple, to calculate points around a circle. If you have not figured it out yet getting the cosine and sine of a point will give the location in radians of a point on a circle in flash. Next you will see why this is useful, I am sure you can image why.

Before I go on, consider what purpose the flash math functions below (in dark gray box) would serve you as you work with angles, triangles, cosine, and sine. Also review the relationship of sine, cosine, and tangent in the image below.

THIS IS VERY IMPORTANT: Most likely you will know the lengths of the opposite and adjacent sides of the triangle because they represent the y and x coordinates of a point. See if you can make sense of this by studying the image below.

Math.Atan2(y, x);........calculates the angle (in radians) from the x-axis to a point on the y-axis.
Math.cos(angle);.............................................calculates the cosine of an angle in radians
Math.sin(angle);..............................................................calcualtes the sine of an angle in radians
Math.round(number);.....rounds the number to the nearest interger Ex. math.round(5.16) returns 5
Math.Sqrt(any number);.............................................................calcuates the square root
Math.PI( )....................................the circumference of a circle divided by its diameter


All right, here it is, if we know the angle of a right triangle and we use the math functions in flash actionscript cos( ) and sin( ) we can calculate the circular path around a circle. Above I showed how to get the angle of an object on the flash stage. For now we will just pick at random angle of 45 degrees. Given this angle we calculate the coordinates where an angle will intersect with a circle. This mean that we we will be a calculate a circular path around a central point or origin.

IMPORTANT: Remember that radius is the distance from the center of a circle to the edge of the circle. And that cosine represents the horizontal (x) and sine the vertical (y) value of the Cartesian coordinate system

Your goal is to find what the x and y coordinate are for the center of the orange circle below.

Remember that you must first change you angle into radians because we are talking about a 45 degree angle, but flash sees it in radians not degrees. The following code is an example of actionscript that will convert the angle into radians and then by using the math functions cos( ) and sin ( ) return the (x, y) coordinates of the orange circle below.

var degrees=45;
radians = degrees* (Math.PI/180);
xcoordinate = radius * cos(radians);
ycoordinate = radius * sin(radians);

OK, let me try and explain the image below. The radius determines how big the path will be that the orange circle will follow. The angle determines where on the circular path the orange circle will be angled at a given point according to the origin or center of the Cartesian system (0,0). By using the cos( ) to find the x coordinate and sin( ) for the y coordinate we will have the exact (x,y) coordinates for the orange circle on the circular path (light gray circle). Did you follow that? Think about this. If I as to add 2 degrees to the the angle I would have 47 degrees. That means my variable degrees in the above actionscript would change the location of the orange circle to 2 more degrees clock wise around the light gray circle. If I was to continually add 2 degrees to the current degree variable the orange circle would be rotation around the origin continually and also continually be following the light gray path. In the next example I actually did this in flash. Note also that the circle is rotation around the z axis, more on this later.


The following code is placed on a movie clip in flash call "ball" with a graphic of a orange ball on its timeline. The only other movie clip in the flash file is a clip called "center_cross_hairs". The clip "center_cross_hairs" is used to reference a point or origin in the center of the movie. If you don't know why this is review the start of this tutorial. If I did not use the "center_cross_hairs" clip flash would think (0,0) is located in the top left-hand corner. Remember to name your movie clips in the flash environment for reference in actionscript.