t
Loading...
Searching...
No Matches
t::Matrix4x4 Class Reference

The \(4 \times 4\) matrix class. More...

#include <Matrix4x4.hpp>

Public Member Functions

 Matrix4x4 (double _n11, double _n12, double _n13, double _n14, double _n21, double _n22, double _n23, double _n24, double _n31, double _n32, double _n33, double _n34, double _n41, double _n42, double _n43, double _n44)
 Creates a new \(4 \times 4\) matrix with the specified elements.
 
Matrix4x4 clone () const
 Returns a copy of this matrix.
 
Matrix4x4copy (const Matrix4x4 &source)
 Copies the elements of another \(4 \times 4\) matrix into this matrix.
 
Matrix4x4set (double _n11, double _n12, double _n13, double _n14, double _n21, double _n22, double _n23, double _n24, double _n31, double _n32, double _n33, double _n34, double _n41, double _n42, double _n43, double _n44)
 Sets the elements of this matrix.
 
double get (int row, int column) const
 Gets the element at the specified row and column of this matrix with bounds checking.
 
Matrix4x4set (int row, int column, int value)
 Sets the element at the specified row and column of this matrix to the specified value.
 
Matrix4x4reset ()
 Resets this matrix to the \(4 \times 4\) identity matrix.
 
double determinant () const
 Returns the determinant of this matrix.
 
Matrix4x4 transpose () const
 Returns the transpose of this matrix.
 
Matrix4x4 inverse () const
 Returns the inverse of this matrix or the zero matrix if this matrix does not have an inverse.
 
Matrix3x3 topLeft3x3Matrix () const
 Returns the top-left \(3 \times 3\) matrix of this matrix.
 
double operator[] (std::size_t index) const
 Returns the element at the specified index of this matrix without bounds checking and assuming row-major ordering.
 
Matrix4x4operator+= (const Matrix4x4 &m)
 Adds the specified \(4 \times 4\) matrix to this matrix.
 
Matrix4x4operator+= (double s)
 Adds the specified constant to all elements in this matrix.
 
Matrix4x4operator-= (const Matrix4x4 &m)
 Substracts the specified \(4 \times 4\) matrix from this matrix.
 
Matrix4x4operator-= (double s)
 Substracts the specified constant from all elements in this matrix.
 
Matrix4x4operator*= (const Matrix4x4 &m)
 Multiplies this matrix with another \(4 \times 4\) matrix and copies the result into this instance.
 
Matrix4x4operator*= (double s)
 Multiplies the elements of this matrix with the specified constant.
 
Matrix4x4operator/= (const Matrix4x4 &m)
 Divides the elements of this matrix by the corresponding elements of the specified \(3 \times 3\) matrix.
 
Matrix4x4operator/= (double s)
 Divides the elements of this matrix with the specified constant.
 

Static Public Member Functions

static Matrix4x4 identity ()
 Returns a \(4 \times 4\) identity matrix.
 
static Matrix4x4 zero ()
 Returns a \(4 \times 4\) zero matrix.
 
