programming / C++ / sailing / nerd stuff
C++ Basic Linear Algebra Classes

## vector2

Useful class when dealing in two dimensional space (R2). Completely inline for better performance.

## vector3

This class provides a big set of features needed when calculating with vectors in third space, in R3. This class is implemented completely inline for better performance.

The methods should be self explained. Example:

 ```1 2 3 4 5 ``` ``````vector3 a(...), b(...), c(...); // corners double area = (b-a).dot(c-a) * 0.5; // solution 1 double area = (b-a) * (c-a) * 0.5; // solution 2 vector3 n = (b-a).cross(c-a); // normal vector on surface``````

## vector4

Similar to the vector2 and vector3 classes but have four components. It is implemented completely inline as well.

## vectorn

This is a template, you may choose the size of the vector when using it.

Example:

 ```1 2 ``` ``````vectorn<3> a; a[0]=1.0; a[1]=2.0; a[2]=3.0; a *= 0.5;``````

## matrix2

Provides a class with many method for 2x2 matrices. It works together with the vector2 for some functions.

Example: Equation-System: A is a matrix with coeffitients, `y` is the known solution vector. `x` is the vector we're looking for.

$A * \underline{x} = \underline{y} ~~~ \Rightarrow ~~~ A^{-1} * A * \underline{x} = A^{-1} * \underline{y} ~~~ \Rightarrow ~~~ \underline{x} = A^{-1} * \underline{y}$

All we need is the inverse matrix A-1 to get the solution.

 ```1 2 3 4 ``` ``````vector2 y(...); matrix2 A(...); vector2 x = A.inv() * y;``````

## matrix3

Similar to matrix2 but for 3x3 matrices. Works together with vector3, of course.

## matrix4

Similar to matrix2 but for 4x4 matrices. Works together with vector4.

## matrixn

Similar to matrix2 but for NxN matrices. Works together with vectorn. This class is also a template to let you choose the size. You can define N, the size of the matrix will be NxN.

## quaternion

This is an implementation of a quaternion $(w,x,y,z)$. It is working tight with the class vector3. The implementation itself is as much inline as possible to get a good performance.

Example (rotation of a vector arround an arbitrary axis):

 ```1 2 3 4 5 6 ``` ``````vector3 p(...); // the vector vector3 u(...); // the rotation axis double angle = 30.0; // the rotation angle in degrees quaternion q(angle, u); q.rot(p); // rotate vector p``````

The short form of this example would be:

 ```1 2 3 ``` ``````vector3 p(...); quaternion(30.0, vector3(...)).rot(p); // temporary objects!``````

This quaternion class can do much more, of course (have a look at the header file)!