Simple matrix data structure. More...
#include <matrix.h>
Public Member Functions | |
Matrix () | |
Constructor. | |
Matrix (const Matrix &m) | |
Copy constructor. | |
Matrix (const unsigned int rows, const unsigned int cols) | |
Creates a matrix and initializes all values to zero. | |
Matrix (const unsigned int rows, const unsigned int cols, const double v) | |
Creates a matrix and initializes all values to a default. | |
~Matrix () | |
Destructor. | |
int | Create (const unsigned int rows, const unsigned int cols) |
Creates a matrix and initializes all values to zero. | |
int | Create (const unsigned int rows, const unsigned int cols, const double v) |
Creates a matrix and initializes all values to a default. | |
int | GetDeterminant (double &d) const |
Calculates the determinant of the matrix. | |
int | GetMinor (const unsigned int row, const unsigned int col, Matrix &minor) const |
Gets the minor of the matrix. The minor is the matrix with the row and column selected blocked out. It used for finding determinants and other things. | |
int | GetInverse (Matrix &i) const |
Gets the inverse of the matrix. Matrix must be a square. | |
void | Clear () |
Sets all values to 0. | |
void | Destroy () |
Deletes all matrix data. | |
void | Print () const |
Prints matrix data to console window. | |
bool | IsSquare () const |
unsigned int | Rows () const |
unsigned int | Cols () const |
Matrix | Inverse () const |
Gets the inverse of the matrix if it is a square. | |
Matrix | Transpose () const |
Matrix & | operator= (const Matrix &m) |
Sets equal to. | |
Matrix & | operator= (const double v) |
Sets all values in the matrix equal to the constant. | |
Matrix | operator+ (const Matrix &m) const |
Adds two matrices together. Both must have the exact same dimensions. | |
Matrix & | operator+= (const Matrix &m) |
Adds two matrices together. Both must have the exact same dimensions. | |
Matrix | operator- (const Matrix &m) const |
Subtracts the matrix. Both must have the exact same dimensions. | |
Matrix & | operator-= (const Matrix &m) |
Subtracts the matrix. Both must have the exact same dimensions. | |
Matrix | operator* (const Matrix &m) const |
Mutliplies by the matrix. The current matrix columns must be equal to the parameter matrices rows. | |
Matrix | operator/ (const Matrix &m) const |
Divides by the matrix. The current matrix columns must be equal to the parameter matrices rows. | |
Matrix & | operator*= (const Matrix &m) |
Mutliplies by the matrix. The current matrix columns must be equal to the parameter matrices rows. | |
Matrix & | operator/= (const Matrix &m) |
Divides by the matrix. The current matrix columns must be equal to the parameter matrices rows. | |
double * | operator[] (const unsigned int i) |
Using this function you can index into the object using two brackets. | |
double * | operator[] (const unsigned int i) const |
Using this function you can index into the object using two brackets. | |
double & | operator() (const unsigned int row, const unsigned int col) |
Allows you to set the value at a specific [row,col] position. | |
double | operator() (const unsigned int row, const unsigned int col) const |
Allows you to set the value at a specific [row,col] position. | |
Static Public Member Functions | |
static int | GaussJordan (Matrix &a, Matrix &b) |
Performs Gauss-Jordan elimination to the two square matrices. | |
static int | GaussJordan (const Matrix &a, const Matrix &b, Matrix &x) |
Performs Gauss-Jordan elimination to the two square matrices and puts the resulting solution in x. | |
static Matrix | CreateRotationX (const double val, const bool degres=false) |
Creates a 4x4 rotation matrix around the axis. | |
static Matrix | CreateRotationY (const double val, const bool degres=false) |
Creates a 4x4 rotation matrix around the axis. | |
static Matrix | CreateRotationZ (const double val, const bool degres=false) |
Creates a 4x4 rotation matrix around the axis. | |
static Matrix | CreateScalingMatrix (const double x, const double y, const double z) |
Creates a 4x4 scaling matrix. | |
static Matrix | CreateTranslationMatrix (const double x, const double y, const double z) |
Creates a 4x4 translation matrix. | |
static void | Transpose (const Matrix &original, Matrix &transpose) |
Method for getting tranpose matrix. More memory efficient than using the other method which returns a temporary object. | |
Protected Attributes | |
double * | mpMatrix |
unsigned int | mRows |
Number of rows in matrix. | |
unsigned int | mCols |
Number of columns in matrix. | |
unsigned int | mSize |
Columns*Rows (size of array). |
Simple matrix data structure.
Definition at line 53 of file matrix.h.
Matrix::Matrix | ( | ) |
Constructor.
Definition at line 56 of file matrix.cpp.
Matrix::Matrix | ( | const Matrix & | m ) |
Copy constructor.
Definition at line 68 of file matrix.cpp.
Matrix::Matrix | ( | const unsigned int | rows, |
const unsigned int | cols | ||
) |
Creates a matrix and initializes all values to zero.
rows | Number of rows in the matrix. |
cols | Number of columns in the matrix. |
Definition at line 97 of file matrix.cpp.
Matrix::Matrix | ( | const unsigned int | rows, |
const unsigned int | cols, | ||
const double | v | ||
) |
Creates a matrix and initializes all values to a default.
rows | Number of rows in the matrix. |
cols | Number of columns in the matrix. |
v | The default value to have at each point in matrix. |
Definition at line 114 of file matrix.cpp.
Matrix::~Matrix | ( | ) |
Destructor.
Definition at line 127 of file matrix.cpp.
void Matrix::Clear | ( | ) |
Sets all values to 0.
Definition at line 543 of file matrix.cpp.
int Matrix::Create | ( | const unsigned int | rows, |
const unsigned int | cols | ||
) |
Creates a matrix and initializes all values to zero.
rows | Number of rows in the matrix. |
cols | Number of columns in the matrix. |
Definition at line 143 of file matrix.cpp.
int Matrix::Create | ( | const unsigned int | rows, |
const unsigned int | cols, | ||
const double | v | ||
) |
Creates a matrix and initializes all values to a default.
rows | Number of rows in the matrix. |
cols | Number of columns in the matrix. |
v | The default value to have at each point in matrix. |
Definition at line 180 of file matrix.cpp.
Matrix Matrix::CreateRotationX | ( | const double | val, |
const bool | degrees = false |
||
) | [static] |
Creates a 4x4 rotation matrix around the axis.
val | The amount to rotate. |
degrees | If true, val is in degrees, otherwise radians. |
Definition at line 670 of file matrix.cpp.
Matrix Matrix::CreateRotationY | ( | const double | val, |
const bool | degrees = false |
||
) | [static] |
Creates a 4x4 rotation matrix around the axis.
val | The amount to rotate. |
degrees | If true, val is in degrees, otherwise radians. |
Definition at line 693 of file matrix.cpp.
Matrix Matrix::CreateRotationZ | ( | const double | val, |
const bool | degrees = false |
||
) | [static] |
Creates a 4x4 rotation matrix around the axis.
val | The amount to rotate. |
degrees | If true, val is in degrees, otherwise radians. |
Definition at line 716 of file matrix.cpp.
Matrix Matrix::CreateScalingMatrix | ( | const double | x, |
const double | y, | ||
const double | z | ||
) | [static] |
Creates a 4x4 scaling matrix.
To make scaling uniform, just make x = y = z.
x | The amount to scale in the x axis. |
y | The amount to scale in the y axis. |
z | The amount to scale in the z axis. |
Definition at line 742 of file matrix.cpp.
Matrix Matrix::CreateTranslationMatrix | ( | const double | x, |
const double | y, | ||
const double | z | ||
) | [static] |
Creates a 4x4 translation matrix.
x | The position change in the x axis. |
y | The position change in the y axis. |
z | The position change in the z axis. |
Definition at line 765 of file matrix.cpp.
void Matrix::Destroy | ( | ) |
Deletes all matrix data.
Definition at line 557 of file matrix.cpp.
Performs Gauss-Jordan elimination to the two square matrices.
Performs the operation with the matrix in the format of a*x = b. After operation completes b is equal to the solution (x), and a is replaced by its matrix inverse.
a | The a matrix being multiplied against the solution x. A is replaced by it's matrix inverse after successful operation of function. This matrix must be a square. |
b | The solution to a*x. After successful operation b is replaced with the solution x. |
Definition at line 353 of file matrix.cpp.
Performs Gauss-Jordan elimination to the two square matrices and puts the resulting solution in x.
Performs the operation with the matrix in the format of a*x = b. After operation completes b is equal to the solution (x), and a is replaced by its matrix inverse.
a | The a matrix being multiplied against the solution x. This matrix must be a square. |
b | The solution to a*x. |
x | The solution of Gauss-Jordan elimination. |
Definition at line 526 of file matrix.cpp.
int Matrix::GetDeterminant | ( | double & | d ) | const |
Calculates the determinant of the matrix.
The matrix must be square for this to work.
d | The calculated determinant. |
Definition at line 221 of file matrix.cpp.
int Matrix::GetInverse | ( | Matrix & | i ) | const |
Gets the inverse of the matrix. Matrix must be a square.
i | The inverse of the matrix. |
Definition at line 320 of file matrix.cpp.
int Matrix::GetMinor | ( | const unsigned int | row, |
const unsigned int | col, | ||
Matrix & | m | ||
) | const |
Gets the minor of the matrix. The minor is the matrix with the row and column selected blocked out. It used for finding determinants and other things.
WARNING: The matrix dimensions must be equal (square).
row | The row to block for minor formation. |
col | The column to block for minor formation. |
m | The resulting minor matrix. |
Definition at line 280 of file matrix.cpp.
Matrix Matrix::Inverse | ( | ) | const |
Gets the inverse of the matrix if it is a square.
Definition at line 630 of file matrix.cpp.
double & Matrix::operator() | ( | const unsigned int | row, |
const unsigned int | col | ||
) |
Allows you to set the value at a specific [row,col] position.
Definition at line 1117 of file matrix.cpp.
double Matrix::operator() | ( | const unsigned int | row, |
const unsigned int | col | ||
) | const |
Allows you to set the value at a specific [row,col] position.
Definition at line 1134 of file matrix.cpp.
Mutliplies by the matrix. The current matrix columns must be equal to the parameter matrices rows.
m | The matrix to mutliply with. |
Definition at line 965 of file matrix.cpp.
Mutliplies by the matrix. The current matrix columns must be equal to the parameter matrices rows.
m | The matrix to mutliply with. |
Definition at line 1017 of file matrix.cpp.
Adds two matrices together. Both must have the exact same dimensions.
m | The matrix to add. |
Definition at line 851 of file matrix.cpp.
Adds two matrices together. Both must have the exact same dimensions.
m | The matrix to add. |
Definition at line 881 of file matrix.cpp.
Subtracts the matrix. Both must have the exact same dimensions.
m | The matrix to subtract. |
Definition at line 908 of file matrix.cpp.
Subtracts the matrix. Both must have the exact same dimensions.
m | The matrix to subtract. |
Definition at line 938 of file matrix.cpp.
Divides by the matrix. The current matrix columns must be equal to the parameter matrices rows.
m | The matrix to divide with (MUST BE A SQUARE MATRIX). |
Definition at line 1001 of file matrix.cpp.
Divides by the matrix. The current matrix columns must be equal to the parameter matrices rows.
m | The matrix to divide with (MUST BE A SQUARE MATRIX). |
Definition at line 1056 of file matrix.cpp.
Matrix & Matrix::operator= | ( | const double | v ) |
Sets all values in the matrix equal to the constant.
v | The value to use at every location in the matrix. |
Definition at line 828 of file matrix.cpp.
Sets equal to.
Definition at line 785 of file matrix.cpp.
double * Matrix::operator[] | ( | const unsigned int | i ) | const |
Using this function you can index into the object using two brackets.
Example: Matrix m(5, 5); m[0][1] = 3; m[1][2] = 4;
i | The row in the matrix to access. |
Definition at line 1100 of file matrix.cpp.
double * Matrix::operator[] | ( | const unsigned int | i ) |
Using this function you can index into the object using two brackets.
Example: Matrix m(5, 5); m[0][1] = 3; m[1][2] = 4;
i | The row in the matrix to access. |
Definition at line 1079 of file matrix.cpp.
void Matrix::Print | ( | ) | const |
Prints matrix data to console window.
Definition at line 573 of file matrix.cpp.
Method for getting tranpose matrix. More memory efficient than using the other method which returns a temporary object.
Definition at line 608 of file matrix.cpp.
Matrix Matrix::Transpose | ( | ) | const |
Definition at line 644 of file matrix.cpp.
unsigned int CxUtils::Matrix::mCols [protected] |
double* CxUtils::Matrix::mpMatrix [protected] |
unsigned int CxUtils::Matrix::mRows [protected] |
unsigned int CxUtils::Matrix::mSize [protected] |