Public Member Functions | Static Public Member Functions | Protected Attributes

CxUtils::Matrix Class Reference

Simple matrix data structure. More...

#include <matrix.h>

List of all members.

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
Matrixoperator= (const Matrix &m)
 Sets equal to.
Matrixoperator= (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.
Matrixoperator+= (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.
Matrixoperator-= (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.
Matrixoperator*= (const Matrix &m)
 Mutliplies by the matrix. The current matrix columns must be equal to the parameter matrices rows.
Matrixoperator/= (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).

Detailed Description

Simple matrix data structure.

Definition at line 53 of file matrix.h.


Constructor & Destructor Documentation

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.

Parameters:
rowsNumber of rows in the matrix.
colsNumber of columns in the matrix.
Returns:
0 If failed to create matrix, otherwise 1.

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.

Parameters:
rowsNumber of rows in the matrix.
colsNumber of columns in the matrix.
vThe 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.


Member Function Documentation

void Matrix::Clear (  )

Sets all values to 0.

Definition at line 543 of file matrix.cpp.

unsigned int CxUtils::Matrix::Cols (  ) const [inline]

Definition at line 81 of file matrix.h.

int Matrix::Create ( const unsigned int  rows,
const unsigned int  cols 
)

Creates a matrix and initializes all values to zero.

Parameters:
rowsNumber of rows in the matrix.
colsNumber of columns in the matrix.
Returns:
0 If failed to create matrix, otherwise 1.

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.

Parameters:
rowsNumber of rows in the matrix.
colsNumber of columns in the matrix.
vThe default value to have at each point in matrix.
Returns:
0 If failed to create matrix, otherwise 1.

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.

Parameters:
valThe amount to rotate.
degreesIf true, val is in degrees, otherwise radians.
Returns:
The new matrix.

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.

Parameters:
valThe amount to rotate.
degreesIf true, val is in degrees, otherwise radians.
Returns:
The new matrix.

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.

Parameters:
valThe amount to rotate.
degreesIf true, val is in degrees, otherwise radians.
Returns:
The new matrix.

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.

Parameters:
xThe amount to scale in the x axis.
yThe amount to scale in the y axis.
zThe amount to scale in the z axis.
Returns:
The new scaling matrix.

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.

Parameters:
xThe position change in the x axis.
yThe position change in the y axis.
zThe position change in the z axis.
Returns:
The new translation matrix.

Definition at line 765 of file matrix.cpp.

void Matrix::Destroy (  )

Deletes all matrix data.

Definition at line 557 of file matrix.cpp.

int Matrix::GaussJordan ( Matrix a,
Matrix b 
) [static]

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.

Parameters:
aThe 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.
bThe solution to a*x. After successful operation b is replaced with the solution x.
Returns:
1 If process completed successfully, otherwise 0.

Definition at line 353 of file matrix.cpp.

int Matrix::GaussJordan ( const Matrix a,
const Matrix b,
Matrix x 
) [static]

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.

Parameters:
aThe a matrix being multiplied against the solution x. This matrix must be a square.
bThe solution to a*x.
xThe solution of Gauss-Jordan elimination.
Returns:
1 If process completed successfully, otherwise 0.

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.

Parameters:
dThe calculated determinant.
Returns:
1 if able calculate determinant, otherwise 0.

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.

Parameters:
iThe inverse of the matrix.
Returns:
1 If process completed successfully, otherwise 0.

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).

Parameters:
rowThe row to block for minor formation.
colThe column to block for minor formation.
mThe resulting minor matrix.
Returns:
1 If minor was extracted, otherwise false.

Definition at line 280 of file matrix.cpp.

Matrix Matrix::Inverse (  ) const

Gets the inverse of the matrix if it is a square.

Returns:
Matrix inverse.

Definition at line 630 of file matrix.cpp.

bool CxUtils::Matrix::IsSquare (  ) const [inline]

Definition at line 79 of file matrix.h.

double & Matrix::operator() ( const unsigned int  row,
const unsigned int  col 
)

Allows you to set the value at a specific [row,col] position.

Parameters:
rowThe row in the matrix [0,Rows()).
colThe column in the matrix [0, Cols()).
Returns:
The value at [row,col].

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.

Parameters:
rowThe row in the matrix [0,Rows()).
colThe column in the matrix [0, Cols()).
Returns:
The value at [row,col].

Definition at line 1134 of file matrix.cpp.

Matrix Matrix::operator* ( const Matrix m ) const

Mutliplies by the matrix. The current matrix columns must be equal to the parameter matrices rows.

Parameters:
mThe matrix to mutliply with.
Returns:
The result of matrix multiplication.

Definition at line 965 of file matrix.cpp.

Matrix & Matrix::operator*= ( const Matrix m )

Mutliplies by the matrix. The current matrix columns must be equal to the parameter matrices rows.

Parameters:
mThe matrix to mutliply with.
Returns:
The result of matrix multiplication.

Definition at line 1017 of file matrix.cpp.

Matrix Matrix::operator+ ( const Matrix m ) const

Adds two matrices together. Both must have the exact same dimensions.

Parameters:
mThe matrix to add.
Returns:
The result of matrix addition.

Definition at line 851 of file matrix.cpp.

Matrix & Matrix::operator+= ( const Matrix m )

Adds two matrices together. Both must have the exact same dimensions.

Parameters:
mThe matrix to add.
Returns:
The result of matrix addition.

Definition at line 881 of file matrix.cpp.

Matrix Matrix::operator- ( const Matrix m ) const

Subtracts the matrix. Both must have the exact same dimensions.

Parameters:
mThe matrix to subtract.
Returns:
The result of matrix subtraction.

Definition at line 908 of file matrix.cpp.

Matrix & Matrix::operator-= ( const Matrix m )

Subtracts the matrix. Both must have the exact same dimensions.

Parameters:
mThe matrix to subtract.
Returns:
The result of matrix subtraction.

Definition at line 938 of file matrix.cpp.

Matrix Matrix::operator/ ( const Matrix m ) const

Divides by the matrix. The current matrix columns must be equal to the parameter matrices rows.

Parameters:
mThe matrix to divide with (MUST BE A SQUARE MATRIX).
Returns:
The result of matrix division.

Definition at line 1001 of file matrix.cpp.

Matrix & Matrix::operator/= ( const Matrix m )

Divides by the matrix. The current matrix columns must be equal to the parameter matrices rows.

Parameters:
mThe matrix to divide with (MUST BE A SQUARE MATRIX).
Returns:
The result of matrix division.

Definition at line 1056 of file matrix.cpp.

Matrix & Matrix::operator= ( const double  v )

Sets all values in the matrix equal to the constant.

Parameters:
vThe value to use at every location in the matrix.

Definition at line 828 of file matrix.cpp.

Matrix & Matrix::operator= ( const Matrix m )

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;

Parameters:
iThe row in the matrix to access.
Returns:
A pointer to the row in the matrix. This array can then be indexed again to acces a column.

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;

Parameters:
iThe row in the matrix to access.
Returns:
A pointer to the row in the matrix. This array can then be indexed again to acces a column.

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.

unsigned int CxUtils::Matrix::Rows (  ) const [inline]

Definition at line 80 of file matrix.h.

void Matrix::Transpose ( const Matrix original,
Matrix transpose 
) [static]

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
Returns:
The transpose of the current matrix.

Definition at line 644 of file matrix.cpp.


Member Data Documentation

unsigned int CxUtils::Matrix::mCols [protected]

Number of columns in matrix.

Definition at line 114 of file matrix.h.

double* CxUtils::Matrix::mpMatrix [protected]

Definition at line 112 of file matrix.h.

unsigned int CxUtils::Matrix::mRows [protected]

Number of rows in matrix.

Definition at line 113 of file matrix.h.

unsigned int CxUtils::Matrix::mSize [protected]

Columns*Rows (size of array).

Definition at line 115 of file matrix.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines