Double precision 3x3 matrix class. More...
#include <cvb/matrix_3d.hpp>
Public Member Functions | |
Matrix3D () noexcept=default | |
Default constructor for empty matrix. More... | |
template<std::size_t N> | |
Matrix3D (const double(&list)[N]) noexcept | |
Construct a 3x3 matrix with an initializer list. More... | |
Matrix3D (double alpha, double beta, double gamma) | |
Creates a rotation matrix from the given Euler angles. More... | |
Matrix3D (double alpha, double beta, double gamma, Factors3D scale) | |
Creates a transformation matrix from the given Euler angles and scaling. More... | |
bool | TryGetRotationAngles (double &alpha, double &beta, double &gamma) const noexcept |
Tries to compute the Euler angles from the matrix. More... | |
void | RotationAnglesScale (double &alpha, double &beta, double &gamma, Factors3D &scale, double &precision) const |
Computes the Euler angles and scaling from the matrix. More... | |
void | RollPitchYaw (double &roll, double &pitch, double &yaw) const |
Computes the Euler angles Roll, Pitch and Yaw for this matrix. More... | |
const double * | operator[] (int row) const noexcept |
Index based element access. More... | |
double * | operator[] (int row) noexcept |
Index based element access. More... | |
const double & | At (int row, int column) const noexcept |
Index based element access. More... | |
double & | At (int row, int column) noexcept |
Index based element access. More... | |
double | Det () const |
Matrix determinant. More... | |
void | Invert () |
Inverts this matrix in-place if possible. More... | |
Matrix3D | Inverse () |
Gets the inverse of this matrix if possible. More... | |
bool | operator== (const Matrix3D &matrix) const noexcept |
Compares to an other matrix. More... | |
bool | operator!= (const Matrix3D &matrix) const noexcept |
Compares to an other matrix. More... | |
Matrix3D & | operator+= (const Matrix3D &matrix) noexcept |
Adds and assigns to this matrix. More... | |
Matrix3D & | operator-= (const Matrix3D &matrix) noexcept |
Subtracts and assigns to this matrix. More... | |
Matrix3D & | operator*= (const Matrix3D &matrix) |
Multiplies and assigns to this matrix. More... | |
Matrix3D & | operator*= (const double &value) noexcept |
Multiplies and assigns to this matrix. More... | |
Matrix3D & | operator/= (const double &value) noexcept |
Divides each element of this matrix by the given value. More... | |
Static Public Member Functions | |
static Matrix3D | Identity () noexcept |
The identity element. More... | |
Related Functions | |
(Note that these are not member functions.) | |
Matrix3D | operator+ (const Matrix3D &lhs, const Matrix3D &rhs) |
Add two matrices. More... | |
Matrix3D | operator- (const Matrix3D &lhs, const Matrix3D &rhs) |
Subtract two matrices. More... | |
Matrix3D | operator* (const Matrix3D &lhs, const Matrix3D &rhs) |
Multiply two matrices. More... | |
Point3D< double > | operator* (const Matrix3D &lhs, const Point3D< double > &rhs) |
Multiply matrix with 3D point. More... | |
Matrix3D | operator* (const Matrix3D &lhs, const double &rhs) |
Multiply matrix with scalar. More... | |
Matrix3D | operator* (const double &lhs, const Matrix3D &rhs) |
Multiply scalar with matrix . More... | |
Matrix3D | operator/ (const Matrix3D &lhs, const double &rhs) |
Divide matrix by scalar. More... | |
Double precision 3x3 matrix class.
|
defaultnoexcept |
Default constructor for empty matrix.
Does | not throw any exception. |
|
inlinenoexcept |
Construct a 3x3 matrix with an initializer list.
[in] | list | Containing exactly 9 elements. |
Does | not throw any exception. |
|
inline |
Creates a rotation matrix from the given Euler angles.
The rotation matrix R is computed via:
where
alpha, beta, gamma are the rotation angles around x, y, z.
[in] | alpha | Angle around x axis in degrees. |
[in] | beta | Angle around y axis in degrees. |
[in] | gamma | Angle around z axis in degrees. |
Any | exception derived from std::exception including CvbException. |
Creates a transformation matrix from the given Euler angles and scaling.
Note, that the scaling is applied before rotation:
where
alpha, beta, gamma are the rotation angles around x, y, z.
sx, sy, sz are the scaling factors for x, y, z.
[in] | alpha | Angle around x axis in degrees. |
[in] | beta | Angle around y axis in degrees. |
[in] | gamma | Angle around z axis in degrees. |
[in] | scale | Scaling factors in x, y and z. |
Any | exception derived from std::exception including CvbException. |
|
inlinenoexcept |
Index based element access.
[in] | row | The row to access. |
[in] | column | The column to access. |
Does | not throw any exception. |
|
inlinenoexcept |
Index based element access.
[in] | row | The row to access. |
[in] | column | The column to access. |
Does | not throw any exception. |
|
inline |
Matrix determinant.
Any | exception derived from std::exception including CvbException. |
|
inlinestaticnoexcept |
The identity element.
Does | not throw any exception. |
|
inline |
Gets the inverse of this matrix if possible.
Any | exception derived from std::exception including CvbException. |
Might cause division by zero.
|
inline |
Inverts this matrix in-place if possible.
Any | exception derived from std::exception including CvbException. |
Might cause division by zero.
|
inlinenoexcept |
Compares to an other matrix.
[in] | matrix | Other matrix. |
Does | not throw any exception. |
|
inlinenoexcept |
Multiplies and assigns to this matrix.
[in] | value | Factor. |
Does | not throw any exception. |
Multiplies and assigns to this matrix.
[in] | matrix | Other matrix. |
Any | exception derived from std::exception including CvbException. |
Adds and assigns to this matrix.
[in] | matrix | Other matrix. |
Does | not throw any exception. |
Subtracts and assigns to this matrix.
[in] | matrix | Other matrix. |
Does | not throw any exception. |
|
inlinenoexcept |
Divides each element of this matrix by the given value.
[in] | value | Divisor. |
Does | not throw any exception. |
|
inlinenoexcept |
Compares to an other matrix.
[in] | matrix | Other matrix. |
Does | not throw any exception. |
|
inlinenoexcept |
Index based element access.
[in] | row |
Does | not throw any exception. |
|
inlinenoexcept |
Index based element access.
[in] | row |
Does | not throw any exception. |
|
inline |
Computes the Euler angles Roll, Pitch and Yaw for this matrix.
This function assumes the rotation matrix defined after the z-y′-x″ convention (see https://en.wikipedia.org/wiki/Euler_angles). The rotation matrix is interpreted as:
R = R_z*R_y*R_x
where R_x, R_y, R_z is the rotation around x″, y′, z.
[in] | roll | Variable to receive angle around x″ in degrees. |
[in] | pitch | Variable to receive angle around y′ in degrees. |
[in] | yaw | Variable to receive angle around z axis in degrees. |
Any | exception derived from std::exception including CvbException. |
|
inline |
Computes the Euler angles and scaling from the matrix.
The transformation matrix M is interpreted as:
where
alpha, beta, gamma are the rotation angles around x, y, z.
sx, sy, sz are the scaling factors for x, y, z.
If the matrix only contains rotation and scaling, i.e. it is not noisy, then the scaling factors are computed from the normed matrix and threfore positive as a start. If the determinant of the normed matrix is -1, the scaling factor in z is set to a negative value.
If calculating the rotation and scaling from the matrix without approximation is successful the precision value is set to -1. Otherwise an approximation is calculated. This is the case for non-valid rotation matrices (e.g. due to noise). Then the rotation angles and scaling factors are estimated using the Nelder-Mead algorithm. Therefore a cost function is set up and minimized over several iterations. The minimum value after the iteration stopped is stored to precision. If the given matrix is valid and not noisy, the precision will be very low. Note, that this estimation does not work for large scaling factors or if all scaling factors are negative. In this case the output precision will be large (in general greater 1). Then please norm your matrix first by dividing all matrix elements by a matrix norm (e.g. the Frobenius norm or other).
[out] | alpha | Variable to receive rotation angle around x axis in degrees. |
[out] | beta | Variable to receive rotation angle around y axis in degrees. |
[out] | gamma | Variable to receive rotation angle around z axis in degrees. |
[out] | scale | Scaling factors in x, y and z. |
[out] | precision | Precision of approximation. if results are calculated directly without approximation, this value is -1. |
Any | exception derived from std::exception including CvbException. |
|
inlinenoexcept |
Tries to compute the Euler angles from the matrix.
The matrix is interpreted as a rotation matrix R:
where
alpha, beta, gamma are the rotation angles around x, y, z.
[out] | alpha | Variable to receive rotation angle around x axis in degrees. |
[out] | beta | Variable to receive rotation angle around y axis in degrees. |
[out] | gamma | Variable to receive rotation angle around z axis in degrees. |
Multiply scalar with matrix .
[in] | lhs | Right hand side value. |
[in] | rhs | Left hand side matrix. |
Does | not throw any exception. |
Multiply matrix with scalar.
[in] | lhs | Right hand side matrix. |
[in] | rhs | Left hand side value. |
Does | not throw any exception. |
Multiply two matrices.
[in] | lhs | Right hand side matrix. |
[in] | rhs | Left hand side matrix. |
Any | exception derived from std::exception including CvbException. |
Multiply matrix with 3D point.
[in] | lhs | Right hand side matrix. |
[in] | rhs | Left hand side point. |
Does | not throw any exception. |
Add two matrices.
[in] | lhs | Right hand side matrix. |
[in] | rhs | Left hand side matrix. |
Does | not throw any exception. |
Subtract two matrices.
[in] | lhs | Right hand side matrix. |
[in] | rhs | Left hand side matrix. |
Does | not throw any exception. |