Efficient, generic implementation of a 3x3 matrix.
The Matrix3 class is the representation of a 3x3 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}{*{3}{c}} xx & xy & xz \\ yx & yy & yz \\ zx & zy & zz \\ \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 & 4 & 5 \\ 6 & 7 & 8 \\ \end{array}\right)\f]
#include <Types.h>
Public Member Functions | |
constexpr | Matrix3 ()=default |
constexpr | Matrix3 (Type init) |
Constructor for a homogeneous initialization of all elements. More... | |
constexpr | Matrix3 (const Vector3< Type > &a, const Vector3< Type > &b, const Vector3< Type > &c) |
constexpr | Matrix3 (Type xx, Type xy, Type xz, Type yx, Type yy, Type yz, Type zx, Type zy, Type zz) |
Constructor for a direct initialization of all matrix elements. More... | |
constexpr | Matrix3 (const Type *init) |
Constructor for an array initializer. More... | |
template<typename Axis , typename Angle > | |
Matrix3 (Vector3< Axis > axis, Angle angle) | |
Rotation matrix constructor. More... | |
Matrix3 (const Matrix3 &m)=default | |
template<typename Other > | |
Matrix3 (const Matrix3< Other > &m) | |
Conversion constructor from different Matrix3 instances. More... | |
template<typename Other > | |
Matrix3< Type > & | operator= (const Matrix3< Other > &set) |
template<typename Other > | |
Matrix3< Type > & | operator+= (const Matrix3< Other > &rhs) |
template<typename Other > | |
Matrix3< Type > & | operator-= (const Matrix3< Other > &rhs) |
template<typename Other > | |
Matrix3< Type > & | operator*= (const Matrix3< Other > &rhs) |
Operators | |
Matrix3 & | operator= (Type set) |
Homogenous assignment to all matrix elements. More... | |
Matrix3 & | operator= (const Matrix3 &set)=default |
template<typename Other > | |
Matrix3 & | operator= (const Matrix3< Other > &set) |
Assignment operator for different Matrix3 instances. More... | |
template<typename Other > | |
bool | operator== (const Matrix3< Other > &rhs) const |
Equality operator for the comparison of two matrices. More... | |
template<typename Other > | |
bool | operator!= (const Matrix3< 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 > | |
Matrix3 & | operator+= (const Matrix3< Other > &rhs) |
Addition assignment operator for the addition of two matrices ( \( A+=B \)). More... | |
template<typename Other > | |
Matrix3 & | operator-= (const Matrix3< Other > &rhs) |
Subtraction assignment operator for the subtraction of two matrices ( \( A-=B \)). More... | |
template<typename Other > | |
Matrix3 & | operator*= (const Matrix3< Other > &rhs) |
Multiplication assignment operator for the multiplication between two matrices. More... | |
template<typename Other > | |
const Matrix3< typename MathTrait< Type, Other >::High > | operator+ (const Matrix3< Other > &rhs) const |
Addition operator for the addition of two matrices ( \( A=B+C \)). More... | |
template<typename Other > | |
const Matrix3< typename MathTrait< Type, Other >::High > | operator- (const Matrix3< Other > &rhs) const |
Subtraction operator for the subtraction of two matrices ( \( A=B-C \)). More... | |
template<typename Other > | |
const Vector3< typename MathTrait< Type, Other >::High > | operator* (const Vector3< Other > &rhs) const |
Multiplication operator for the multiplication of a matrix and a vector. More... | |
template<typename Other > | |
const Matrix3< typename MathTrait< Type, Other >::High > | operator* (const Matrix3< Other > &rhs) const |
Multiplication operator for the multiplication of two matrices ( \( A=B*C \)). More... | |
template<typename Other > | |
std::enable_if< std::is_arithmetic< Other >::value, Matrix3 & >::type | operator*= (Other rhs) |
Multiplication assignment operator for the multiplication between a matrix and. More... | |
template<typename Other > | |
std::enable_if< std::is_arithmetic< Other >::value, const Matrix3< typename MathTrait< Type, Other >::High > >::type | operator* (Other rhs) const |
Multiplication operator for the multiplication of a matrix and a scalar value. More... | |
Euler rotations | |
For the classification of the Euler rotation, the following characteristics are defined:
to a vector.
Y, or Y is followed by Z, or Z is followed by X; otherwise parity is odd.
Altogether, there are 24 possible Euler rotations. The possibilities are consisting of the choice of the inner axis (X,Y or Z), the parity (even or odd), repetition (yes or no) and the frame (static or rotating). E.g., an Euler order of XYZs stands for the rotation order of x-, y- and z-axis in a static frame (inner axis: X, parity: even, repetition: no, frame: static), whereas YXYr stands for the rotation order y-, x- and y-axis in a rotating frame ( inner axis: Y, parity: odd, repetition: yes, frame: rotating). | |
const Vector3< Type > | getEulerAngles (EulerRotation order) const |
Calculation of the Euler angles for a specific rotation order. More... | |
const Vector3< Type > | getEulerAnglesXYZ () const |
Calculation of the Euler angles (in radian measure). More... | |
Static Public Member Functions | |
static Matrix3 | makeDiagonalMatrix (const Type xx, const Type yy, const Type zz) |
Named constructor to create a diagonal matrix. All non-diagonal elements are initialized with zero. More... | |
static Matrix3 | makeDiagonalMatrix (const Type d) |
Named constructor to create a diagonal matrix. All non-diagonal elements are initialized with zero. More... | |
static Matrix3 | makeIdentityMatrix () |
Named constructor to create the identity matrix. More... | |
Private Attributes | |
Member variables | |
std::array< Type, 9 > | v_ |
The nine statically allocated matrix elements. 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). | |
enum | EulerRotation { XYZs = 0, ZYXr = 1, XYXs = 2, XYXr = 3, XZYs = 4, YZXr = 5, XZXs = 6, XZXr = 7, YZXs = 8, XZYr = 9, YZYs = 10, YZYr = 11, YXZs = 12, ZXYr = 13, YXYs = 14, YXYr = 15, ZXYs = 16, YXZr = 17, ZXZs = 18, ZXZr = 19, ZYXs = 20, XYZr = 21, ZYZs = 22, ZYZr = 23 } |
Order of the Euler rotation. More... | |
Type | getDeterminant () const |
Calculation of the determinant of the matrix. More... | |
Matrix3 & | transpose () |
Transposing the matrix. More... | |
const Matrix3 | getTranspose () const |
Calculation of the transpose of the matrix. More... | |
Matrix3 & | invert () |
Inverting the matrix. More... | |
const Matrix3 | getInverse () const |
Calculation of the inverse of the matrix. More... | |
template<typename Other > | |
const Vector3< typename MathTrait< Type, Other >::High > | multTranspose (const Vector3< Other > &rhs) const |
Multiplication of the transpose of the matrix and a vector ( \( \vec{a}=B^T*\vec{c} \)). More... | |
template<typename Other > | |
const Matrix3< typename MathTrait< Type, Other >::High > | rotate (const Matrix3< Other > &m) const |
Rotation of a matrix M ( \( ROT=R*M*R^{-1} \)). More... | |
template<typename Other > | |
const Matrix3< typename MathTrait< Type, Other >::High > | diagRotate (const Matrix3< Other > &m) const |
Rotation of a diagonal matrix M ( \( ROT=R*M*R^{-1} \)). More... | |
bool | isSingular () const |
Singularity check for the matrix (det=0). More... | |
bool | isSymmetric () const |
Checks if the matrix is symmetric. More... | |
bool | isZero () const |
Checks if all matrix entries are zero. More... | |
const Matrix3 | getCholesky () const |
Cholesky decomposition of the matrix ( \( A = LR \)). More... | |
template<typename Other > | |
const Vector3< typename MathTrait< Type, Other >::High > | solve (const Vector3< Other > &rhs) const |
Solving the linear system of equations \(A*x=b\) with the decomposed matrix. More... | |
Type | trace () const |
Computes the trace of the matrix (sum of diagonal elements). More... | |
Type * | data () |
const Type * | data () const |
enum walberla::math::Matrix3::EulerRotation |
Order of the Euler rotation.
This codes are needed for the EulerAngles function in order to calculate the Euler angles for a specific combination of rotations.
|
inlineexplicitconstexprdefault |
|
inlineexplicitconstexpr |
Constructor for a homogeneous initialization of all elements.
init | Initial value for all matrix elements. |
|
inlineexplicitconstexpr |
|
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. |
xz | The initial value for the xz-component. |
yx | The initial value for the yx-component. |
yy | The initial value for the yy-component. |
yz | The initial value for the yz-component. |
zx | The initial value for the zx-component. |
zy | The initial value for the zy-component. |
zz | The initial value for the zz-component. |
|
inlineexplicitconstexpr |
Constructor for an array initializer.
init | Pointer to the initialization array. |
The array is assumed to have at least nine valid elements.
|
explicit |
Rotation matrix constructor.
axis | The rotation axis. |
angle | The rotation angle. |
This constructor is only defined for floating point vectors. The attempt to use this constructor for vectors of integral data type results in a compile time error.
|
inlinedefault |
|
inline |
Conversion constructor from different Matrix3 instances.
m | Matrix to be copied. |
|
inline |
|
inline |
|
inline |
Rotation of a diagonal matrix M ( \( ROT=R*M*R^{-1} \)).
m | The diagonal matrix to be rotated. |
The DiagRotate function is a special case of the Rotate function. The matrix is assumed to be a diagonal matrix, which reduces the number of floating point operations of the rotation. This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data type will result in a compile time error.
|
inline |
Cholesky decomposition of the matrix ( \( A = LR \)).
This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data type will result in a compile time error.
|
inline |
Calculation of the determinant of the matrix.
const Vector3< Type > walberla::math::Matrix3< Type >::getEulerAngles | ( | EulerRotation | order | ) | const |
Calculation of the Euler angles for a specific rotation order.
order | The specific rotation order. |
This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data type will result in a compile time error.
|
inline |
Calculation of the Euler angles (in radian measure).
The Euler angles are calculated for a rotation order of x-, y- and z-axis. This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data type will result in a compile time error.
|
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 |
Checks if all matrix entries are zero.
|
inlinestatic |
Named constructor to create a diagonal matrix. All non-diagonal elements are initialized with zero.
d | value for diagonal elements. |
|
inlinestatic |
Named constructor to create a diagonal matrix. All non-diagonal elements are initialized with zero.
xx | value for element (0,0). |
yy | value for element (1,1). |
zz | value for element (2,2). |
|
inlinestatic |
Named constructor to create the identity matrix.
All diagonal elements are initialized to one, alls others to zero.
|
inline |
Multiplication of the transpose of the matrix and a vector ( \( \vec{a}=B^T*\vec{c} \)).
rhs | The right-hand-side vector for the multiplication. |
|
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 |
Multiplication operator for the multiplication of a matrix and a vector.
( \( \vec{a}=B*\vec{c} \)).
rhs | The right-hand-side vector for the multiplication. |
|
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 |
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 |
|
inlinedefault |
|
inline |
Assignment operator for different Matrix3 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 |
Rotation of a matrix M ( \( ROT=R*M*R^{-1} \)).
m | The matrix to be rotated. |
This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data type will result in a compile time error.
|
inline |
Solving the linear system of equations \(A*x=b\) with the decomposed matrix.
\(LR = A\).
rhs | The right-hand-side of the linear system of equations. |
This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data type will result in a compile time error.
|
inline |
Computes the trace of the matrix (sum of diagonal elements).
|
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}{*{3}{c}} 0 & 1 & 2 \\ 3 & 4 & 5 \\ 6 & 7 & 8 \\ \end{array}\right)\]