Core 1.0
|
This class implements 32 matrix. More...
#include <matrix.h>
Public Member Functions | |
Matrix () | |
Empty. | |
Matrix (const double &) | |
Creates a diagonal matrix. More... | |
Matrix (const Vector &) | |
Create a diagonal matrix with diagonal terms set to the vector entries. More... | |
Matrix (const Vector &, const Vector &, const Vector &) | |
Creates a matrix given column vectors. More... | |
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. More... | |
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. More... | |
constexpr double | operator() (int, int) const |
Overloaded. | |
Vector | C (int) const |
Get the i-th column vector of the matrix. More... | |
Vector | Row (int) const |
Get the i-th row vector of the matrix. More... | |
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*= (double) |
Destructive multiplication operator. | |
Matrix & | operator/= (double) |
Destructive division operator. | |
Vector | operator* (const Vector &) const |
Right multiply by a vector. More... | |
Vector | GetRotationAngles () const |
Compute the angles of the rotation matrix. | |
Matrix | Abs () const |
Compute the absolute value of the matrix. | |
Matrix | T () const |
Transpose the matrix. More... | |
Matrix | Adjoint () const |
Compute the adjoint, i.e, the comatrix of the matrix. More... | |
double | Determinant () const |
Computes the determinant of the matrix. | |
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 | SingularValueDecomposition (Matrix &, Vector &, Matrix &) const |
Decompose a matrix into singular values. More... | |
void | QDU (Matrix &, Vector &, Vector &) const |
Perform the QDU decomposition of a matrix. More... | |
void | ExtractAngleAxis (Vector &, double &) const |
Given a rotation matrix, extract its defining axis and its angle. More... | |
void | EigenSolveSymmetric (double[3], Vector[3]) const |
Find the eigen values of the matrix. More... | |
Vector | Eigen () const |
Find the eigen values of the matrix. More... | |
void | Tridiagonal (double[3], double[2]) |
Compute the Householder reduction of a symmetric matrix. More... | |
int | QLAlgorithm (double[3], double[3]) |
iteration with implicit shifting to reduce matrix from tridiagonal to diagonal More... | |
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. More... | |
static Matrix | RotationMaya (const Vector &) |
Create a rotation matrix given a vector of angles that specifies the rotation around each world coordinate axis. More... | |
static Matrix | Rotation (const Vector &, const double &) |
Create a rotation matrix about an arbitrary axis. More... | |
static Matrix | Rotation (const Vector &, const Vector &) |
Create a rotation matrix that rotates a normalized vector into another one. More... | |
static Matrix | RotationCanonical (const Vector &) |
Create a rotation matrix that rotates (0,0,1) to a normalized vector. More... | |
static Matrix | RotationX (const double &) |
Create a rotation matrix around the x-axis. More... | |
static Matrix | RotationY (const double &) |
Create a rotation matrix around the y-axis. More... | |
static Matrix | RotationZ (const double &) |
Create a rotation matrix around the z-axis. More... | |
static Matrix | Symmetry (const Vector &) |
Create a planar symmetry matrix. More... | |
static Matrix | Covariance (Vector *, int) |
Compute the covariance matrix of a point cloud. More... | |
static Matrix | Lerp (const double &, const Matrix &, const Matrix &) |
Spherical interpolation of two rotation matrices. More... | |
static Matrix | Rotation (RandomFast &=random239) |
Generate uniformly distributed random rotation matrix. More... | |
static Matrix | Frenet (const Vector &, const Vector &=Vector::Z) |
Compute the Frenet frame. More... | |
Static Public Attributes | |
static const Matrix | Null |
Null matrix. | |
static const Matrix | Identity |
Identity matrix. | |
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 &, const Matrix &) |
Overloaded. | |
Matrix | operator- (const Matrix &, const Matrix &) |
Overloaded. | |
Matrix | operator* (const Matrix &, const Matrix &) |
Multiplication. More... | |
Matrix | operator* (const Matrix &, const double &) |
Right multiply by a double. | |
Matrix | operator* (const double &, const Matrix &) |
Left multiply by a double. | |
Matrix | operator/ (const Matrix &, const double &) |
Right divide by a double. | |
Matrix | operator/ (const double &, const Matrix &) |
Computes the inverse matrix and scales it by a double. More... | |
std::ostream & | operator<< (std::ostream &, const Matrix &) |
Overloaded. More... | |
Matrix | Inverse (const Matrix &) |
Compute the inverse of a matrix A-1. More... | |
This class implements 32 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.
|
inlineexplicit |
Creates a diagonal matrix.
a | The diagonal value. |
|
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. |
|
inlineexplicit |
Creates a matrix with a set of double values.
Coefficients are given in column order.
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. |
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) the unit-length axis and let a an angle of rotation. The rotation matrix is R=I+sin(a).P+(1-cos(A)).P2 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-Rt=2.sin(a).P
In the event that a=π, R-Rt=0 which prevents us from extracting the axis through P. Instead note that R=I+2.P2 when a=π, so P2=(R-I)/2. The diagonal entries of P2 are x2-1, y2-1, and z2-1. We can solve these for axis (x,y,z). Because the angle is π, it does not matter which sign you choose on the square roots.
Compute the Frenet frame.
Given tangent t and up vector u, computes the matrix (t,t^u,u)). This function stores the tangent, the binormal and the normal vectors in the matrix. The normalization of the vectors is performed internally.
t | Tangent, which need not be normalized. |
u | Up vector. |
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. |
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 | Fast 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). |
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. |
|
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. |
Decompose a matrix into singular values.
The input matrix M will be equal to M = L S R.
L | Lower matrix. |
S | Singular values. |
R | Matrix. |
Create a planar symmetry matrix.
n | Normal to the plane. |
|
inline |
Transpose the matrix.
Note that if the matrix is a rotation matrix, then the transpose is equal to its inverse.
void Matrix::Tridiagonal | ( | double | diag[3], |
double | subd[2] | ||
) |
Compute the Householder reduction of a symmetric matrix.
Decompose a matrix A into Qt M Q.
diag | Diagonal entries of A. |
subd | Sub-diagonal entries of A. |
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.
A | Matrix. |
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. |