Core 1.0
Matrix2 Class Reference

This class implements 22 matrix. More...

#include <matrix.h>

Public Member Functions

 Matrix2 ()
 Empty.
 
 Matrix2 (const double &)
 Creates a matrix with the same diagonal value.
 
 Matrix2 (const Vector2 &)
 Create a diagonal matrix with diagonal terms set to the vector entries.
 
 Matrix2 (const Vector2 &, const Vector2 &)
 Creates a column vector matrix.
 
 Matrix2 (const double &, const double &, const double &, const double &)
 Creates a matrix with a set of double values.
 
 Matrix2 (const double &, const double &, const double &)
 Create a symmetric matrix.
 
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.
 
Vector2 C (int) const
 Get the i-th column vector of the matrix.
 
Matrix2 operator- () const
 Returns the opposite of a matrix -A.
 
Matrix2operator+= (const Matrix2 &)
 Destructive addition operator.
 
Matrix2operator-= (const Matrix2 &)
 Destructive subtraction operator.
 
Matrix2operator*= (const Matrix2 &)
 Destructive multiplication.
 
Matrix2operator*= (double)
 Destructive multiplication operator.
 
Matrix2operator/= (double)
 Destructive division operator.
 
Matrix2 Scaled (const Matrix2 &) const
 Hadamart product, which is the element-wise product.
 
Vector2 operator* (const Vector2 &) const
 Right multiply by a vector.
 
QString ToGLSL () const
 Return a string expression.
 
Matrix2 T () const
 Transpose the matrix.
 
double Determinant () const
 Computes the determinant of the matrix.
 
Matrix2 Inverse () const
 Computes the inverse of a matrix A-1.
 
double Trace () const
 Compute the trace (sum of diagonal terms) of a matrix.
 
double FrobeniusNorm () const
 Compute the Frobenius norm of the matrix.
 
Quadric Characteristic () const
 Compute the characteristic polynomial.
 
double SpectralNorm () const
 Compute the spectral norm of the matrix.
 
double InfinityNorm () const
 Compute the infinity norm of the matrix.
 
void EigenSolveSymmetric (double[2], Vector2[2]) const
 Compute the eigen values of the matrix.
 
Vector2 Eigen () const
 Compute the eigen values.
 

Static Public Member Functions

static Matrix2 Rotation (const double &)
 Create a rotation matrix.
 
static Matrix2 Rotation (RandomFast &=random239)
 Create a random rotation matrix.
 
static Matrix2 Tensor2 (const double &)
 Create an anisotropic tensor matrix.
 
static Matrix2 Tensor2 (const double &, const double &)
 Create a tensor matrix.
 

Static Public Attributes

static const Matrix2 Null
 This static member defines the null matrix.
 
static const Matrix2 Identity
 This static member defines the identity matrix.
 
static const Matrix2 RotationHalfPi
 Half-pi rotation.
 
static const Matrix2 RotationTwoThirdsPi
 Two thirds pi rotation.
 

Protected Attributes

double r [4] = { 1.0,0.0,0.0,1.0 }
 The array storing the coefficients of the matrix.
 

Friends

Matrix2 operator+ (const Matrix2 &u, const Matrix2 &v)
 Overloaded.
 
Matrix2 operator- (const Matrix2 &u, const Matrix2 &v)
 Overloaded.
 
Matrix2 operator* (const Matrix2 &u, const Matrix2 &v)
 Multiplication.
 
Matrix2 operator* (const Matrix2 &u, const double &a)
 Right multiply by a double.
 
Matrix2 operator* (const double &a, const Matrix2 &u)
 Left multiply by a double.
 
Matrix2 operator/ (const Matrix2 &u, const double &a)
 Right divide by a double.
 
Matrix2 operator/ (const double &x, const Matrix2 &a)
 Computes the inverse matrix and scales it by a double.
 
std::ostream & operator<< (std::ostream &s, const Matrix2 &matrix)
 Overloaded.
 

Detailed Description

This class implements 22 matrix.

Operators have been overloaded to behave as expected. Thus it is possible to write:

Matrix2 a = Matrix2(Vector2(1.0, 2.0)); // Scale
Matrix2 b = Matrix2::Rotation(Math::Pi / 4.0); // Rotation matrix
Vector2 u(2.0, -1.0); // Vector
Vector2 v = (a*b)*u; // Matrix vector product
static constexpr double Pi
π.
Definition mathematics.h:178
static Matrix2 Rotation(const double &)
Create a rotation matrix.
Definition matrix2.cpp:90
Matrix2()
Empty.
Definition matrix.h:18
Vectors in two dimensions.
Definition evector.h:628

