Trigonometry is a branch of mathematics which consists of the study of right-angled triangles — specifically, the ratios of sides of right-angled triangles. Trig (short for trigonometry) functions simply return the ratio of a certain two sides of a triangle, given one angle; or the angle given a ratio of two sides. The point of trigonometry is to be able to quickly relate angles to side lengths and vice-versa to do otherwise complex calculations. For example, finding out the new position of a sprite after it has moved some distance given its direction is impossible without trigonometry.
Basically, trigonometry is a shortcut to find relations that can be theoretically measured. It is a powerful tool, and has applications in all sorts of fields.
|Note:||This article is intended for an audience with some background in math, especially algebra and geometry.|
There are three major trig functions. To define them, we use the following names for sides:
|Warning:||These are relative to angle A. The names change depending on the angle you consider.|
- The Sine (sin) is the Opposite ÷ Hypotenuse
- The Cosine (cos) is the Adjacent ÷ Hypotenuse
- The Tangent (tan) is the Opposite ÷ Adjacent
To remember these functions, some people use "Soh cah toa", a simple acronym.
We express a trig function as, for example, sin(45°) or cos(60 rad).
|Note:||"rad" stands for Radians, another unit of angles where 2π radians = 360°, and 1 radian = 180/π degrees.|
There are also three minor trig functions:
- The Secant (sec) is the reciprocal of the cosine.
- The Cosecant (csc) is the reciprocal of the sine.
- The Cotangent (cot) is the reciprocal of the tangent.
Reciprocal of any value is simply 1 divided by the value.
Finally, the arcsin, arccos, arctan, arcsec, arccsc and arccot are the reverse of their respective trig functions; they convert a trig ratio to the angle. For example, arctan(1) = 45° implies that tan(45°) = 1. However, you may also see these as sin-1, cos-1, tan-1, sec-1, csc-1, and cot-1. They mean the same thing.
Using Trigonometric Functions: Example
Trig functions have many uses in programming, especially in graphics and physics simulations. For example, consider a rock thrown at 30° at 5m/s. To model the parabolic (curved) path of the rock, we need to split the tilted velocity into a horizontal and vertical velocity, then move the sprite by those values in the respective directions repetitively. Also, we need to constantly decrement the vertical velocity to account for gravity.
To split the values, we use trigonometry. We image a right triangle with one angle 30° and hypotenuse 5m/s. Now, the opposite side must be the vertical velocity and the adjacent side must be the horizontal velocity. To find the opposite side, we find the sine of 30°, which is opposite/hypotenuse. We then multiply it by the hypotenuse (i.e. 5m/s). The result, using a calculator to evaluate sin(30°)*5 is 2.5m/s. We can use similar reasoning to find the horizontal velocity using sin(30°).
|Warning:||Note that in some calculators, such as Google Calculator, you must specify degrees, since it assumes radians. However, Scratch always uses degrees, as does Wolfram Alpha.|
You are encouraged to attempt each of these to learn more about trigonometry.
- Using atan to find the direction the mouse is moving in—find the atan of the ratio of X motion and Y motion at any given point in time, and you should get the direction in which it is moving.
- Using atan to make a block called "point towards x:() y:()"—use similar reasoning as the above
- Using a script like the following to make a sprite move in complex paths:
when gf clicked forever change [a v] by (1) go to x: ((100)*([sin v] of (a))) y: ((50)*([cos v] of (a)))
Once of the great things about trigonometric functions is that they are all cyclic, which means they keep repeating. So you can get complex motions which repeat indefinitely without too much trouble.
- Predicting the position of a sprite after it moves some distance in a specific direction—this is a simple application of sine and cosine. One interesting use of this is to make a sprite move perpendicular to the direction it is facing in, or move in a circle without changing its direction.
- Modeling 3D rotations—this is a much more advanced application of trigonometry. It relies on the principle that any point in 3D, when rotated through some angle, will appear to move straight to a viewer (imagine staring at a single point on a spinning globe). The distance moved can be calculated with some more complex trigonometry.
Angles Greater than 90°
Angles greater than 90 degrees have trig functions, too. In fact, the sin, cosine, secant, and cosecant of and angle A are the same as the respective function of A%180 (i.e. the remainder obtained when A is divided by 180). This holds for negative values of A, too. For tangent and cotangent, the value is A%90. The proofs of these are obvious if one looks at the sine wave or sinusoid, where the wave repeats every 2pi=180° times. The same applies to the other functions, with different graphs but the same principle.
For Non-Right Triangles
Trigonometry is not just used with right triangles. The following equations apply to all triangles.
|Note:||Here, a,b,c and lengths of sides, and A,B,C are measures of angles opposite sides a,b, and c respectively.|
The law of sines
<<((a) / ([sin v] of (A))) = ((b) / ([sin v] of (B)))> = ((c) / ([sin v] of (C)))
This identity is extremely useful to relate sides of triangles and angles. More importantly, though, it also relates the circumradius of the given triangle. The circumradius is the radius of the circle in which the triangle fits perfectly (each vertex lies on the circle).
The law of cosines
<((c) * (c)) = (((a) * (a)) + (((b) * (b)) - ((2) * ((a) * ((b) * ([cos v] of (C)))))>
The obvious use of this surprising but true identity is to find the third side of a triangle given any two sides and the distance between them, or finding the angles given three sides. This has many interesting uses, for example: If you have a spaceship-shooting game like asteroids, you can program the AI spaceships to aim towards the point where the target will be when the bullet hits it (since during the time taken for the bullet to move, the spacecraft themselves change position linearly).
The law of tangents
To find the area of a triangle
(Here, α, β, and gamma mean A, B, and C):
This identity is used to derive some of the above.