Maths stuff and code snippets

ArcTangent
This is used to find the angle of a position around a given point (say 0,0) Given coordinate x and y: Tan^-1 (y/x) * 180/PI

Matrix Addition
This really is pretty simple. Simply add the corresponding position value in the second matrix to the first:

1 3 7 -4 3 2
2 6 -2 1 6 5

Adding these together yields the same dimensional size matrix:

(a1+a2) (b1+b2) (c1+c2)
(d1+d2) (e1+e2) (f1+f2)

(1+-4) (3+3) ( 7+2)
(2+ 1) (6+6) (-2+5)

-3 6 9
3 12 3

3D Distance
Given 2 vectors, the distance between them, given as a scalar, is calculated as:

float DistanceBetweenVectors(D3DXVECTOR3 vec1, D3DXVECTOR3 vec2)
{
return sqrt( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 )
}

Dot Product
This one is quite important in game maths, used for all sorts
To get the angle between two vectors:

float GetAngleBetweenVectors(D3DXVECTOR3 vec1, D3DXVECTOR3 vec2)
{
return acos ( (vec1*vec2) / (length(vec1)*length(vec2)) );
}

Trig Rules - good to remember!
SOHCAHTOA and SHOCHATAO
That is -
Sin(A) = Opposite / Hypotenuse
Cos(A) = Adjacent / Hypotenuse
Tan(A) = Opposite / Adjacent

aSin(A) = Hypotenuse / Opposite
aCos(A) = Hypotenuse / Adjacent
aTan(A) = Adjacent / Opposite

Cos rule:
a^2 = b^2+c^2-( 2bcCOS(A) )

Sin Rule:
a /sin A = b / sin B = c / sin C
OR
sin A / a = sin B / b = sin C / c

No comments: