|
Core 1.0
|
This class implements \( 3^2 \) matrix. More...
#include <matrix.h>
Public Member Functions | |
| Matrix () | |
| Empty. | |
| constexpr | Matrix (const double &) |
| Creates a diagonal matrix. | |
| Matrix (const Matrix2 &) | |
| Creates a matrix form a lower dimension. | |
| Matrix (const Vector &) | |
| Create a diagonal matrix with diagonal terms set to the vector entries. | |
| Matrix (const Vector &, const Vector &, const Vector &) | |
| Creates a matrix given column vectors. | |
| constexpr | Matrix (const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &) |
| Creates a matrix with a set of double values. | |
| constexpr double & | operator[] (int) |
| Direct access to the array of the matrix. | |
| constexpr double | operator[] (int) const |
| Overloaded. | |
| constexpr double & | operator() (int, int) |
| Get element (i,j) of the matrix. | |
| constexpr double | operator() (int, int) const |
| Overloaded. | |
| Vector | C (int) const |
| Get the i-th column vector of the matrix. | |
| Vector | Row (int) const |
| Get the i-th row vector of the matrix. | |
| Matrix | operator- () const |
| Returns the opposite of a matrix -A. | |
| Matrix & | operator+= (const Matrix &) |
| Destructive addition operator. | |
| Matrix & | operator-= (const Matrix &) |
| Destructive subtraction operator. | |
| Matrix & | operator*= (const Matrix &) |
| Destructive multiplication. | |
| Matrix & | operator*= (const double &) |
| Destructive multiplication operator. | |
| Matrix & | operator/= (double) |
| Destructive division operator. | |
| Vector | operator* (const Vector &) const |
| Right multiply by a vector. | |
| Matrix | Scaled (const Matrix &) const |
| Hadamard (element-wise) product. | |
| Vector | GetRotationAngles () const |
| Compute the angles of the rotation matrix. | |
| QString | ToGLSL () const |
| Return a string expression. | |
| Matrix | Abs () const |
| Compute the absolute value of the matrix. | |
| Matrix | T () const |
| Transpose the matrix. | |
| Matrix | RotateElements () const |
| Rotate the elements of the matrix by a quarter turn. | |
| Matrix | Adjoint () const |
| Compute the adjoint, i.e, the comatrix of the matrix. | |
| double | Determinant () const |
| Computes the determinant of the matrix. | |
| Matrix | Inverse () const |
| Compute the inverse of a matrix \( A^{-1} \). | |
| double | Trace () const |
| Compute the trace (sum of diagonal terms) of a matrix. | |
| Cubic | Characteristic () const |
| Compute the characteristic polynomial. | |
| double | SpectralNorm () const |
| Computes the spectral norm of the matrix. | |
| double | InfinityNorm () const |
| Compute the infinity norm of the matrix. | |
| double | FrobeniusNorm () const |
| Compute the Frobenius norm of the matrix. | |
| void | QDU (Matrix &, Vector &, Vector &) const |
| Perform the QDU decomposition of a matrix. | |
| void | ExtractAngleAxis (Vector &, double &) const |
| Given a rotation matrix, extract its defining axis and its angle. | |
| void | EigenSolveSymmetric (double[3], Vector[3]) const |
| Find the eigen values of the matrix. | |
| Vector | Eigen () const |
| Find the eigen values of the matrix. | |
| void | Tridiagonal (double[3], double[3]) |
| Compute the Householder reduction of a symmetric matrix. | |
| int | QLAlgorithm (double[3], double[3]) |
| iteration with implicit shifting to reduce matrix from tridiagonal to diagonal | |
Static Public Member Functions | |
| static Matrix | Rotation (const Vector &) |
| Create a rotation matrix given a vector of angles that specifies the rotation around each world coordinate axis. | |
| static Matrix | Rotation (const Vector &, const double &) |
| Create a rotation matrix about an arbitrary axis. | |
| static Matrix | Rotation (const Vector &, const Vector &) |
| Create a rotation matrix that rotates a normalized vector into another one. | |
| static Matrix | RotationCanonical (const Vector &) |
| Create a rotation matrix that rotates (0,0,1) to a normalized vector. | |
| static Matrix | RotationX (const double &) |
| Create a rotation matrix around the x-axis. | |
| static Matrix | RotationY (const double &) |
| Create a rotation matrix around the y-axis. | |
| static Matrix | RotationZ (const double &) |
| Create a rotation matrix around the z-axis. | |
| static Matrix | Symmetry (const Vector &) |
| Create a planar symmetry matrix. | |
| static Matrix | Covariance (Vector *, int) |
| Compute the covariance matrix of a point cloud. | |
| static Matrix | Lerp (const double &, const Matrix &, const Matrix &) |
| Spherical interpolation of two rotation matrices. | |
| static Matrix | Rotation (Xoshiro256 &=Xoshiro256::X512) |
| Generate uniformly distributed random rotation matrix. | |
| static Matrix | Frenet (const Vector &, const Vector &=Vector::Z) |
| Compute the Frenet frame. | |
| static Matrix | External (const Vector &) |
| Compute the outer product \( n \otimes n^t \). | |
| static Matrix | External (const Vector &, const Vector &) |
| Compute the outer product \( n \otimes n^t \). | |
Static Public Attributes | |
| static const Matrix | Null |
| Null matrix. | |
| static const Matrix | Identity |
| Identity matrix. | |
| static const Matrix | Exchange |
| Exchange matrix, also called anti-identity or row-reversal matrix. | |
| static const Matrix | RotationHalfPiZ |
| Half-pi rotation around vertical axis. | |
Protected Attributes | |
| double | r [9] = { 1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0 } |
| The array storing the coefficients of the matrix. | |
Friends | |
| Matrix | operator+ (const Matrix &u, const Matrix &v) |
| Overloaded. | |
| Matrix | operator- (const Matrix &u, const Matrix &v) |
| Overloaded. | |
| Matrix | operator* (const Matrix &u, const Matrix &v) |
| Multiplication. | |
| Matrix | operator* (const Matrix &u, const double &a) |
| Right multiply by a double. | |
| Matrix | operator* (const double &a, const Matrix &u) |
| Left multiply by a double. | |
| Matrix | operator/ (const Matrix &u, const double &a) |
| Right divide by a double. | |
| Matrix | operator/ (const double &x, const Matrix &a) |
| Computes the inverse matrix and scales it by a double. | |
| std::ostream & | operator<< (std::ostream &s, const Matrix &matrix) |
| Overloaded. | |
This class implements \( 3^2 \) matrix.
Operators have been overloaded so as to behave as expected with the Vector class.
Many functions have been coded inline out of efficiency.
The constructors of this class are used to create matrices in the general case. See the static member functions Matrix::Rotation() to create different kinds of rotation matrices. Canonical symmetry matrices should be created as follows:
More general symmetries can be created using static member functions:
Components are stored in a single dimension array, sorting components by column.
|
inlineexplicitconstexpr |
Creates a diagonal matrix.
| a | The diagonal value. |
|
inlineexplicit |
Creates a matrix form a lower dimension.
| a | The matrix. |
|
inlineexplicit |
Create a diagonal matrix with diagonal terms set to the vector entries.
| a | Vector of diagonal values. |
Creates a matrix given column vectors.
| a,b,c | Column vectors. |
|
inlineexplicitconstexpr |
Creates a matrix with a set of double values.
The coefficients are given column by column: the parameter cJrI is the coefficient of the column J and of the row I, i.e., the element (I,J) of the matrix, which is stored at the index I+3J. The matrix whose rows are (a,b,c), (d,e,f) and (g,h,i) is therefore Matrix(a, d, g, b, e, h, c, f, i).
| c0r0,c0r1,c0r2 | Coefficients of the first column. |
| c1r0,c1r1,c1r2 | Coefficients of the second column. |
| c2r0,c2r1,c2r2 | Coefficients of the third column. |
| Matrix Matrix::Adjoint | ( | ) | const |
Compute the adjoint, i.e, the comatrix of the matrix.
|
inline |
Get the i-th column vector of the matrix.
| i | Index. |
Compute the covariance matrix of a point cloud.
This matrix is useful for computing the principal directions of a point of clouds. The principal directions are defined as the eigen vectors of the matrix.
| p | Array of vertices. |
| n | Number of vertices. |
| Vector Matrix::Eigen | ( | ) | const |
Find the eigen values of the matrix.
Eigen values are sorted and returned as a vector.
| void Matrix::EigenSolveSymmetric | ( | double | a[3], |
| Vector | e[3] ) const |
Find the eigen values of the matrix.
Return eigen vectors as well.
| a | An array of three eigen values. |
| e | The array containing the three eigen vectors. |
Compute the outer product \( n \otimes n^t \).
| u | Vector. |
Compute the outer product \( n \otimes n^t \).
| a,b | Vectors. |
| void Matrix::ExtractAngleAxis | ( | Vector & | v, |
| double & | angle ) const |
Given a rotation matrix, extract its defining axis and its angle.
This is the same as computing its quaternion representation.
| angle | Angle. |
| v | Vector. |
Let \( (x,y,z) \) be the unit-length axis and let \( a \) be an angle of rotation. The rotation matrix is \( R=I+sin(a).P+(1-cos(a)).P^2 \) where I is the identity and P a 0 diagonal matrix with \( (x,y,z) \) located at theit right index locations.
Some algebra will show that:
\( cos(a)=(trace(R)-1)/2 \) and \( R-R^t=2.sin(a).P \)
In the event that \( a=\pi \), \( R-R^t=0 \) which prevents from extracting the axis through P. Instead note that \( R=I+2.P^2 \) when \( a=\pi \), so \( P^2=(R-I)/2 \). The diagonal entries of \( P^2 \) are \( x^2-1 \), \( y^2-1 \), and \( z^2-1 \). We can solve these for axis \( (x,y,z) \). Because the angle is \( \pi \), it does not matter which sign you choose on the square roots.
Compute the Frenet frame.
Given tangent t and up vector u, computes an orthonormal matrix whose columns are the tangent, the binormal (t×u), and the normal (b×t). The normal is derived from the other two axes so that the three columns are mutually orthogonal regardless of whether u is perpendicular to t.
| t | Tangent, which need not be normalized. |
| u | Up vector (hint; need not be perpendicular to t). |
| Matrix Matrix::Inverse | ( | ) | const |
Compute the inverse of a matrix \( A^{-1} \).
Recall that \( A^{-1} \) can be defined as the transposed adjoint matrix divided by the determinant.
This function returns the null matrix if A cannot be inversed.
The threshold value involved in the singular matrix detection is set to \( 10^{-18} \).
Spherical interpolation of two rotation matrices.
This is an expensive function that first converts rotations to quaternions, then interpolates the quaternions, before finaly reconstructing the corresponding matrix.
| t | Interpolation parameter. |
| a,b | Rotation matrix. |
|
inlineconstexpr |
Get element (i,j) of the matrix.
| i | Row. |
| j | Column. |
Right multiply by a vector.
Right multiplication by a vector is a member function and not a friend to avoid left/right multiplication ambiguities since matrix multiplication is not commutative.
| v | Vector. static Matrix Rotation(const Vector &) Create a rotation matrix given a vector of angles that specifies the rotation around each world coord... Definition matrix.cpp:117 |
Perform the QDU decomposition of a matrix.
Q is orthogonal, D is diagonal, and U is upper triangular with ones on its diagonal.
The algorithm uses Gram-Schmidt orthogonalization (the QR algorithm).
| int Matrix::QLAlgorithm | ( | double | diag[3], |
| double | subd[3] ) |
iteration with implicit shifting to reduce matrix from tridiagonal to diagonal
| diag | Diagonal elements. |
| subd | Triangular sub-matrix. |
|
inline |
Rotate the elements of the matrix by a quarter turn.
The element (i,j) of the result is the element (j,2-i) of the matrix. For example, the matrix whose rows are (1,2,3), (4,5,6) and (7,8,9) becomes the matrix whose rows are (7,4,1), (8,5,2) and (9,6,3). This function is useful to rotate a 3x3 kernel.
The rotation of the elements is \( R = J K^T \), with J the row-reversal matrix (the exchange matrix, also called anti-identity matrix, Matrix::Exchange) and K the matrix: it is the transpose followed by a reversal of the rows.
Create a rotation matrix given a vector of angles that specifies the rotation around each world coordinate axis.
Rotations are concatenated, starting by rotating around the z axis, then y and eventually x.
| v | Vector of angles in radian. |
Create a rotation matrix about an arbitrary axis.
| u | Rotation axis, which should be unit. |
| a | Angle, in radian. |
Create a rotation matrix that rotates a normalized vector into another one.
| a,b | Initial and final vector (should be normalized). |
|
static |
Generate uniformly distributed random rotation matrix.
See Fast Random Rotation Matrices, J. Arvo. Graphics Gems III, 1992.
| ra | Random number generator. |
Create a rotation matrix that rotates (0,0,1) to a normalized vector.
This is the same as:
| v | Final vector (should be normalized). |
|
static |
Create a rotation matrix around the x-axis.
This static member function is provided out of efficiency as it is much faster than any other general Matrix::Rotation() member.
| a | Angle (in radian). |
|
static |
Create a rotation matrix around the y-axis.
| a | Angle (in radian). |
|
static |
Create a rotation matrix around the z-axis.
| a | Angle (in radian). |
|
inline |
Get the i-th row vector of the matrix.
| i | Index. |
Hadamard (element-wise) product.
| u | Matrix. |
| double Matrix::SpectralNorm | ( | ) | const |
Computes the spectral norm of the matrix.
The spectral norm is the largest singular value of the matrix, i.e., the square root of the largest eigenvalue of \( M^T M \). It is null for the null matrix.
Create a planar symmetry matrix.
The plane goes through the origin, the matrix is \( I-2nn^T \), where n is the normal vector.
| n | Normal to the plane, which is not necessarily a unit vector. |
|
inline |
Transpose the matrix.
Note that if the matrix is a rotation matrix, then the transpose is equal to its inverse.
| QString Matrix::ToGLSL | ( | ) | const |
Return a string expression.
Yields a QString of the form 'mat3(m(0, 0), ..., m(2, 2))' that write the matrix in GLSL.
| void Matrix::Tridiagonal | ( | double | diag[3], |
| double | subd[3] ) |
Compute the Householder reduction of a symmetric matrix.
Decompose a matrix A into \( Q^t M Q \).
| diag | Diagonal entries of A. |
| subd | Sub-diagonal entries of A. |
Multiplication.
| u,v | Input matrices. |
Computes the inverse matrix and scales it by a double.
This function calls Matrix::Inverse().
| x | Real. |
| a | Matrix. |
|
friend |
Overloaded.
| s | Stream. |
| matrix | The matrix. |
|
inlinestaticconstexpr |
Exchange matrix, also called anti-identity or row-reversal matrix.
The coefficients are null except those of the anti-diagonal, which are equal to one. Multiplying a matrix on the left by the exchange matrix reverses its rows, and multiplying it on the right reverses its columns.