# G1. Trigonometry{twn}

Go back

> Truth is, most games are played in continuous space, where geometry matters. Math classes turn out to be not so useless after all. But even if you don't know your numbers well, you can compose functions by their meaning, and not number logic. This page will try to help you with that, providing examples.

the Hell are Vectors

> There are distinct meanings they posses: position in space, travel between points and direction. Often you need to juggle those representation around.

> For example, player and enemy positions by themselves don't tell you anything about their spatial relation. For that you need to compute the difference between them, which is plain per component subtraction. Resulted direction of travel depends on order of inputs, - it will point to position on the right side, the one you subtract with, but not from.

> It's important to understand that after subtraction the travel vector doesn't have relation with original positions, it is effectively in a subspace, where (0,0,0) is at position you subtracted with to get it. Operation is reversible by means of addition, resulting in position in space once again.

> I often forget what the direction is pointed at but here's a quick way to remind yourself: take two numbers, 10 and 0, and try subtracting them in different order. Sign of result will tell you which part is pointed at, +10 -> direction is to the 10, -10 -> direction is to the 0. (Draw it in your head)

> Sometimes direction is more important than the travel, for which you need to drop the length of it. This is called normalization, where result is called a normal (You probably heard those terms). This is achieved by dividing every component by the length (magnitude) of vector itself. Length is computed as sqrt(x*x, y*y, z*z). This effectively creates a vector of length 1. As every direction sized the same, when graphed they trace a circle.

Center between two points

> Method one. Add two positions and divide them by two: (a + b) / 2. This is cheap, but harder to remember.

> Method two. Find the travel between points, divide it by two and then translate the origin: (a + (a - b) / 2)