#include <include/Matrix4.h>
Public Member Functions | |
Matrix4 () | |
Matrix4 (const Vector4 &v0, const Vector4 &v1, const Vector4 &v2, const Vector4 &v3) | |
Matrix4 & | zero () |
Vector4 & | operator[] (int n) |
const Vector4 & | operator[] (int n) const |
void | setOne (const int c, const Vector4 &v) |
void | setOne (const int c, const float v1, const float v2, const float v3, const float v4) |
void | setAll (const Vector4 &v1, const Vector4 &v2, const Vector4 &v3, const Vector4 &v4) |
void | setAll (const Vector4 *v) |
Vector4 | getOne (const int c) |
void | getAll (Vector4 &v1, Vector4 &v2, Vector4 &v3, Vector4 &v4) |
Matrix4 & | id () |
Matrix4 & | transpose () |
Matrix3 | sub (const int r, const int c) |
float | det () |
Matrix4 & | inv () |
Matrix4 & | adjoint () |
Matrix4 & | outer (const Vector4 &a, const Vector4 &b) |
Matrix4 | operator* (const Matrix4 &m) |
Vector4 | operator* (const Vector4 &v) |
Matrix4 | operator+ (const Matrix4 &m) const |
Matrix4 | operator- (const Matrix4 &m) const |
Matrix4 | operator- () const |
Matrix4 & | operator= (const Matrix4 &m) |
Matrix4 & | operator+= (const Matrix4 &m) |
Matrix4 & | operator-= (const Matrix4 &m) |
Matrix4 & | operator*= (const float s) |
Matrix4 & | operator/= (const float s) |
int | operator== (const Matrix4 &m) const |
int | operator!= (const Matrix4 &m) const |
void | print (ostream &out) const |
Friends | |
Matrix4 | operator* (const Matrix4 &m, float d) |
Matrix4 | operator* (float d, const Matrix4 &m) |
Matrix4 | operator/ (const Matrix4 &m, float d) |
ostream & | operator<< (ostream &out, const Matrix4 &m) |
This class provides storage for a 4x4 floating point table, representing a matrix. It is possible to compute determinant, inverse, transpose and other matrix operations in 4-dimensions.
A matrix is given by 4 Vector4 column vectors and has the form
Caution : When accessing a matrix element by M[i][j], i is the column index, and j the row index! In the linear algebra literature most of the time this convention is the inverse. The structure is chosen like this such that a change of basis from a coordinate system A to a coordinate system B is given by the matrix M, composed by the basis column vectors of the final coordinate system.
Matrix4::Matrix4 | ( | ) |
The default constructor initializes all matrix elements to zero.
References Vector4::zero().
Referenced by operator+(), and operator-().
Constructs a Matrix4 given three row vectors v0, v1, v2 and v3.
Matrix4 & Matrix4::zero | ( | ) |
Set all matrix elements to zero. Returns an instance to itself.
References Vector4::zero().
Vector4 & Matrix4::operator[] | ( | int | n | ) | [inline] |
const Vector4 & Matrix4::operator[] | ( | int | n | ) | const [inline] |
void Matrix4::setOne | ( | const int | c, | |
const Vector4 & | v | |||
) |
Fill matrix column c with the components of the vector v.
void Matrix4::setOne | ( | const int | c, | |
const float | v1, | |||
const float | v2, | |||
const float | v3, | |||
const float | v4 | |||
) |
Fill matrix column c from top to bottom with the values v1 to v4.
void Matrix4::setAll | ( | const Vector4 & | v1, | |
const Vector4 & | v2, | |||
const Vector4 & | v3, | |||
const Vector4 & | v4 | |||
) |
Reset the matrix by columns v1 to v4.
Referenced by id().
Put the matrix columns into the vectors v1 to v4.
Matrix4 & Matrix4::id | ( | ) |
Set the current matrix to the identity and return a reference to itself.
References setAll().
Matrix4 & Matrix4::transpose | ( | ) |
Set the current matrix to its transpose and return a reference to itself.
Columns become rows and rows become the columns. I.e, the transpose of a matrix is
Matrix3 Matrix4::sub | ( | const int | r, | |
const int | c | |||
) |
float Matrix4::det | ( | ) |
Matrix4 & Matrix4::inv | ( | ) |
Sets the current matrix to its inverse and return a reference to itself.
Given the matrix , its inverse is the matrix B, satisfying the relation
,
where is the identity matrix.
If the matrix is hardly invertible, i.e. its determinant is close to zero, then a warning is posted to the error channel and the matrix itself is not changed.
Matrix4 & Matrix4::adjoint | ( | ) |
Computes the adjoint matrix A. Replaces the currently stored matrix by A and returns a reference to it.
The transposition of the cofactor matrix is the adjoint matrix. A cofactor is given by :
,
where is the matrix obtained by erasing line and column .
References Matrix3::det(), and sub().
Referenced by inv().
Computes the outer product between a vector a and a vector b and stores the result in the current Matrix4 object.
Formally we have the product between a column vector a with a row vector b.
Referenced by Vector4::reflect().
Multiplies the current matrix on the right hand side by m and returns the result as a new Matrix4 instance.
Applies the current matrix on the left side of a column vector v and returns a vector with the result.
Matrix4 Matrix4::operator- | ( | ) | const |
Assign operator. Makes a copy of m. Returns an instance to itself.
Adds the matrix m to the current one. Returns an instance to itself.
Substracts the matrix m from the current one. Returns an instance to itself.
Matrix4 & Matrix4::operator*= | ( | const float | s | ) |
Multiplies all the elements of the current matrix by s and returns\ an instance to itself.
Matrix4 & Matrix4::operator/= | ( | const float | s | ) |
Divides all the elements of the current matrix by s and returns\ an instance to itself.
int Matrix4::operator== | ( | const Matrix4 & | m | ) | const |
Compare the current matrix to m. If all the elements are the same, the function return 1, 0 otherwise.
int Matrix4::operator!= | ( | const Matrix4 & | m | ) | const |
Compare the current matrix to m. Returns 1 if they are different. 0 if they are the same.
void Matrix4::print | ( | ostream & | out | ) | const |
Prints the components of this matrix in a formated way onto the stream out.
Multiplies every element of the matrix m by a factor of d. and returns a Matrix4 object.
Multiplies every element of the matrix m by a factor of d. and returns a Matrix4 object.
Divides every element of the matrix m by d. and returns a Matrix4 object.
ostream & Matrix4::operator<< | ( | ostream & | out, | |
const Matrix4 & | m | |||
) | [friend] |