Matrix4 Class Reference
[libbiarc]

The Matrix4 class is a 4x4 dimensional Matrix class with floating point entries. More...

#include <include/Matrix4.h>

List of all members.

Public Member Functions

 Matrix4 ()
 Matrix4 (const Vector4 &v0, const Vector4 &v1, const Vector4 &v2, const Vector4 &v3)
Matrix4zero ()
Vector4operator[] (int n)
const Vector4operator[] (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)
Matrix4id ()
Matrix4transpose ()
Matrix3 sub (const int r, const int c)
float det ()
Matrix4inv ()
Matrix4adjoint ()
Matrix4outer (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
Matrix4operator= (const Matrix4 &m)
Matrix4operator+= (const Matrix4 &m)
Matrix4operator-= (const Matrix4 &m)
Matrix4operator*= (const float s)
Matrix4operator/= (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)


Detailed Description

The Matrix4 class is a 4x4 dimensional Matrix class with floating point entries.

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 $v_0,v_1,v_2,v_3$ and has the form $M=\left( \begin{array}{cccc}v_{00} & v_{10} & v_{20} & v_{30} \\ v_{01} & v_{11} & v_{21} & v_{31} \\ v_{02} & v_{12} & v_{22} & v_{32} \\ v_{03} & v_{13} & v_{23} & v_{33} \end{array} \right) $

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.

See also:
class Vector4

Constructor & Destructor Documentation

Matrix4::Matrix4 (  ) 

The default constructor initializes all matrix elements to zero.

References Vector4::zero().

Referenced by operator+(), and operator-().

Matrix4::Matrix4 ( const Vector4 v0,
const Vector4 v1,
const Vector4 v2,
const Vector4 v3 
)

Constructs a Matrix4 given three row vectors v0, v1, v2 and v3.


Member Function Documentation

Matrix4 & Matrix4::zero (  ) 

Set all matrix elements to zero. Returns an instance to itself.

References Vector4::zero().

Vector4 & Matrix4::operator[] ( int  n  )  [inline]

Index operator. Returns one of the three matrix columns as a Vector4 instance.

See also:
getOne(), getAll(), setOne(), setAll().

const Vector4 & Matrix4::operator[] ( int  n  )  const [inline]

Index operator. Returns one of the three matrix columns as a Vector4 instance.

See also:
getOne(), getAll(), setOne(), setAll().

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

void Matrix4::setAll ( const Vector4 v  ) 

Fill the matrix with the array of Vector4 v.

Vector4 Matrix4::getOne ( const int  c  ) 

Returns matrix column c as a Vector4 instance.

void Matrix4::getAll ( Vector4 v1,
Vector4 v2,
Vector4 v3,
Vector4 v4 
)

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 $M=$ is

$M^t=\left( \begin{array}{cccc}v_{00} & v_{01} & v_{02} & v_{03} \\ v_{10} & v_{11} & v_{12} & v_{13} \\ v_{20} & v_{21} & v_{22} & v_{23} \\ v_{30} & v_{31} & v_{32} & v_{33} \end{array} \right) $

Matrix3 Matrix4::sub ( const int  r,
const int  c 
)

Returns a Matrix3 object that is the current Matrix4 without line r and column c. Let's take as an example a matrix M. A call to M.sub(2,1), where the first argument is the line 3 and the second one the column 2 (since we start counting at 0), yields the following Matrix3 :

$M^{4x4}=\left( \begin{array}{c|ccc} v_{00}\quad & \!\!\!\!\!v_{10} & v_{20} & v_{30} \\ v_{01}\quad & \!\!\!\!\!v_{11} & v_{21} & v_{31} \\[3mm] \hline \vspace{-7.5mm} v_{03}\quad & \!\!\!\!\!v_{13} & v_{23} & v_{33} \\ v_{02}\quad & \!\!\!\!\!v_{12} & v_{22} & v_{32} \\ \end{array} \right) \quad\Rightarrow\quad M^{3x3}=\left( \begin{array}{ccc}v_{00} & v_{20} & v_{30} \\ v_{01} & v_{21} & v_{31} \\ v_{03} & v_{23} & v_{33} \end{array} \right) $

Referenced by adjoint(), and det().

float Matrix4::det (  ) 

Computes and returns the determinant of the Matrix4.

See also:
sub(),inv(),adjoint()

References Matrix3::det(), and sub().

Referenced by inv().

Matrix4 & Matrix4::inv (  ) 

Sets the current matrix to its inverse and return a reference to itself.

Given the matrix $A$, its inverse is the matrix B, satisfying the relation

$A\cdot B = id$,

where $id$ 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.

See also:
adjoint(),sub(),det(),Matrix3::inv()

References adjoint(), and det().

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 :

$cof_{ij}=(-1)^{i+j}det\:M_{ij}$,

where $M_{ij}$ is the matrix obtained by erasing line $i$ and column $j$.

See also:
inv(), det(), sub()

References Matrix3::det(), and sub().

Referenced by inv().

Matrix4 & Matrix4::outer ( const Vector4 a,
const Vector4 b 
)

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.

$M=\left( \begin{array}{c}a_0 \\ a_1 \\ a_2 \\ a_3 \end{array} \right) \cdot \left( \begin{array}{cccc}b_0 & b_1 & b_2 & b_3 \end{array} \right)$

Referenced by Vector4::reflect().

Matrix4 Matrix4::operator* ( const Matrix4 m  ) 

Multiplies the current matrix on the right hand side by m and returns the result as a new Matrix4 instance.

Vector4 Matrix4::operator* ( const Vector4 v  ) 

Applies the current matrix on the left side of a column vector v and returns a vector with the result.

Matrix4 Matrix4::operator+ ( const Matrix4 m  )  const

Matrix summation. Returns a Matrix4 instance.

References Matrix4().

Matrix4 Matrix4::operator- ( const Matrix4 m  )  const

Matrix substraction. Returns a Matrix4 instance.

References Matrix4().

Matrix4 Matrix4::operator- (  )  const

Matrix negation. Returns a Matrix4 instance where all the elements have now switched their sign.

References Matrix4().

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

Assign operator. Makes a copy of m. Returns an instance to itself.

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

Adds the matrix m to the current one. Returns an instance to itself.

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

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.


Friends And Related Function Documentation

Matrix4 operator* ( const Matrix4 m,
float  d 
) [friend]

Multiplies every element of the matrix m by a factor of d. and returns a Matrix4 object.

Matrix4 operator* ( float  d,
const Matrix4 m 
) [friend]

Multiplies every element of the matrix m by a factor of d. and returns a Matrix4 object.

Matrix4 operator/ ( const Matrix4 m,
float  d 
) [friend]

Divides every element of the matrix m by d. and returns a Matrix4 object.

ostream & Matrix4::operator<< ( ostream &  out,
const Matrix4 m 
) [friend]

Overloaded left shift operator. Returns the Matrix4 m as an ostream object that can be written to a file or to standart output.

See also:
print()


The documentation for this class was generated from the following files:

Generated on Mon Feb 8 17:22:36 2010 for libbiarc by  doxygen 1.5.6