#include <Magnum/Math/Matrix.h>
template<std:: size_t size, class T>
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::class RectangularMatrix<size, size, T>
size_t cols, std:: size_t rows, class T> - Rectangular matrix.
Derived classes
Public types
-
enum (anonymous): std::
size_t { Size = size }
Constructors, destructors, conversion operators
- Matrix() constexpr noexcept
- Default constructor.
- Matrix(IdentityInitT, T value = T(1)) explicit constexpr noexcept
- Construct an identity matrix.
- Matrix(ZeroInitT) explicit constexpr noexcept
- Construct a zero-filled matrix.
-
Matrix(Magnum::
NoInitT) explicit constexpr noexcept - Construct without initializing the contents.
-
template<class ... U>Matrix(const Vector<size, T>& first, const U&... next) constexpr noexcept
- Construct from column vectors.
- Matrix(T value) explicit constexpr noexcept
- Construct with one value for all elements.
-
template<std::Matrix(const T(&data)[cols_][rows_]) explicit constexpr noexcept new in Git master
size_t cols_, std:: size_t rows_> - Construct from a fixed-size array.
-
template<class U>Matrix(const RectangularMatrix<size, size, U>& other) explicit constexpr noexcept
- Construct from a matrix of a different type.
-
template<class U, class = decltype(Implementation::RectangularMatrixConverter<size, size, T, U>::from(std::Matrix(const U& other) explicit constexpr
declval<U>()))> - Construct a matrix from external representation.
-
template<std::Matrix(IdentityInitT, const RectangularMatrix<otherCols, otherRows, T>& other, T value = T(1)) explicit constexpr noexcept new in Git master
size_t otherCols, std:: size_t otherRows> - Construct by slicing or expanding a matrix of different size, leaving the rest at identity.
-
template<std::Matrix(ZeroInitT, const RectangularMatrix<otherCols, otherRows, T>& other) explicit constexpr noexcept new in Git master
size_t otherCols, std:: size_t otherRows> - Construct by slicing or expanding a matrix of different size, leaving the rest at zero.
-
template<std::Matrix(const RectangularMatrix<otherCols, otherRows, T>& other, T value = T(1)) explicit constexpr noexcept new in Git master
size_t otherCols, std:: size_t otherRows> - Construct by slicing or expanding a matrix of different size.
- 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 cofactor(std::
size_t col, std:: size_t row) const -> T new in 2019.10 - Cofactor.
- auto comatrix() const -> Matrix<size, T> new in 2019.10
- Matrix of cofactors.
- auto adjugate() const -> Matrix<size, T> new in 2019.10
- Adjugate matrix.
- 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 |
Function documentation
template<std:: size_t size, class T>
Magnum:: Math:: Matrix<size, T>:: Matrix() constexpr noexcept
Default constructor.
Equivalent to Matrix(IdentityInitT, T).
template<std:: size_t size, class T>
Magnum:: Math:: Matrix<size, T>:: Matrix(IdentityInitT,
T value = T(1)) explicit constexpr noexcept
Construct an identity matrix.
The value
allows you to specify a value on diagonal.
template<std:: size_t size, class T>
Magnum:: Math:: Matrix<size, T>:: Matrix(ZeroInitT) explicit constexpr noexcept
Construct a zero-filled matrix.
Magnum:: Math:: Matrix<size, T>:: Matrix(const T(&data)[cols_][rows_]) explicit constexpr noexcept new in Git master
Construct from a fixed-size array.
Use from(const T*) to reinterpret an arbitrary pointer to a matrix.
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 from a matrix of a different type.
Performs only default casting on the values, no rounding or anything else. Example usage:
Matrix2x2 floatingPoint{Vector2{1.3f, 2.7f}, Vector2{-15.0f, 7.0f}}; Math::Matrix2x2<Byte> integral{floatingPoint}; // {{1, 2}, {-15, 7}}
Magnum:: Math:: Matrix<size, T>:: Matrix(IdentityInitT,
const RectangularMatrix<otherCols, otherRows, T>& other,
T value = T(1)) explicit constexpr noexcept new in Git master
Construct by slicing or expanding a matrix of different size, leaving the rest at identity.
If the other matrix has less columns or rows, the corresponding vectors and components are set to either zeros or value
on the diagonal.
Magnum:: Math:: Matrix<size, T>:: Matrix(ZeroInitT,
const RectangularMatrix<otherCols, otherRows, T>& other) explicit constexpr noexcept new in Git master
Construct by slicing or expanding a matrix of different size, leaving the rest at zero.
If the other matrix has less columns or rows, the corresponding vectors and components are set to zeros.
Magnum:: Math:: Matrix<size, T>:: Matrix(const RectangularMatrix<otherCols, otherRows, T>& other,
T value = T(1)) explicit constexpr noexcept new in Git master
Construct by slicing or expanding a matrix of different size.
Equivalent to Matrix(IdentityInitT, const RectangularMatrix<otherCols, otherRows, T>&, T). Note that this default is different from RectangularMatrix, where it's equivalent to the ZeroInit variant instead.
template<std:: size_t size, class T>
bool Magnum:: Math:: Matrix<size, T>:: isOrthogonal() const
Whether the matrix is orthogonal.
Also called an orthonormal matrix. Returns true
if all basis vectors have unit length and are orthogonal to each other. In other words, when its transpose is equal to its inverse:
template<std:: size_t size, class T>
T Magnum:: Math:: Matrix<size, T>:: trace() const
Trace of the matrix.
template<std:: size_t size, class T>
Matrix<size-1, T> Magnum:: Math:: Matrix<size, T>:: ij(std:: size_t skipCol,
std:: size_t skipRow) const
Matrix without given column and row.
For the following matrix , is defined as:
template<std:: size_t size, class T>
T Magnum:: Math:: Matrix<size, T>:: cofactor(std:: size_t col,
std:: size_t row) const new in 2019.10
Cofactor.
Cofactor of a matrix is defined as , with being without the i-th column and j-th row. For example, calculating of defined as
would be
template<std:: size_t size, class T>
Matrix<size, T> Magnum:: Math:: Matrix<size, T>:: comatrix() const new in 2019.10
Matrix of cofactors.
A cofactor matrix of a matrix is defined as the following, with each calculated as in cofactor().
template<std:: size_t size, class T>
Matrix<size, T> Magnum:: Math:: Matrix<size, T>:: adjugate() const new in 2019.10
Adjugate matrix.
. Transpose of a comatrix(), used for example to calculate an inverted() matrix.
template<std:: size_t size, class T>
T Magnum:: Math:: Matrix<size, T>:: determinant() const
Determinant.
Returns 0 if the matrix is noninvertible, ±1 if the matrix is orthogonal, 1 if it's a pure rotation and -1 if it contains a reflection. Computed recursively using Laplace's formula:
is without the i-th column and j-th row. The formula is recursed down to a 2x2 matrix, where the determinant is calculated directly:
template<std:: size_t size, class T>
Matrix<size, T> Magnum:: Math:: Matrix<size, T>:: inverted() const
Inverted matrix.
Calculated using Cramer's rule and adjugate(), or equivalently using a comatrix():
See invertedOrthogonal(), Matrix3::
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.