C++ Basic Linear Algebra Classes
/ Mario Konrad
Useful class when dealing in two dimensional space (R2). Completely inline for better performance.
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:
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
Similar to the vector2 and vector3 classes but have four components. It is implemented completely inline as well.
This is a template, you may choose the size of the vector when using it.
vectorn<3> a; a=1.0; a=2.0; a=3.0;
a *= 0.5;
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.
All we need is the inverse matrix A-1 to get the solution.
vector2 x = A.inv() * y;
Similar to matrix2 but for 3x3 matrices. Works together with vector3, of course.
Similar to matrix2 but for 4x4 matrices. Works together with vector4.
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.
This is an implementation of a quaternion . 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):
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:
quaternion(30.0, vector3(...)).rot(p); // temporary objects!
This quaternion class can do much more, of course (have a look at the header file)!