# Trigonometry

When I promoted this course, I informed you that I was going to reinforce your math skills. The good part of this lesson is that ALL games that deal with collision need to make use of trig rations in order to make them realistic.

When I was in high school, trig was all about looking up trig ratios at the back of the book and then applying them to a problem. In this course, you will be using trig ratios to make a ball go in the direction that you point at. I cannot think of a better way to use and truly understand trig at the high school level.

Let me quote Keith Peters, author of *Actionscript 3.0 Animation*: "with trigonometry, you are hardly dealing with numbers at all... you are dealing with variables containing ositions, distances, and angles. It's mostly about memorizing various relationships... In fact, 90% of the trig you need for basic animation will come down to two functions: Math.sin and Math.cos." p. 52

Trigonometry is the study of triangles and the relationship of their sides and angles.

**Radians vs. Degrees:**

A radian is equal to approximately 57.3 degrees. Here's what wikipedia as to say about radians. 360 degrees equals 2*pi*radians. Why do you have to know this? To rotate an object, you need to know the value in degrees, but to figure out motion, you need to use trig with radians. Yes, you will have to be moving between degrees and radians and back again in order to make motion games work. Here are the conversion formulas:

dRadians = dDegrees*Math.PI/180;

dDegrees = dRadians*180/Math.PI;

All this links to the original identitt that I shared above: 360 degrees = 2*pi*radians.

**Coordinates revisited:**

Please revist my note in the Graphic Loop note about coordinates (called x and y orientation). Remember the point of origin is the upper left. This is important because on a traditional Cartesian plane, angles are measure *counterclockwise*. Since in Flash, the point of origin is in the upper left, angles are measured *clockwise*. Back to trig:

**Sine:**

The sine of an angle is the ratio of the angle's opposite side over the hypotenuse. The Math.sin() funtion will return the value of the sine ratio for a given angle - *in radians*. If you want to get the sine for an angle of 15 degrees, you will do the following:

dSin = Math.sin(15 * Math.PI/180);

**Cosine:**

The cosine of an angle is the ratio of the angle's adjacent side over the hypotenuse. The Math.cos() funtion will return the value of the cosine ratio for a given angle - *in radians*. If you want to get the cosine for an angle of 15 degrees, you will do the following:

dCos = Math.cos(15 * Math.PI/180);

**Tangent**: This is the ratio of the opposite side over the adjacent. It is used less frequently than the first two. Math.tan() is the function that is used.

**Arcsine and arccosine:**

These functions allow you to retrieve the angle (in radians) for a given trig ratio. For example, to get the angle, given the sine value of dSin you would do the following:

dRad = Math.asin(dSin); // get the angle in radians

dDeg - dRad*180/Math.PI; // convert the angle from radians to degrees.