modm API documentation
modm::Matrix< T, ROWS, COLUMNS > Class Template Reference

Class for handling common matrix operations. More...

#include <modm/math/matrix.hpp>

Public Member Functions

 Matrix () = default
 Default Constructor. More...
 
 Matrix (const T *data)
 Create a matrix from an array. More...
 
template<uint8_t MR, uint8_t MC>
Matrix< T, MR, MC > subMatrix (uint8_t row, uint8_t column) const
 Create a new sub matrix.
 
bool operator== (const Matrix &m) const
 
bool operator!= (const Matrix &m) const
 
const T * operator[] (uint8_t row) const
 
T * operator[] (uint8_t row)
 
uint8_t getNumberOfRows () const
 
uint8_t getNumberOfColumns () const
 
Matrix< T, 1, COLUMNS > getRow (uint8_t index) const
 
Matrix< T, ROWS, 1 > getColumn (uint8_t index) const
 
const T * ptr () const
 
T * ptr ()
 
Matrix operator- ()
 
Matrix operator+ (const Matrix &rhs) const
 
Matrix operator- (const Matrix &rhs) const
 
Matrix operator* (const T &rhs) const
 Scalar multiplication.
 
Matrix operator/ (const T &rhs) const
 Scalar division.
 
Matrix & operator+= (const Matrix &rhs)
 
Matrix & operator-= (const Matrix &rhs)
 
Matrix & operator*= (const T &rhs)
 Scalar multiplication.
 
Matrix & operator/= (const T &rhs)
 Scalar division.
 
Matrix operator*= (const Matrix &rhs)
 Matrix multiplication with matrices with the same size.
 
template<uint8_t RHSCOL>
Matrix< T, ROWS, RHSCOL > operator* (const Matrix< T, COLUMNS, RHSCOL > &rhs) const
 Matrix multiplication with different size matrices.
 
Matrix< T, COLUMNS, ROWS > asTransposed () const
 
void transpose ()
 Transpose the matrix. More...
 
determinant () const
 Calculate the determinant. More...
 
bool hasNan () const
 
bool hasInf () const
 
template<typename U >
Matrix & replace (const U *data)
 Fill the matrix with the values in data.
 
template<uint8_t MW, uint8_t MH>
Matrix & replace (uint8_t row, uint8_t column, const Matrix< T, MW, MH > &m)
 
Matrix & replaceRow (uint8_t index, const Matrix< T, 1, COLUMNS > &m)
 
Matrix & replaceColumn (uint8_t index, const Matrix< T, ROWS, 1 > &m)
 
Matrix< T, ROWS, COLUMNS+1 > addColumn (uint8_t index, const Matrix< T, ROWS, 1 > &c) const
 
Matrix< T, ROWS+1, COLUMNS > addRow (uint8_t index, const Matrix< T, 1, COLUMNS > &r) const
 
Matrix< T, ROWS, COLUMNS-1 > removeColumn (uint8_t index) const
 
Matrix< T, ROWS-1, COLUMNS > removeRow (uint8_t index) const
 

Static Public Member Functions

static const Matrix & identityMatrix ()
 Get a identity matrix. More...
 

Public Attributes

element [ROWS *COLUMNS]
 

Detailed Description

template<typename T, uint8_t ROWS, uint8_t COLUMNS>
class modm::Matrix< T, ROWS, COLUMNS >

Class for handling common matrix operations.

Having the width and height as template parameters has several advantages over the tradition dynamic matrix class:

  • The compiler knows how many elements you have in your matrix and can unroll and optimize loops
  • You can ensure that you are not doing operations on matrices with incompatible sizes (multiplication for example). The compiler will tell you at compile time if you do.
  • When you receive a matrix as a function parameter, you don't need to check that it is what you expect it to be. For example, if your function expects a 4x4 matrix, you'll ask for a Matrix and you are guaranteed to get what you asked for.

Adapted from the implementation of Gaspard Petit (gaspardpetit@gmail.com).

See also
<a href"http://www-etud.iro.umontreal.ca/~petitg/cpp/matrix.html">Homepage
Template Parameters
ROWSNumber of rows
COLUMNSNumber of columns
Author
Niklas Hauser
Fabian Greif

Constructor & Destructor Documentation

template<typename T , uint8_t ROWS, uint8_t COLUMNS>
constexpr static modm::Matrix< U >::Matrix ( )
explicitconstexprdefault

Default Constructor.

Create a matrix from an initializer list.

Creates a Matrix with uninitialized elements. Use zeroMatrix() to create a matrix with all elements set to zero.

Example:

Get a zero matrix

Creates an internal zero matrix and returns a reference to that internal matrix.

template<typename T , uint8_t ROWS, uint8_t COLUMNS>
modm::Matrix< T, ROWS, COLUMNS >::Matrix ( const T *  data)

Create a matrix from an array.

Example:

const int16_t m[6] = {
1, 2,
3, 4,
5, 6,
};

Member Function Documentation

template<typename T , uint8_t ROWS, uint8_t COLUMNS>
T modm::Matrix< T, ROWS, COLUMNS >::determinant ( ) const
inline

Calculate the determinant.

Uses modm::determinant(*this);

template<typename T , uint8_t ROWS, uint8_t COLUMNS>
static const Matrix& modm::Matrix< T, ROWS, COLUMNS >::identityMatrix ( )
static

Get a identity matrix.

Creates an internal identity matrix and returns a reference to that internal matrix.

template<typename T , uint8_t ROWS, uint8_t COLUMNS>
void modm::Matrix< T, ROWS, COLUMNS >::transpose ( )
inline

Transpose the matrix.

Warning
Will only work if the matrix is square!

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