mbed.org local branch of microbit-dal. The real version lives in git at https://github.com/lancaster-university/microbit-dal

Dependencies:   BLE_API nRF51822 mbed-dev-bin

Dependents:   microbit Microbit IoTChallenge1 microbit ... more

Embed: (wiki syntax)

« Back to documentation index

Matrix4 Class Reference

Matrix4 Class Reference

Class definition for a simple matrix, that is optimised for nx4 or 4xn matrices. More...

#include <Matrix4.h>

Public Member Functions

 Matrix4 (int rows, int cols)
 Constructor.
 Matrix4 (const Matrix4 &matrix)
 Constructor.
int width ()
 Determines the number of columns in this matrix.
int height ()
 Determines the number of rows in this matrix.
float get (int row, int col)
 Reads the matrix element at the given position.
void set (int row, int col, float v)
 Writes the matrix element at the given position.
Matrix4 transpose ()
 Transposes this matrix.
Matrix4 multiply (Matrix4 &matrix, bool transpose=false)
 Multiplies this matrix with the given matrix (if possible).
Matrix4 multiplyT (Matrix4 &matrix)
 Multiplies the transpose of this matrix with the given matrix (if possible).
Matrix4 invert ()
 Performs an optimised inversion of a 4x4 matrix.
 ~Matrix4 ()
 Destructor.

Detailed Description

Class definition for a simple matrix, that is optimised for nx4 or 4xn matrices.

This class is heavily optimised for these commonly used matrices as used in 3D geometry. Whilst this class does support basic operations on matrices of any dimension, it is not intended as a general purpose matrix class as inversion operations are only provided for 4x4 matrices. For programmers needing more flexible Matrix support, the Matrix and MatrixMath classes from Ernsesto Palacios provide a good basis:

https://developer.mbed.org/cookbook/MatrixClass https://developer.mbed.org/users/Yo_Robot/code/MatrixMath/

Definition at line 43 of file Matrix4.h.


Constructor & Destructor Documentation

Matrix4 ( int  rows,
int  cols 
)

Constructor.

Class definition for a simple matrix, optimised for n x 4 or 4 x n matrices.

Create a matrix of the given size.

Parameters:
rowsthe number of rows in the matrix to be created.
colsthe number of columns in the matrix to be created.
 Matrix4(10, 4);        // Creates a Matrix with 10 rows and 4 columns.

This class is heavily optimised for these commonly used matrices as used in 3D geometry, and is not intended as a general purpose matrix class. For programmers needing more flexible Matrix support, the mbed Matrix and MatrixMath classes from Ernsesto Palacios provide a good basis:

https://developer.mbed.org/cookbook/MatrixClass https://developer.mbed.org/users/Yo_Robot/code/MatrixMath/ Constructor. Create a matrix of the given size.

Parameters:
rowsthe number of rows in the matrix to be created.
colsthe number of columns in the matrix to be created.
 Matrix4(10, 4);        // Creates a Matrix with 10 rows and 4 columns.

Definition at line 53 of file Matrix4.cpp.

Matrix4 ( const Matrix4 matrix )

Constructor.

Create a matrix that is an identical copy of the given matrix.

Parameters:
matrixThe matrix to copy.
 Matrix newMatrix(matrix);        .

Definition at line 76 of file Matrix4.cpp.

~Matrix4 (  )

Destructor.

Frees any memory consumed by this Matrix4 instance.

Definition at line 278 of file Matrix4.cpp.


Member Function Documentation

float get ( int  row,
int  col 
)

Reads the matrix element at the given position.

Parameters:
rowThe row of the element to read.
colThe column of the element to read.
Returns:
The value of the matrix element at the given position. 0 is returned if the given index is out of range.
 float v = matrix.get(1,2);

Definition at line 137 of file Matrix4.cpp.

int height (  )

Determines the number of rows in this matrix.

Returns:
The number of rows in the matrix.
 int r = matrix.height();

Definition at line 119 of file Matrix4.cpp.

Matrix4 invert (  )

Performs an optimised inversion of a 4x4 matrix.

Only 4x4 matrices are supported by this operation.

Returns:
the resultant matrix. An empty matrix is returned if the operation canot be completed.
 Matrix result = matrixA.invert();

Definition at line 235 of file Matrix4.cpp.

Matrix4 multiply ( Matrix4 matrix,
bool  transpose = false 
)

Multiplies this matrix with the given matrix (if possible).

Parameters:
matrixthe matrix to multiply this matrix's values against.
transposeTranspose the matrices before multiplication. Defaults to false.
Returns:
the resultant matrix. An empty matrix is returned if the operation canot be completed.
 Matrix result = matrixA.multiply(matrixB);

Definition at line 199 of file Matrix4.cpp.

Matrix4 multiplyT ( Matrix4 matrix )

Multiplies the transpose of this matrix with the given matrix (if possible).

Parameters:
matrixthe matrix to multiply this matrix's values against.
Returns:
the resultant matrix. An empty matrix is returned if the operation canot be completed.
 Matrix result = matrixA.multiplyT(matrixB);
Returns:
the resultant matrix. An empty matrix is returned if the operation canot be completed.
 Matrix result = matrixA.multiplyT(matrixB);

Definition at line 197 of file Matrix4.h.

void set ( int  row,
int  col,
float  v 
)

Writes the matrix element at the given position.

Parameters:
rowThe row of the element to write.
colThe column of the element to write.
vThe new value of the element.
 matrix.set(1,2,42.0);

Definition at line 158 of file Matrix4.cpp.

Matrix4 transpose (  )

Transposes this matrix.

Returns:
the resultant matrix.
 matrix.transpose();

Definition at line 175 of file Matrix4.cpp.

int width (  )

Determines the number of columns in this matrix.

Returns:
The number of columns in the matrix.
 int c = matrix.width();

Definition at line 105 of file Matrix4.cpp.