Trigonometry  v1-01-2000  Release 1.01 © RTCM Cyborg

Introduction | What is trigonometry? | What's so good about them? | Excuse me!?

Introduction

Not more maths...
I'm afraid so, but if you're hoping to gleem some idea of how to program new features for Eduke you really are gonna have to brush up on your maths.

What is trigonometry?

What is trigonometry?
Trigonometry is all about triangles. Mainly the ratio's of the lengths of sides and of angles. The main trig functions being sine, cosine and tangent.

What's so good about them?

What's so good about them?
Well, in the Eduke section I wrote out a plan for the sort of code I would need to write out to allow actors to act in a particle like way in Duke Nukem 3D using vectors to describe the acceleration and velocities of the particles. To convert these vectors into specific directions in Build angles I need to use the sine and cosine functions.

Excuse me!?

Excuse me!?
Okay, I can see you are now utterly lost. So here's an explanation of the sine and cosine functions and why they are so useful with vectors.
Here's a right angled triangle:



It's called a right angled triangle because of it's angles is 90 degrees, exactly 1/4 of the degrees in a circle (the right angle is represented by the square, the arc representing one of the other angles in the triangle). In a right angled triangle the sides are given names relating to one of the two other angles in the triangle. The side next to the angle is called the adjacent side. The side opposite the angle is called the opposite side. The side opposite the right angle is called the hypotenuse and is always the longest side in a triangle.

The sine function of an angle is defined as being the ratio of the opposite side to the hypotenuse. The cosine function of an angle is defined as being the ratio of the adjacent side to the hypotenuse. You might be able to see from the diagram that the sine of one angle is the cosine of the other and vice versa. The tangent is defined as being the ratio of the opposite side to the adjacent side. You may also realize here that the sine of an angle divided by the cosine of the same angle will also give you the tangent of the angle.

The inverse of these functions are known as arcsine, arcosine and arctangent. Applying a ratio of sides to these functions will give you an angle back for that function.

e.g, sin 45 = 0.707, arcsin 0.707 = 45 (N.B. it is important that when calculating these values you know what you are measuring angles in, common measurements being degrees and radians).
e.g, sin 45 = 0.707, cos 45 = 0.707, sin/cos = 1, tan 45 = 1.

Now have a look at this diagram of a vector:



The number represents the length of the line, depending on what units the graph takes it could represent a force, velocity or acceleration.

We can draw a triangle from this vector:



And add trig functions:



From a vector pointing in any old direction I can get the extent to which it is moving in the x direction and the extent to which it is moving in the y direction using the sine and cosine functions. And in the opposite sense, if I define a vector in terms of units of x and units of y I can express this as a single vector with an anglular displacement from a origin and a magnitude of movement. In my eduke alpha code I used the functions to define a strafing amount for actor movement in the perpendicular sense to its direction and a forward/backward amount in the sense of which it is facing. The idea is that if your actor has been hit by a force that moves him left he will still move himself as a lizard trooper might now but if the trooper turns to the left the force will now be acting in a strafing manner to the trooper so the trooper will strafe to match the expected movement. If the trooper tries to move in another direction the rather than just moving in this direction the force of movement is sent to the particle routine and the actor is returned the values which he should move by.

I'm still confused!
Well, talk to me and I'll explain it more. Your question will be added here.