Efficient, generic implementation of a 2x2 matrix.
The Matrix2 class is the representation of a 2x2 matrix with a total of 9 statically allocated elements of arbitrary type. The naming convention of the elements is as follows:
\f[\left(\begin{array}{*{2}{c}} xx & xy \\ yx & yy \\ \end{array}\right)\f]\n
These elements can be accessed directly with the 1D subscript operator or with the 2D function operator. The numbering of the matrix elements is
\f[\left(\begin{array}{*{3}{c}} 0 & 1 \\ 2 & 3 \\ \end{array}\right)\f]
#include <Types.h>
Public Member Functions | |
constexpr | Matrix2 () |
The default constructor for Matrix2. More... | |
constexpr | Matrix2 (Type init) |
Constructor for a homogeneous initialization of all elements. More... | |
constexpr | Matrix2 (Type xx, Type xy, Type yx, Type yy) |
Constructor for a direct initialization of all matrix elements. More... | |
constexpr | Matrix2 (const Type *init) |
Constructor for an array initializer. More... | |
constexpr | Matrix2 (const Matrix2 &m) |
The copy constructor for Matrix2. More... | |
template<typename Other > | |
constexpr | Matrix2 (const Matrix2< Other > &m) |
Conversion constructor from different Matrix2 instances. More... | |
template<typename Other > | |
Matrix2< Type > & | operator= (const Matrix2< Other > &set) |
template<typename Other > | |
Matrix2< Type > & | operator+= (const Matrix2< Other > &rhs) |
template<typename Other > | |
Matrix2< Type > & | operator-= (const Matrix2< Other > &rhs) |
template<typename Other > | |
Matrix2< Type > & | operator*= (Other rhs) |
template<typename Other > | |
Matrix2< Type > & | operator*= (const Matrix2< Other > &rhs) |
Operators | |
Matrix2 & | operator= (Type set) |
Homogenous assignment to all matrix elements. More... | |
Matrix2 & | operator= (const Matrix2 &set) |
Copy assignment operator for Matrix2. More... | |
template<typename Other > | |
Matrix2 & | operator= (const Matrix2< Other > &set) |
Assignment operator for different Matrix2 instances. More... | |
template<typename Other > | |
bool | operator== (const Matrix2< Other > &rhs) const |
Equality operator for the comparison of two matrices. More... | |
template<typename Other > | |
bool | operator!= (const Matrix2< Other > &rhs) const |
Inequality operator for the comparison of two matrices. More... | |
Type & | operator[] (uint_t index) |
1D-access to the matrix elements. More... | |
const Type & | operator[] (uint_t index) const |
1D-access to the matrix elements. More... | |
Type & | operator() (uint_t i, uint_t j) |
2D-access to the matrix elements. More... | |
const Type & | operator() (uint_t i, uint_t j) const |
2D-access to the matrix elements. More... | |
Arithmetic operators | |
The return type of the arithmetic operators depends on the involved data types of the matrices. HIGH denotes the more significant data type of the arithmetic operation (for further detail see the MathTrait class description). | |
template<typename Other > | |
Matrix2 & | operator+= (const Matrix2< Other > &rhs) |
Addition assignment operator for the addition of two matrices ( \( A+=B \)). More... | |
template<typename Other > | |
Matrix2 & | operator-= (const Matrix2< Other > &rhs) |
Subtraction assignment operator for the subtraction of two matrices ( \( A-=B \)). More... | |
template<typename Other > | |
Matrix2 & | operator*= (Other rhs) |
Multiplication assignment operator for the multiplication between a matrix and. More... | |
template<typename Other > | |
Matrix2 & | operator*= (const Matrix2< Other > &rhs) |
Multiplication assignment operator for the multiplication between two matrices. More... | |
template<typename Other > | |
const Matrix2< typename MathTrait< Type, Other >::High > | operator+ (const Matrix2< Other > &rhs) const |
Addition operator for the addition of two matrices ( \( A=B+C \)). More... | |
template<typename Other > | |
const Matrix2< typename MathTrait< Type, Other >::High > | operator- (const Matrix2< Other > &rhs) const |
Subtraction operator for the subtraction of two matrices ( \( A=B-C \)). More... | |
template<typename Other > | |
const Matrix2< typename MathTrait< Type, Other >::High > | operator* (Other rhs) const |
Multiplication operator for the multiplication of a matrix and a scalar value. More... | |
template<typename Other > | |
const Vector2< typename MathTrait< Type, Other >::High > | operator* (const Vector2< Other > &rhs) const |
template<typename Other > | |
const Matrix2< typename MathTrait< Type, Other >::High > | operator* (const Matrix2< Other > &rhs) const |
Multiplication operator for the multiplication of two matrices ( \( A=B*C \)). More... | |
Utility functions | |
The return type of the utility functions depends on the involved data types of the matrices. HIGH denotes the more significant data type of the utility operations (for further detail see the MathTrait class description). | |
Type | getDeterminant () const |
Calculation of the determinant of the matrix. More... | |
Matrix2 & | transpose () |
Transposing the matrix. More... | |
const Matrix2 | getTranspose () const |
Calculation of the transpose of the matrix. More... | |
Matrix2 & | invert () |
Inverting the matrix. More... | |
const Matrix2 | getInverse () const |
Calculation of the inverse of the matrix. More... | |
bool | isSingular () const |
Singularity check for the matrix (det=0). More... | |
bool | isSymmetric () const |
Checks if the matrix is symmetric. More... | |
Type * | data () |
Private Attributes | |
Member variables | |
Type | v_ [4] |
The nine statically allocated matrix elements. More... | |
|
inlineexplicitconstexpr |
The default constructor for Matrix2.
The diagonal matrix elements are initialized with 1, all other elements are initialized with 0.
|
inlineexplicitconstexpr |
Constructor for a homogeneous initialization of all elements.
init | Initial value for all matrix elements. |
|
inlineexplicitconstexpr |
Constructor for a direct initialization of all matrix elements.
xx | The initial value for the xx-component. |
xy | The initial value for the xy-component. |
yx | The initial value for the yx-component. |
yy | The initial value for the yy-component. |
|
inlineexplicitconstexpr |
Constructor for an array initializer.
init | Pointer to the initialization array. |
The array is assumed to have at least nine valid elements.
|
inlineconstexpr |
The copy constructor for Matrix2.
m | Matrix to be copied. |
The copy constructor is explicitly defined in order to enable/facilitate NRV optimization.
|
inlineconstexpr |
Conversion constructor from different Matrix2 instances.
m | Matrix to be copied. |
|
inline |
|
inline |
Calculation of the determinant of the matrix.
|
inline |
Calculation of the inverse of the matrix.
The calculation is performed with the matrix inversion by Cramer. This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data types will result in a compile time error.
|
inline |
Calculation of the transpose of the matrix.
|
inline |
Inverting the matrix.
The calculation is performed with the matrix inversion by Cramer. This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data types will result in a compile time error.
|
inline |
Singularity check for the matrix (det=0).
|
inline |
Checks if the matrix is symmetric.
|
inline |
Inequality operator for the comparison of two matrices.
rhs | The right-hand-side matrix for the comparison. |
|
inline |
2D-access to the matrix elements.
i | Access index for the row. The index has to be in the range [0..2]. |
j | Access index for the column. The index has to be in the range [0..2]. |
|
inline |
2D-access to the matrix elements.
i | Access index for the row. The index has to be in the range [0..2]. |
j | Access index for the column. The index has to be in the range [0..2]. |
|
inline |
Multiplication operator for the multiplication of two matrices ( \( A=B*C \)).
rhs | The right-hand-side matrix for the multiplication. |
|
inline |
|
inline |
Multiplication operator for the multiplication of a matrix and a scalar value.
( \( A=B*s \)).
rhs | The right-hand-side scalar value for the multiplication. |
|
inline |
Multiplication assignment operator for the multiplication between two matrices.
( \( A*=B \)).
rhs | The right-hand-side matrix for the multiplication. |
|
inline |
|
inline |
Multiplication assignment operator for the multiplication between a matrix and.
a scalar value ( \( A*=s \)).
rhs | The right-hand-side scalar value for the multiplication. |
|
inline |
|
inline |
Addition operator for the addition of two matrices ( \( A=B+C \)).
rhs | The right-hand-side matrix to be added to the matrix. |
|
inline |
Addition assignment operator for the addition of two matrices ( \( A+=B \)).
rhs | The right-hand-side matrix to be added to the matrix. |
|
inline |
|
inline |
Subtraction operator for the subtraction of two matrices ( \( A=B-C \)).
rhs | The right-hand-side matrix to be subtracted from the matrix. |
|
inline |
Subtraction assignment operator for the subtraction of two matrices ( \( A-=B \)).
rhs | The right-hand-side matrix to be subtracted from the matrix. |
|
inline |
|
inline |
Copy assignment operator for Matrix2.
set | Matrix to be copied. |
Explicit definition of a copy assignment operator for performance reasons.
|
inline |
Assignment operator for different Matrix2 instances.
set | Matrix to be copied. |
|
inline |
|
inline |
Homogenous assignment to all matrix elements.
set | Scalar value to be assigned to all matrix elements. |
|
inline |
Equality operator for the comparison of two matrices.
rhs | The right-hand-side matrix for the comparison. |
|
inline |
1D-access to the matrix elements.
index | Access index. The index has to be in the range \([0..8]\). |
|
inline |
1D-access to the matrix elements.
index | Access index. The index has to be in the range \([0..8]\). |
|
inline |
Transposing the matrix.
|
private |
The nine statically allocated matrix elements.
Access to the matrix elements is gained via the subscript or function call operator. The order of the elements is
\[\left(\begin{array}{*{2}{c}} 0 & 1 \\ 2 & 3 \\ \end{array}\right)\]