static Matrix4x4 fromTranslation (const Vector3 &distance)
 Returns a translation matrix for the specified translation for post-multiplication ( \(V' = AV\) where \(V\) is the homogeneous coordinates and \(A\) is the transformation matrix).
 
static Matrix4x4 fromRotation (const EulerRotation &angle)
 Returns a rotation matrix for the specified rotation for post-multiplication ( \(V' = AV\) where \(V\) is the homogeneous coordinates and \(A\) is the transformation matrix).
 
static Matrix4x4 fromScale (const Vector3 &scaleFactor)
 Returns a scale matrix for the specified scale factor.
 

Public Attributes

std::array< double, 16 > elements
 The array containing the elements of this matrix in row-major order.
 

Friends

bool operator== (const Matrix4x4 &a, const Matrix4x4 &b)=default
 Returns whether two \(4 \times 4\) matrices are equal.
 
Matrix4x4 operator+ (const Matrix4x4 &a, const Matrix4x4 &b)
 Adds two \(4 \times 4\) matrices.
 
Matrix4x4 operator+ (const Matrix4x4 &a, double s)
 Adds a constant to all elements of a \(4 \times 4\) matrix.
 
Matrix4x4 operator+ (double s, const Matrix4x4 &a)
 Adds a constant to all elements of a \(4 \times 4\) matrix.
 
Matrix4x4 operator- (const Matrix4x4 &a, const Matrix4x4 &b)
 Substracts 2 \(4 \times 4\) matrices.
 
Matrix4x4 operator- (const Matrix4x4 &a, double s)
 Substracts a constant from all elements of a \(4 \times 4\) matrix.
 
Matrix4x4 operator- (double s, const Matrix4x4 &a)
 Substracts a \(4 \times 4\) matrix from a \(4 \times 4\) constant matrix.
 
Matrix4x4 operator* (const Matrix4x4 &a, const Matrix4x4 &b)
 Multiplies two \(4 \times 4\) matrices.
 
Matrix4x4 operator* (const Matrix4x4 &a, double s)
 Multiplies all elements of a \(4 \times 4\) matrix with a constant.
 
Matrix4x4 operator* (double s, const Matrix4x4 &a)
 Multiplies all elements of a \(4 \times 4\) matrix with a constant.
 
Vector4 operator* (const Matrix4x4 &a, const Vector4 &v)
 Multiplies a \(4 \times 4\) matrix with a four-dimensional vector.
 
Matrix4x4 operator/ (const Matrix4x4 &a, const Matrix4x4 &b)
 Returns the element-wise division of two \(4 \times 4\) matrices.
 
Matrix4x4 operator/ (const Matrix4x4 &a, double s)
 Divides all elements of a \(4 \times 4\) matrix by a constant.
 
Matrix4x4 operator/ (double s, const Matrix4x4 &a)
 Returns the element-wise division of a \(4 \times 4\) constant matrix and a \(4 \times 4\) matrix.
 

Detailed Description

The \(4 \times 4\) matrix class.

Constructor & Destructor Documentation

◆ Matrix4x4()

t::Matrix4x4::Matrix4x4 ( double _n11,
double _n12,
double _n13,
double _n14,
double _n21,
double _n22,
double _n23,
double _n24,
double _n31,
double _n32,
double _n33,
double _n34,
double _n41,
double _n42,
double _n43,
double _n44 )
inline

Creates a new \(4 \times 4\) matrix with the specified elements.

Parameters
_n11The \((1, 1)\) element of the new matrix.
_n12The \((1, 2)\) element of the new matrix.
_n13The \((1, 3)\) element of the new matrix.
_n14The \((1, 4)\) element of the new matrix.
_n21The \((2, 1)\) element of the new matrix.
_n22The \((2, 2)\) element of the new matrix.
_n23The \((2, 3)\) element of the new matrix.
_n24The \((2, 4)\) element of the new matrix.
_n31The \((3, 1)\) element of the new matrix.
_n32The \((3, 2)\) element of the new matrix.
_n33The \((3, 3)\) element of the new matrix.
_n34The \((3, 4)\) element of the new matrix.
_n41The \((4, 1)\) element of the new matrix.
_n42The \((4, 2)\) element of the new matrix.
_n43The \((4, 3)\) element of the new matrix.
_n44The \((4, 4)\) element of the new matrix.

Member Function Documentation

◆ clone()

Matrix4x4 t::Matrix4x4::clone ( ) const
inline

Returns a copy of this matrix.

Returns
A copy of this matrix.

◆ copy()

Matrix4x4 & t::Matrix4x4::copy ( const Matrix4x4 & source)
inline

Copies the elements of another \(4 \times 4\) matrix into this matrix.

Parameters
sourceThe \(4 \times 4\) matrix to copy from.
Returns
This matrix.

◆ determinant()

double t::Matrix4x4::determinant ( ) const
inline

Returns the determinant of this matrix.

Returns
The determinant of this matrix.

◆ fromRotation()

static Matrix4x4 t::Matrix4x4::fromRotation ( const EulerRotation & angle)
inlinestatic

Returns a rotation matrix for the specified rotation for post-multiplication ( \(V' = AV\) where \(V\) is the homogeneous coordinates and \(A\) is the transformation matrix).

If you want to use pre-multiplication i.e. \(V' = VA\), transpose the returned matrix.

Parameters
angleAn Euler rotation.
Returns
The rotation matrix for angle.

◆ fromScale()

static Matrix4x4 t::Matrix4x4::fromScale ( const Vector3 & scaleFactor)
inlinestatic

Returns a scale matrix for the specified scale factor.

Parameters
scaleFactorThe scale factor along the x, y, and z axes.
Returns
The scale matrix for scaleFactor.

◆ fromTranslation()

static Matrix4x4 t::Matrix4x4::fromTranslation ( const Vector3 & distance)
inlinestatic

Returns a translation matrix for the specified translation for post-multiplication ( \(V' = AV\) where \(V\) is the homogeneous coordinates and \(A\) is the transformation matrix).

If you want to use pre-multiplication i.e. \(V' = VA\), transpose the returned matrix.

Parameters
distanceThe distance to translate along the x, y, and z axes.
Returns
The translation matrix for distance.

◆ get()

double t::Matrix4x4::get ( int row,
int column ) const
inline

Gets the element at the specified row and column of this matrix with bounds checking.

Parameters
rowThe 0-based index of the row of the element.
columnThe 0-based index of the column of the element.
Returns
The element at the specified row and column of this matrix.
See also
operator[] for accessing without bounds checking.

◆ identity()

static Matrix4x4 t::Matrix4x4::identity ( )
inlinestatic

Returns a \(4 \times 4\) identity matrix.

Returns
A \(4 \times 4\) identity matrix.

◆ inverse()

Matrix4x4 t::Matrix4x4::inverse ( ) const
inline

Returns the inverse of this matrix or the zero matrix if this matrix does not have an inverse.

The inverse of a matrix \(A\) is the matrix \(A^{-1}\) such that \(AA^{-1} = I\) where \(I\) is the identity matrix. A matrix does not have an inverse if its determinant is zero.

Note that this method does not modify this instance.

Returns
The inverse of this matrix.

◆ operator*=() [1/2]

Matrix4x4 & t::Matrix4x4::operator*= ( const Matrix4x4 & m)
inline

Multiplies this matrix with another \(4 \times 4\) matrix and copies the result into this instance.

Note that this is not an element-wise multiplication, but matrix multiplication.

Parameters
mA \(4 \times 4\) matrix to multiply with.
Returns
This matrix.

◆ operator*=() [2/2]

Matrix4x4 & t::Matrix4x4::operator*= ( double s)
inline

Multiplies the elements of this matrix with the specified constant.

Parameters
sA constant.
Returns
This matrix.

◆ operator+=() [1/2]

Matrix4x4 & t::Matrix4x4::operator+= ( const Matrix4x4 & m)
inline

Adds the specified \(4 \times 4\) matrix to this matrix.

Parameters
mA \(4 \times 4\) matrix.
Returns
This matrix.

◆ operator+=() [2/2]

Matrix4x4 & t::Matrix4x4::operator+= ( double s)
inline

Adds the specified constant to all elements in this matrix.

Parameters
sA constant.
Returns
This matrix.

◆ operator-=() [1/2]

Matrix4x4 & t::Matrix4x4::operator-= ( const Matrix4x4 & m)
inline

Substracts the specified \(4 \times 4\) matrix from this matrix.

Parameters
mA \(4 \times 4\) matrix.
Returns
This matrix.

◆ operator-=() [2/2]

Matrix4x4 & t::Matrix4x4::operator-= ( double s)
inline

Substracts the specified constant from all elements in this matrix.

Parameters
sA constant.
Returns
This matrix.

◆ operator/=() [1/2]

Matrix4x4 & t::Matrix4x4::operator/= ( const Matrix4x4 & m)
inline

Divides the elements of this matrix by the corresponding elements of the specified \(3 \times 3\) matrix.

Parameters
mA \(4 \times 4\) matrix.
Returns
This matrix.

◆ operator/=() [2/2]

Matrix4x4 & t::Matrix4x4::operator/= ( double s)
inline

Divides the elements of this matrix with the specified constant.

Parameters
sA constant.
Returns
This matrix.

◆ operator[]()

double t::Matrix4x4::operator[] ( std::size_t index) const
inline

Returns the element at the specified index of this matrix without bounds checking and assuming row-major ordering.

The element at row \(i\) and column \(j\) of this matrix has the index \(4i + j\) assuming \(i\) and \(j\) are zero-based.

Parameters
indexThe 0-based index of the element in row-major order.
Returns
The element at the specified index of this matrix.
See also
get for accessing with bounds checking.

◆ reset()

Matrix4x4 & t::Matrix4x4::reset ( )
inline

Resets this matrix to the \(4 \times 4\) identity matrix.

Returns
This matrix.

◆ set() [1/2]

Matrix4x4 & t::Matrix4x4::set ( double _n11,
double _n12,
double _n13,
double _n14,
double _n21,
double _n22,
double _n23,
double _n24,
double _n31,
double _n32,
double _n33,
double _n34,
double _n41,
double _n42,
double _n43,
double _n44 )
inline

Sets the elements of this matrix.

Parameters
_n11The new \((1, 1)\) element of this matrix.
_n12The new \((1, 2)\) element of this matrix.
_n13The new \((1, 3)\) element of this matrix.
_n14The new \((1, 4)\) element of this matrix.
_n21The new \((2, 1)\) element of this matrix.
_n22The new \((2, 2)\) element of this matrix.
_n23The new \((2, 3)\) element of this matrix.
_n24The new \((2, 4)\) element of this matrix.
_n31The new \((3, 1)\) element of this matrix.
_n32The new \((3, 2)\) element of this matrix.
_n33The new \((3, 3)\) element of this matrix.
_n34The new \((3, 4)\) element of this matrix.
_n41The new \((4, 1)\) element of this matrix.
_n42The new \((4, 2)\) element of this matrix.
_n43The new \((4, 3)\) element of this matrix.
_n44The new \((4, 4)\) element of this matrix.
Returns
This matrix.

◆ set() [2/2]

Matrix4x4 & t::Matrix4x4::set ( int row,
int column,
int value )
inline

Sets the element at the specified row and column of this matrix to the specified value.

Parameters
rowThe 0-based index of the row of the element.
columnThe 0-based index of the column of the element.
valueThe new value for the element.
Returns
This matrix.

◆ topLeft3x3Matrix()

Matrix3x3 t::Matrix4x4::topLeft3x3Matrix ( ) const
inline

Returns the top-left \(3 \times 3\) matrix of this matrix.

For a transformation matrix, this method may be used to extract the rotation and scale components of the transformation, while discarding the translation component.

Returns
The top-left \(3 \times 3\) matrix of this matrix.

◆ transpose()

Matrix4x4 t::Matrix4x4::transpose ( ) const
inline

Returns the transpose of this matrix.

Note that this method does not modify this instance.

Returns
The transpose of this matrix.

◆ zero()

static Matrix4x4 t::Matrix4x4::zero ( )
inlinestatic

Returns a \(4 \times 4\) zero matrix.

Returns
A \(4 \times 4\) zero matrix.

Friends And Related Symbol Documentation

◆ operator* [1/4]

Matrix4x4 operator* ( const Matrix4x4 & a,
const Matrix4x4 & b )
friend

Multiplies two \(4 \times 4\) matrices.

Note that this is not an element-wise multiplication, but matrix multiplication.

Parameters
aA \(4 \times 4\) matrix.
bAnother \(4 \times 4\) matrix.
Returns
The matrix product of a and b.

◆ operator* [2/4]

Vector4 operator* ( const Matrix4x4 & a,
const Vector4 & v )
friend

Multiplies a \(4 \times 4\) matrix with a four-dimensional vector.

Parameters
aA \(4 \times 4\) matrix.
vA four-dimensional vector.
Returns
The product of a and v.

◆ operator* [3/4]

Matrix4x4 operator* ( const Matrix4x4 & a,
double s )
friend

Multiplies all elements of a \(4 \times 4\) matrix with a constant.

Parameters
aA \(4 \times 4\) matrix.
sA constant.
Returns
The resulting matrix when multiplying the elements of a with s.

◆ operator* [4/4]

Matrix4x4 operator* ( double s,
const Matrix4x4 & a )
friend

Multiplies all elements of a \(4 \times 4\) matrix with a constant.

Parameters
sA constant.
aA \(4 \times 4\) matrix.
Returns
The resulting matrix when multiplying the elements of a with s.

◆ operator+ [1/3]

Matrix4x4 operator+ ( const Matrix4x4 & a,
const Matrix4x4 & b )
friend

Adds two \(4 \times 4\) matrices.

Parameters
aA \(4 \times 4\) matrix.
bAnother \(4 \times 4\) matrix.
Returns
The sum of a and b.

◆ operator+ [2/3]

Matrix4x4 operator+ ( const Matrix4x4 & a,
double s )
friend

Adds a constant to all elements of a \(4 \times 4\) matrix.

Parameters
aA \(4 \times 4\) matrix.
sA constant.
Returns
The resulting matrix when adding s to all elements of a.

◆ operator+ [3/3]

Matrix4x4 operator+ ( double s,
const Matrix4x4 & a )
friend

Adds a constant to all elements of a \(4 \times 4\) matrix.

Parameters
sA constant.
aA \(4 \times 4\) matrix.
Returns
The resulting matrix when adding s to all elements of a.

◆ operator- [1/3]

Matrix4x4 operator- ( const Matrix4x4 & a,
const Matrix4x4 & b )
friend

Substracts 2 \(4 \times 4\) matrices.

Parameters
aA \(4 \times 4\) matrix.
bAnother \(4 \times 4\) matrix.
Returns
The difference of a and b.

◆ operator- [2/3]

Matrix4x4 operator- ( const Matrix4x4 & a,
double s )
friend

Substracts a constant from all elements of a \(4 \times 4\) matrix.

Parameters
aA \(4 \times 4\) matrix.
sA constant.
Returns
The resulting matrix when substracting s from all elements of a.

◆ operator- [3/3]

Matrix4x4 operator- ( double s,
const Matrix4x4 & a )
friend

Substracts a \(4 \times 4\) matrix from a \(4 \times 4\) constant matrix.

Parameters
sA constant for a \(4 \times 4\) constant matrix.
aA \(4 \times 4\) matrix.
Returns
The resulting matrix when substracting a from the constant matrix of s.

◆ operator/ [1/3]

Matrix4x4 operator/ ( const Matrix4x4 & a,
const Matrix4x4 & b )
friend

Returns the element-wise division of two \(4 \times 4\) matrices.

Parameters
aA \(4 \times 4\) matrix.
bAnother \(4 \times 4\) matrix.
Returns
The element-wise division of a and b.

◆ operator/ [2/3]

Matrix4x4 operator/ ( const Matrix4x4 & a,
double s )
friend

Divides all elements of a \(4 \times 4\) matrix by a constant.

Parameters
aA \(4 \times 4\) matrix.
sA constant.
Returns
The resulting matrix when dividing the elements of a by s.

◆ operator/ [3/3]

Matrix4x4 operator/ ( double s,
const Matrix4x4 & a )
friend

Returns the element-wise division of a \(4 \times 4\) constant matrix and a \(4 \times 4\) matrix.

Parameters
sA constant for a \(4 \times 4\) constant matrix.
aAnother \(4 \times 4\) matrix.
Returns
The element-wise division of the constant matrix and a.

◆ operator==

bool operator== ( const Matrix4x4 & a,
const Matrix4x4 & b )
friend

Returns whether two \(4 \times 4\) matrices are equal.

Parameters
aA \(4 \times 4\) matrix.
bAnother \(4 \times 4\) matrix.
Returns
true if a equals b, false otherwise.

The documentation for this class was generated from the following file: