template<std::size_t size, class T>
Magnum::Math::Matrix class

Square matrix.

Template parameters
size Matrix size
T Data type

See Operations with matrices and vectors for brief introduction.

Base classes

template<std::size_t cols, std::size_t rows, class T>
class RectangularMatrix
Rectangular matrix.

Derived classes

template<class T>
class Matrix3
2D transformation matrix
template<class T>
class Matrix4
3D transformation matrix
template<class T>
class Matrix3
2D transformation matrix
template<class T>
class Matrix4
3D transformation matrix

Public types

enum (anonymous): std::size_t { Size = size }
enum ZeroType { Zero } deprecated
Pass to constructor to create zero-filled matrix.
enum IdentityType { Identity } deprecated
Pass to constructor to create identity matrix.

Constructors, destructors, conversion operators

Matrix(IdentityInitT = IdentityInit, T value = T(1)) constexpr noexcept
Default constructor.
Matrix(ZeroInitT) explicit constexpr noexcept
Construct zero-filled matrix.

Matrix(NoInitT) explicit constexpr noexcept
Construct matrix without initializing the contents.

template<class... U>
Matrix(const Vector<size, T>& first, const U&... next) constexpr noexcept
Construct matrix from column vectors.
Matrix(T value) explicit constexpr noexcept
Construct matrix with one value for all elements.
template<class U>
Matrix(const RectangularMatrix<size, size, U>& other) explicit constexpr noexcept
Construct matrix from another of different type.
template<class U, class V = decltype(Implementation::RectangularMatrixConverter<size, size, T, U>::from(std::declval<U>()))>
Matrix(const U& other) explicit constexpr
Construct matrix from external representation.
Matrix(const RectangularMatrix<size, size, T>& other) constexpr noexcept
Copy constructor.

Public functions

auto isOrthogonal() const -> bool
Whether the matrix is orthogonal.
auto trace() const -> T
Trace of the matrix.
auto ij(std::size_t skipCol, std::size_t skipRow) const -> Matrix<size-1, T>
Matrix without given column and row.
auto determinant() const -> T
Determinant.
auto inverted() const -> Matrix<size, T>
Inverted matrix.
auto invertedOrthogonal() const -> Matrix<size, T>
Inverted orthogonal matrix.

Enum documentation

template<std::size_t size, class T>
enum Magnum::Math::Matrix<size, T>::(anonymous): std::size_t

Enumerators
Size

Matrix size

template<std::size_t size, class T>
enum Magnum::Math::Matrix<size, T>::ZeroType

Pass to constructor to create zero-filled matrix.

Enumerators
Zero

template<std::size_t size, class T>
enum Magnum::Math::Matrix<size, T>::IdentityType

Pass to constructor to create identity matrix.

Enumerators
Identity

Function documentation

template<std::size_t size, class T>
Magnum::Math::Matrix<size, T>::Matrix(IdentityInitT = IdentityInit, T value = T(1)) constexpr noexcept

Default constructor.

Creates identity matrix. value allows you to specify value on diagonal.

template<std::size_t size, class T> template<class U>
Magnum::Math::Matrix<size, T>::Matrix(const RectangularMatrix<size, size, U>& other) explicit constexpr noexcept

Construct matrix from another of different type.

Performs only default casting on the values, no rounding or anything else. Example usage:

Matrix2x2<Float> floatingPoint({1.3f, 2.7f},
                               {-15.0f, 7.0f});
Matrix2x2<Byte> integral(floatingPoint);
// integral == {{1, 2}, {-15, 7}}

template<std::size_t size, class T>
bool Magnum::Math::Matrix<size, T>::isOrthogonal() const

Whether the matrix is orthogonal.

The matrix is orthogonal if its transpose is equal to its inverse:

LaTeX Math \[ Q^T = Q^{-1} \]

template<std::size_t size, class T>
T Magnum::Math::Matrix<size, T>::trace() const

Trace of the matrix.

LaTeX Math \[ tr(A) = \sum_{i=1}^n a_{i,i} \]

template<std::size_t size, class T>
T Magnum::Math::Matrix<size, T>::determinant() const

Determinant.

Returns 0 if the matrix is noninvertible and 1 if the matrix is orthogonal. Computed recursively using Laplace's formula:

LaTeX Math \[ \det(A) = \sum_{j=1}^n (-1)^{i+j} a_{i,j} \det(A^{i,j}) \]

LaTeX Math $ A^{i, j} $ is matrix without i-th row and j-th column, see ij(). The formula is expanded down to 2x2 matrix, where the determinant is computed directly:

LaTeX Math \[ \det(A) = a_{0, 0} a_{1, 1} - a_{1, 0} a_{0, 1} \]

template<std::size_t size, class T>
Matrix<size, T> Magnum::Math::Matrix<size, T>::inverted() const

Inverted matrix.

Computed using Cramer's rule:

LaTeX Math \[ A^{-1} = \frac{1}{\det(A)} Adj(A) \]

See invertedOrthogonal(), Matrix3::invertedRigid() and Matrix4::invertedRigid() which are faster alternatives for particular matrix types.

template<std::size_t size, class T>
Matrix<size, T> Magnum::Math::Matrix<size, T>::invertedOrthogonal() const

Inverted orthogonal matrix.

Equivalent to transposed(), expects that the matrix is orthogonal.

LaTeX Math \[ A^{-1} = A^T \]