Constructor & Destructor Documentation

◆ Matrix2() [1/4]

Matrix2::Matrix2 ( const double & a)
inlineexplicit

Creates a matrix with the same diagonal value.

Parameters
aThe diagonal value.

◆ Matrix2() [2/4]

Matrix2::Matrix2 ( const Vector2 & a)
inlineexplicit

Create a diagonal matrix with diagonal terms set to the vector entries.

Note that this is a scaling matrix.

Parameters
aVector of diagonal values

◆ Matrix2() [3/4]

Matrix2::Matrix2 ( const Vector2 & a,
const Vector2 & b )
inlineexplicit

Creates a column vector matrix.

Parameters
a,bColumn vectors.

◆ Matrix2() [4/4]

Matrix2::Matrix2 ( const double & a,
const double & b,
const double & c )
inlineexplicit

Create a symmetric matrix.

Parameters
a,bDiagonal terms.
cLast term.

Member Function Documentation

◆ C()

Vector2 Matrix2::C ( int i) const
inline

Get the i-th column vector of the matrix.

Parameters
iIndex.

◆ EigenSolveSymmetric()

void Matrix2::EigenSolveSymmetric ( double a[2],
Vector2 e[2] ) const

Compute the eigen values of the matrix.

Return eigen vectors as well.

Parameters
aAn array of two eigen values.
eThe array containing the two eigen vectors.

◆ Inverse()

Matrix2 Matrix2::Inverse ( ) const

Computes the inverse of a matrix A-1.

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.

◆ operator()()

double & Matrix2::operator() ( int i,
int j )
inlineconstexpr

Get element (i,j) of the matrix.

Parameters
iRow.
jColumn.

◆ operator+=()

Matrix2 & Matrix2::operator+= ( const Matrix2 & u)

Destructive addition operator.

Parameters
uMatrix.

◆ operator-=()

Matrix2 & Matrix2::operator-= ( const Matrix2 & u)

Destructive subtraction operator.

Parameters
uMatrix.

◆ Rotation() [1/2]

Matrix2 Matrix2::Rotation ( const double & a)
static

Create a rotation matrix.

Parameters
aAngle in radian.

◆ Rotation() [2/2]

Matrix2 Matrix2::Rotation ( RandomFast & ra = random239)
static

Create a random rotation matrix.

This is a simple function which is equivalent to the following inlined code:

double r[4]
The array storing the coefficients of the matrix.
Definition matrix.h:15
A fast linear congruential random number generator.
Definition random.h:40
Parameters
raRandom number generator.

◆ Scaled()

Matrix2 Matrix2::Scaled ( const Matrix2 & u) const

Hadamart product, which is the element-wise product.

Parameters
uMatrix.

◆ T()

Matrix2 Matrix2::T ( ) const
inline

Transpose the matrix.

Note that if the matrix is a rotation matrix, then the transpose is equal to its inverse.

See also
Matrix::T()

◆ Tensor2() [1/2]

Matrix2 Matrix2::Tensor2 ( const double & angle)
static

Create an anisotropic tensor matrix.

Parameters
angleThe angle of the tensor.

◆ Tensor2() [2/2]

Matrix2 Matrix2::Tensor2 ( const double & c,
const double & s )
static

Create a tensor matrix.

Parameters
c,sCosine and sine of the angle of the tensor.

◆ ToGLSL()

QString Matrix2::ToGLSL ( ) const

Return a string expression.

Yields a QString of the form 'mat4(m(0, 0), ..., m(1, 1))' that write the matrix in GLSL.

Author
Hubert-Brierre Pierre

Friends And Related Symbol Documentation

◆ operator*

Matrix2 operator* ( const Matrix2 & u,
const Matrix2 & v )
friend

Multiplication.

Parameters
u,vInput matrices.

◆ operator/

Matrix2 operator/ ( const double & x,
const Matrix2 & a )
friend

Computes the inverse matrix and scales it by a double.

Parameters
xReal.
aMatrix.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Matrix2 & matrix )
friend

Overloaded.

Parameters
sStream.
matrixThe matrix.