Trigonometry

Trigonometry is best explained in the context of a unit circle, that is, the radius of the circle is one. Cutting the circle in half horizontally and vertically gives us a coordinate system. Each vector drawn from the origin can then be measured in three ways to represent the angle from the x axis which are degrees, turns, and radians.

Degrees, Turns, and Radians

DegreesTurnsRadians (τ)Radians (π)
0000
451/81/8τ1/4π
901/41/4τ1/2π
1353/83/8τ3/4π
1801/21/2τπ
2255/85/8τ5/4π
2703/43/4τ3/2π
3157/87/8τ7/4π
3601τ

Degrees is the most well known of the three where 360 degrees would be the full circle.

Turns are represented in fractions of a turn. A full turn would be around the circle which would be one while a half turn would be half the circle or one half.

Radians are defined by the the relationship of the arc length of a circle and its radius being equal. When you go around the circle using this arc length, the result is a little bit over six arcs. This number (6.28…) is known as Tau or two PI. Tau is to radius and PI is to diameter when talking about ratios to the circumference of a circle. Subjectively speaking, Tau is more intuitive as it directly correlates with the concept of turns as shown in the table above. With PI, everything must be doubled. Radians is also useful for calculating the arc length by multiplying the radius by the angle in radians.

For the next sections, the mnemonic SOH CAH TOA is useful in remembering what the definitions of sine, cosine, and tangent are as well as what they can solve.

Cosine

The cosine of an angle gives the x coordinate of a vector per definition of adjacent over hypotenuse. This is because the hypotenuse is the radius and the radius in a unit circle is one so it is just the adjacent side. In addition, the definition of a cosine of an angle is equivalent to the dot product of two normalized vectors.

Sine

The sine of an angle gives the y coordinate of a vector and the reasoning is the same as cosine. The definition of a sine of an angle is equivalent to the determinant of two normalized vectors when working in 2D space. The determinant is useful for checking if something is to the right or left and is calculated by the formula (a.x * b.y) - (a.y * b.x) where a and b are vectors.

Tangent

The tangent of an angle gives the length that is tangent to the circle. This is the line that extends at a 90 degree angle from the point on the arc of the circle towards a point on the x axis.

The graphs of these functions show the relationship with the unit circle as both cosine and sine are cyclic as they go around the circle while tangent goes to infinity as it becomes parallel to the x axis at 90 and 270 degrees.

Inverse

The inverse functions are prefixed with arc and are used to find the angle. For sine and cosine it is ambiguous when using the inverse functions as there are an infinite number of answers therefore it is usually defined to return within a range from 0 to 180 degrees. There are an infinite number of answers because the inverse function rotates it 90 degrees and since it is cyclic, multiple angles will have the same result (drawing a vertical line will prove this). As a result, arctan2 is usually used to get the actual angle. For example, tan(θ) = y/x and arctan2(y, x) = θ.

Unity

In Unity, the trigonometric functions are found in the Mathf struct. To go from angle to vector, Sin and Cos is used and to go from vector to angle Atan2 is used.