A little of the math that every game programmer should known PART 1
Finding the distance between two points:
take a look on this triangle (ac,ab,bc)

to find the distance 'a' between the points ac and ab, we'll simply use the theorem of our friend Pythagoras: a² = b² + c²
As you might known we're on a cartesian xy-plane so the 'c' edge is the delta from the x values of ac and bc aka ac.x and ab.x, and b is the delta from the y values, ac.y and ab.y
as you can on the image:

float dx = P1.x - P2.x; float dy = P1.y - P2.y; float distance = sqrtf(dx*dx+dy*dy);or on a 3d coordinate system:
float dx = P1.x - P2.x; float dy = P1.y - P2.y; float dz = P1.z - P2.z; float distance = sqrtf(dx*dx+dy*dy+dz*dz);
Magnitude of a vector
A vector normally has two points, one for the head and the other for the tail, on game development we often work just with the head one, and the tail is considered to be the zero point. So, to calculate the magnitude of a vector we'll again use the theorem of pythagoras and calculate the distance between head and tail, but as said, on this case the P2 has just zero values so we'll not compute it.
float dx = P1.x;// - P2.x;
float dy = P1.y;// - P2.y;
float dz = P1.z;// - P2.z;
float magnitude = sqrtf(dx*dx+dy*dy+dz*dz);
//often written as
float magnitude = sqrtf(P1.x*P1.x+P1.y*P1.y+P1.z*P1.z);
Next:
- Dot Product aka Scalar Product
- Cross Product

Add new comment