template <typename Scalar, size_t Rows, size_t Columns>
muu::matrix struct

A matrix.

Template parameters
Scalar The matrix's scalar component type.
Rows The number of rows in the matrix.
Columns The number of columns in the matrix.

Public types

using axis_angle_type = axis_angle<scalar_type>
The muu::axis_angle with the same scalar_type as this matrix.
using column_type = vector<scalar_type, rows>
The type of one column of this matrix.
using constants = muu::constants<matrix>
Compile-time constants for this matrix.
using determinant_type = std::conditional_t<is_integral<scalar_type>, impl::highest_ranked<make_signed<scalar_type>, int>, scalar_type>
The scalar type used for determinants. Always signed.
using euler_type = euler_angles<scalar_type>
The muu::euler_angles with the same scalar_type as this matrix.
using inverse_scalar_type = std::conditional_t<is_integral<scalar_type>, double, scalar_type>
The scalar type returned by inversion operations. Always floating-point.
using inverse_type = matrix<inverse_scalar_type, Rows, Columns>
The matrix type returned by inversion operations. Always floating-point.
using quaternion_type = quaternion<scalar_type>
The muu::quaternion with the same scalar_type as this matrix.
using row_type = vector<scalar_type, columns>
The type of one row of this matrix.
using scalar_type = Scalar
The type of each scalar component stored in this matrix.

Public static variables

static size_t columns constexpr
The number of columns in the matrix.
static size_t rows constexpr
The number of rows in the matrix.

Constructors, destructors, conversion operators

matrix() defaulted noexcept
Default constructor. Values are not initialized.
matrix(const matrix&) defaulted constexpr noexcept
Copy constructor.
matrix(scalar_type broadcast) explicit constexpr noexcept
Constructs a matrix by broadcasting a scalar value to all components.
template <typename... T>
matrix(scalar_type v0, scalar_type v1, const T&... vals) constexpr noexcept
Constructs a matrix from (row-major-ordered) scalars.
template <typename S, size_t R, size_t C>
matrix(const matrix<S, R, C>& mat) explicit constexpr noexcept
Enlarging/truncating/converting constructor.
template <typename T>
matrix(const T& obj) constexpr noexcept
Constructs a matrix from an implicitly bit-castable type.
template <typename S0, size_t D0, typename S1, size_t D1, typename... Cols>
matrix(const vector<S0, D0>& col0, const vector<S1, D1>& col1, const Cols&... cols) explicit constexpr noexcept
Constructs a matrix from a series of column vectors.

Public functions

auto operator=(const matrix&) -> matrix& defaulted constexpr noexcept
Copy-assigment operator.

Public variables

column_type m
The values in the matrix (stored column-major).

Addition

auto operator+() const -> matrix constexpr noexcept
Returns a componentwise copy of a matrix.
auto operator+=(const matrix& rhs) -> matrix& constexpr noexcept
Componentwise adds another matrix to this one.
auto operator+(const matrix& lhs, const matrix& rhs) -> matrix constexpr noexcept
Returns the componentwise addition of two matrices.

Column accessors

template <size_t C>
auto column() -> column_type& constexpr noexcept
Gets a reference to a specific column.
template <size_t C>
auto column() const -> constcolumn_type& constexpr noexcept
Gets a const reference to a specific column.
auto translation_column() -> column_type& constexpr noexcept
Returns a reference to the Translation column.
auto translation_column() const -> constcolumn_type& constexpr noexcept
Returns a const reference to the Translation column.
auto w_column() -> column_type& constexpr noexcept
Returns a reference to the W column (column 3).
auto w_column() const -> constcolumn_type& constexpr noexcept
Returns a const reference to the W column (column 3).
auto x_column() -> column_type& constexpr noexcept
Returns a reference to the X column (column 0).
auto x_column() const -> constcolumn_type& constexpr noexcept
Returns a const reference to the X axis column (column 0).
auto y_column() -> column_type& constexpr noexcept
Returns a reference to the Y column (column 1).
auto y_column() const -> constcolumn_type& constexpr noexcept
Returns a const reference to the Y column (column 1).
auto z_column() -> column_type& constexpr noexcept
Returns a reference to the Z column (column 2).
auto z_column() const -> constcolumn_type& constexpr noexcept
Returns a const reference to the Z column (column 2).

Division

auto operator/=(scalar_type rhs) -> matrix& constexpr noexcept
Componentwise multiplies this matrix by a scalar.
auto operator/(const matrix& lhs, scalar_type rhs) -> matrix constexpr noexcept
Returns the componentwise multiplication of a matrix by a scalar.

Equality (approximate)

template <typename T>
static auto approx_equal(const matrix& m1, const matrix<T, rows, columns>& m2, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) -> bool constexpr noexcept
Returns true if two matrices are approximately equal.
static auto approx_zero(const matrix& m, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if all the scalar components in a matrix are approximately equal to zero.
template <typename T>
auto approx_equal(const matrix<T, rows, columns>& m, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) const -> bool constexpr noexcept
Returns true if the matrix is approximately equal to another.
auto approx_zero(scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if all the scalar components in the matrix are approximately equal to zero.

Equality (exact)

static auto infinity_or_nan(const matrix& m) -> bool constexpr noexcept
Returns true if any of the scalar components of a matrix are infinity or NaN.
static auto zero(const matrix& m) -> bool constexpr noexcept
Returns true if all the scalar components of a matrix are exactly zero.
auto infinity_or_nan() const -> bool constexpr noexcept
Returns true if any of the scalar components of the matrix are infinity or NaN.
auto zero() const -> bool constexpr noexcept
Returns true if all the scalar components of the matrix are exactly zero.
template <typename T>
auto operator!=(const matrix& lhs, const matrix<T, rows, columns>& rhs) -> bool constexpr noexcept
Returns true if two matrices are not exactly equal.
template <typename T>
auto operator==(const matrix& lhs, const matrix<T, rows, columns>& rhs) -> bool constexpr noexcept
Returns true if two matrices are exactly equal.

Inverse & Determinant

static auto determinant(const matrix& m) -> determinant_type constexpr noexcept
Calculates the determinant of a matrix.
static auto invert(const matrix& m) -> inverse_type constexpr noexcept
Returns the inverse of a matrix.
auto determinant() -> determinant_type constexpr noexcept
Calculates the determinant of a matrix.
auto invert() -> matrix& constexpr noexcept
Inverts the matrix (in-place).

Multiplication

auto operator*=(const matrix& rhs) -> matrix& constexpr noexcept
Multiplies this matrix with another and assigns the result.
auto operator*=(scalar_type rhs) -> matrix& constexpr noexcept
Componentwise multiplies this matrix by a scalar.
template <size_t C>
auto operator*(const matrix& lhs, const matrix<scalar_type, columns, C>& rhs) -> matrix<scalar_type, rows, C> constexpr noexcept
Multiplies two matrices.
auto operator*(const matrix& lhs, const vector<scalar_type, columns>& rhs) -> column_type constexpr noexcept
Multiplies a matrix and a column vector.
auto operator*(const vector<scalar_type, rows>& lhs, const matrix& rhs) -> row_type constexpr noexcept
Multiplies a row vector and a matrix.
auto operator*(const matrix& lhs, scalar_type rhs) -> matrix constexpr noexcept
Returns the componentwise multiplication of a matrix and a scalar.
auto operator*(scalar_type lhs, const matrix& rhs) -> matrix constexpr noexcept
Returns the componentwise multiplication of a matrix and a scalar.

Orthonormalization

static auto orthonormalize(const matrix&) -> matrix constexpr noexcept
Orthonormalizes the 3x3 part of a rotation or transformation matrix.
static auto orthonormalized(const matrix&) -> bool constexpr noexcept
Returns true if the 3x3 part of a matrix is orthonormalized.
auto orthonormalize() -> matrix& constexpr noexcept
Orthonormalizes the 3x3 part of the matrix.
auto orthonormalized() const -> bool constexpr noexcept
Returns true if the 3x3 part of the matrix is orthonormalized.

Projection

static auto perspective_projection(scalar_type vertical_fov, scalar_type aspect_ratio, scalar_type near_clip, scalar_type far_clip) -> matrix constexpr noexcept
Creates a perspective projection matrix.
static auto perspective_projection(scalar_type vertical_fov, const vector<scalar_type, 2>& screen_size, scalar_type near_clip, scalar_type far_clip) -> matrix constexpr noexcept
Creates a perspective projection matrix.

Rotation

template <size_t R, size_t C>
static auto from_2d_rotation(const matrix<scalar_type, R, C>& rot) -> matrix constexpr noexcept
Creates a 2D rotation matrix from the lower 2x2 part of a matrix.
static auto from_3d_direction(const vector<scalar_type, 3>& dir) -> matrix constexpr noexcept
Creates a 3D rotation matrix from a forward direction vector.
template <size_t R, size_t C>
static auto from_3d_rotation(const matrix<scalar_type, R, C>& rot) -> matrix constexpr noexcept
Creates a 3D rotation matrix from the lower 3x3 part of a matrix.
static auto from_axes(const vector<Scalar, 2>& x, const vector<Scalar, 2>& y) -> matrix constexpr noexcept
Creates a 2D rotation matrix from x and y axis vectors.
static auto from_axes(const vector<Scalar, 3>& x, const vector<Scalar, 3>& y, const vector<Scalar, 3>& z) -> matrix constexpr noexcept
Creates a 3D rotation matrix from x, y and z axis vectors.
static auto from_axis_angle(const vector<scalar_type, 3>& axis, scalar_type angle) -> matrix constexpr noexcept
Creates a 3D rotation matrix from an axis and an angle.
static auto from_axis_angle(const axis_angle_type& aa) -> matrix constexpr noexcept
Creates a 3D rotation matrix from an axis and an angle.
static auto from_euler(scalar_type yaw, scalar_type pitch, scalar_type roll) -> matrix constexpr noexcept
Creates a 3D rotation matrix from a set of euler angles.
static auto from_euler(const euler_type& angles) -> matrix constexpr noexcept
Creates a 3D rotation matrix from a set of euler angles.
static auto from_quaternion(const quaternion_type& quat) -> matrix constexpr noexcept
Creates a 3D rotation matrix from a quaternion.
static auto from_rotation(const matrix<scalar_type, 2, 2>& rot) -> matrix constexpr noexcept
Creates a 2D rotation matrix from a 2x2 matrix.
static auto from_rotation(const matrix<scalar_type, 2, 3>& rot) -> matrix constexpr noexcept
Creates a 2D rotation matrix from a 2x3 matrix.
static auto from_rotation(const matrix<scalar_type, 3, 3>& rot) -> matrix constexpr noexcept
Creates a 3D rotation matrix from a 3x3 matrix.
static auto from_rotation(const matrix<scalar_type, 3, 4>& rot) -> matrix constexpr noexcept
Creates a 3D rotation matrix from a 3x4 matrix.
static auto from_rotation(const matrix<scalar_type, 4, 4>& rot) -> matrix constexpr noexcept
Creates a 3D rotation matrix from a 4x4 matrix.
auto has_2d_shear() const -> bool constexpr noexcept
Returns true if a 2D rotation matrix contains shear.
auto has_3d_shear() const -> bool constexpr noexcept
Returns true if a 3D rotation matrix contains shear.

Scalar accessors

auto data() const -> constscalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the matrix.
auto data() -> scalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the matrix.
template <size_t R, size_t C>
auto get() const -> constscalar_type& constexpr noexcept
Gets a reference to the scalar component at a specific row and column.
template <size_t R, size_t C>
auto get() -> scalar_type& constexpr noexcept
Gets a reference to the scalar component at a specific row and column.
auto operator()(size_t r, size_t c) const -> constscalar_type& constexpr noexcept
Gets a reference to the scalar component at a specific row and column.
auto operator()(size_t r, size_t c) -> scalar_type& constexpr noexcept
Gets a reference to the scalar component at a specific row and column.

Scaling

static auto from_2d_scale(scalar_type x, scalar_type y) -> matrix constexpr noexcept
Creates a scale matrix from x and y scalar components.
template <size_t D>
static auto from_2d_scale(const vector<scalar_type, D>& scale) -> matrix constexpr noexcept
Creates a scale matrix from the x and y components of a vector of arbitrary size.
static auto from_3d_scale(scalar_type x, scalar_type y, scalar_type z = Scalar{ 1 }) -> matrix constexpr noexcept
Creates a scale matrix from x, y and z scalar components.
template <size_t D>
static auto from_3d_scale(const vector<scalar_type, D>& scale) -> matrix constexpr noexcept
Creates a scale matrix from the x, y and z components of a vector of arbitrary size.
static auto from_scale(scalar_type x, scalar_type y) -> matrix constexpr noexcept
Creates a scale matrix from x and y scalar components.
static auto from_scale(scalar_type x, scalar_type y, scalar_type z) -> matrix constexpr noexcept
Creates a scale matrix from x, y and z scalar components.
static auto from_scale(const vector<scalar_type, 2>& scale) -> matrix constexpr noexcept
Creates a scale matrix from a 2D vector.
static auto from_scale(const vector<scalar_type, 3>& scale) -> matrix constexpr noexcept
Creates a scale matrix from a 3D vector.

Subtraction

auto operator-() const -> matrix constexpr noexcept
Returns a componentwise negation of a matrix.
auto operator-=(const matrix& rhs) -> matrix& constexpr noexcept
Componentwise subtracts another matrix from this one.
auto operator-(const matrix& lhs, const matrix& rhs) -> matrix constexpr noexcept
Returns the componentwise subtraction of two matrices.

Transformation

static auto extract_2d_scale(const matrix& mat) -> vector<scalar_type, 2> constexpr noexcept
Extracts the scale from a 2D transform matrix.
static auto extract_3d_scale(const matrix& mat) -> vector<scalar_type, 3> constexpr noexcept
Extracts the scale from a 3D transform matrix.
static auto transform_direction(const matrix& xform, const vector<scalar_type, 3>& dir) -> vector<scalar_type, 3> constexpr noexcept
Applies a matrix's 3d transformation to the given direction vector, ignorning translation and scale.
static auto transform_position(const matrix& xform, const vector<scalar_type, 3>& pos) -> vector<scalar_type, 3> constexpr noexcept
Applies a matrix's 3d transformation to the given vector.
static auto transform_without_translating(const matrix& xform, const vector<scalar_type, 3>& v) -> vector<scalar_type, 3> constexpr noexcept
Applies a matrix's 3d transformation to the given position or direction vector, ignorning translation.
auto extract_2d_scale() const -> vector<scalar_type, 2> constexpr noexcept
Extracts the scale from a 2D transform matrix.
auto extract_3d_scale() const -> vector<scalar_type, 3> constexpr noexcept
Extracts the scale from a 3D transform matrix.
auto transform_direction(const vector<scalar_type, 3>& dir) const -> vector<scalar_type, 3> constexpr noexcept
Applies a matrix's 3d transformation to the direction vector, ignorning translation and scale.
auto transform_position(const vector<scalar_type, 3>& pos) const -> vector<scalar_type, 3> constexpr noexcept
Applies the matrix's 3d transformation to the given vector.
auto transform_without_translating(const vector<scalar_type, 3>& v) const -> vector<scalar_type, 3> constexpr noexcept
Applies a matrix's 3d transformation to the position or direction vector, ignorning translation.
auto operator*(const matrix& xform, const vector<scalar_type, 3>& pos) -> vector<scalar_type, 3> constexpr noexcept
Applies the matrix's 3d transformation to the vector.

Translation

static auto from_2d_translation(scalar_type x, scalar_type y) -> matrix constexpr noexcept
Creates a translation matrix from x and y scalar components.
template <size_t D>
static auto from_2d_translation(const vector<scalar_type, D>& xlat) -> matrix constexpr noexcept
Creates a translation matrix from the x and y components of a vector of arbitrary size.
static auto from_3d_translation(scalar_type x, scalar_type y, scalar_type z = Scalar{}) -> matrix constexpr noexcept
Creates a translation matrix from x, y and z scalar components.
template <size_t D>
static auto from_3d_translation(const vector<scalar_type, D>& xlat) -> matrix constexpr noexcept
Creates a translation matrix from the x, y and z components of a vector of arbitrary size.
static auto from_translation(scalar_type x, scalar_type y) -> matrix constexpr noexcept
Creates a translation matrix from x and y scalar components.
static auto from_translation(scalar_type x, scalar_type y, scalar_type z) -> matrix constexpr noexcept
Creates a translation matrix from x, y and z scalar components.
static auto from_translation(const vector<scalar_type, 2>& xlat) -> matrix constexpr noexcept
Creates a translation matrix from a 2D vector.
static auto from_translation(const vector<scalar_type, 3>& xlat) -> matrix constexpr noexcept
Creates a translation matrix from a 3D vector.

Transposition

static auto transpose(const matrix& m) -> matrix<scalar_type, columns, rows> constexpr noexcept
Returns a transposed copy of a matrix.
auto transpose() -> matrix& constexpr noexcept
Transposes the matrix (in-place).

Friends

template <typename Char, typename Traits>
auto operator<<(std::basic_ostream<Char, Traits>& os, const matrix& m) -> std::basic_ostream<Char, Traits>&
Writes a matrix out to a text stream.

Function documentation

template <typename Scalar, size_t Rows, size_t Columns>
muu::matrix::matrix(scalar_type broadcast) explicit constexpr noexcept

Constructs a matrix by broadcasting a scalar value to all components.

Parameters
broadcast The value used to initialize each of the matrix's scalar components.
std::cout << matrix<int, 3, 3>{ 1 } << "\n";
{    1,    1,    1,
     1,    1,    1,
     1,    1,    1 }

template <typename Scalar, size_t Rows, size_t Columns>
template <typename... T>
muu::matrix::matrix(scalar_type v0, scalar_type v1, const T&... vals) constexpr noexcept

Constructs a matrix from (row-major-ordered) scalars.

Template parameters
T Types convertible to scalar_type.
Parameters
v0 Initial value for the matrix's first scalar component.
v1 Initial value for the matrix's second scalar component.
vals Initial values for the matrix's remaining scalar components.
// explicitly-sized matrices:
std::cout << matrix<int, 2, 3>{ 1, 2, 3, 4, 5, 6 } << "\n\n";

// 2x2, 2x3, 3x3, 3x4 and 4x4 matrices can be deduced automatically
// from 4, 6, 9, 12 and 16 inputs (respectively):
std::cout << matrix{ 1, 2, 3, 4 } << "\n\n";
std::cout << matrix{ 1, 2, 3, 4, 5, 6 } << "\n\n";
std::cout << matrix{ 1, 2, 3, 4, 5, 6, 7, 8, 9 } << "\n\n";
std::cout << matrix{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } << "\n\n";
std::cout << matrix{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } << "\n\n";
{    1,    2,
     3,    4 }

{    1,    2,    3,
     4,    5,    6 }

{    1,    2,    3,
     4,    5,    6,
     7,    8,    9 }

{    1,    2,    3,    4,
     5,    6,    7,    8,
     9,   10,   11,   12 }

{    1,    2,    3,    4,
     5,    6,    7,    8,
     9,   10,   11,   12,
    13,   14,   15,   16 }

Any scalar components not covered by the constructor's parameters are initialized to zero.

template <typename Scalar, size_t Rows, size_t Columns>
template <typename S, size_t R, size_t C>
muu::matrix::matrix(const matrix<S, R, C>& mat) explicit constexpr noexcept

Enlarging/truncating/converting constructor.

Template parameters
S Source matrix's scalar_type.
R Source matrix's row count.
C Source matrix's column count.
Parameters
mat Source matrix.

Copies source matrix's scalar components, casting if necessary:

matrix<int, 3, 3> m33 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::cout << m33 << "\n\n";

matrix<int, 2, 2> m22 = { m33 };
std::cout << m22 << "\n\n";

matrix<int, 4, 4> m44 = { m33 };
std::cout << m44 << "\n\n";
{    1,    2,    3,
     4,    5,    6,
     7,    8,    9 }

{    1,    2,
     4,    5 }

{    1,    2,    3,    0,
     4,    5,    6,    0,
     7,    8,    9,    0,
     0,    0,    0,    0 }

Any scalar components not covered by the constructor's parameters are initialized to zero.

template <typename Scalar, size_t Rows, size_t Columns>
template <typename T>
muu::matrix::matrix(const T& obj) constexpr noexcept

Constructs a matrix from an implicitly bit-castable type.

Template parameters
T A bit-castable type.

template <typename Scalar, size_t Rows, size_t Columns>
template <typename S0, size_t D0, typename S1, size_t D1, typename... Cols>
muu::matrix::matrix(const vector<S0, D0>& col0, const vector<S1, D1>& col1, const Cols&... cols) explicit constexpr noexcept

Constructs a matrix from a series of column vectors.

Template parameters
S0 scalar_type of the first column's initializer.
D0 Number of dimensions in the first column's initializer.
S1 scalar_type of the second column's initializer.
D1 Number of dimensions in the second column's initializer.
Cols Any additional column initializers.

Copies from the input columns, enlarging/truncating/casting as necessary:

matrix<int, 3, 3> m33{ vector{ 1, 2, 3 }, vector{ 4, 5, 6 }, vector{ 7, 8, 9 } };
std::cout << m33 << "\n\n";

matrix<int, 2, 2> m22{ vector{ 1, 2, 3 }, vector{ 4, 5, 6 } };
std::cout << m22 << "\n\n";
{    1,    4,    7,
     2,    5,    8,
     3,    6,    9 }

{    1,    4,
     2,    5 }

Any scalar components not covered by the constructor's parameters are initialized to zero.

template <typename Scalar, size_t Rows, size_t Columns>
column_type& muu::matrix::translation_column() constexpr noexcept

Returns a reference to the Translation column.

template <typename Scalar, size_t Rows, size_t Columns>
constcolumn_type& muu::matrix::translation_column() const constexpr noexcept

Returns a const reference to the Translation column.

template <typename Scalar, size_t Rows, size_t Columns>
column_type& muu::matrix::w_column() constexpr noexcept

Returns a reference to the W column (column 3).

template <typename Scalar, size_t Rows, size_t Columns>
constcolumn_type& muu::matrix::w_column() const constexpr noexcept

Returns a const reference to the W column (column 3).

template <typename Scalar, size_t Rows, size_t Columns>
column_type& muu::matrix::x_column() constexpr noexcept

Returns a reference to the X column (column 0).

template <typename Scalar, size_t Rows, size_t Columns>
constcolumn_type& muu::matrix::x_column() const constexpr noexcept

Returns a const reference to the X axis column (column 0).

template <typename Scalar, size_t Rows, size_t Columns>
column_type& muu::matrix::y_column() constexpr noexcept

Returns a reference to the Y column (column 1).

template <typename Scalar, size_t Rows, size_t Columns>
constcolumn_type& muu::matrix::y_column() const constexpr noexcept

Returns a const reference to the Y column (column 1).

template <typename Scalar, size_t Rows, size_t Columns>
column_type& muu::matrix::z_column() constexpr noexcept

Returns a reference to the Z column (column 2).

template <typename Scalar, size_t Rows, size_t Columns>
constcolumn_type& muu::matrix::z_column() const constexpr noexcept

Returns a const reference to the Z column (column 2).

template <typename Scalar, size_t Rows, size_t Columns>
template <typename T>
static bool muu::matrix::approx_equal(const matrix& m1, const matrix<T, rows, columns>& m2, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) constexpr noexcept

Returns true if two matrices are approximately equal.

template <typename Scalar, size_t Rows, size_t Columns>
static bool muu::matrix::approx_zero(const matrix& m, scalar_type epsilon = default_epsilon<scalar_type>) constexpr noexcept

Returns true if all the scalar components in a matrix are approximately equal to zero.

template <typename Scalar, size_t Rows, size_t Columns>
template <typename T>
bool muu::matrix::approx_equal(const matrix<T, rows, columns>& m, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) const constexpr noexcept

Returns true if the matrix is approximately equal to another.

template <typename Scalar, size_t Rows, size_t Columns>
bool muu::matrix::approx_zero(scalar_type epsilon = default_epsilon<scalar_type>) const constexpr noexcept

Returns true if all the scalar components in the matrix are approximately equal to zero.

template <typename Scalar, size_t Rows, size_t Columns>
static bool muu::matrix::zero(const matrix& m) constexpr noexcept

Returns true if all the scalar components of a matrix are exactly zero.

template <typename Scalar, size_t Rows, size_t Columns>
bool muu::matrix::zero() const constexpr noexcept

Returns true if all the scalar components of the matrix are exactly zero.

template <typename Scalar, size_t Rows, size_t Columns>
template <typename T>
bool muu::matrix::operator!=(const matrix& lhs, const matrix<T, rows, columns>& rhs) constexpr noexcept

Returns true if two matrices are not exactly equal.

template <typename Scalar, size_t Rows, size_t Columns>
template <typename T>
bool muu::matrix::operator==(const matrix& lhs, const matrix<T, rows, columns>& rhs) constexpr noexcept

Returns true if two matrices are exactly equal.

template <typename Scalar, size_t Rows, size_t Columns>
static determinant_type muu::matrix::determinant(const matrix& m) constexpr noexcept

Calculates the determinant of a matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static inverse_type muu::matrix::invert(const matrix& m) constexpr noexcept

Returns the inverse of a matrix.

template <typename Scalar, size_t Rows, size_t Columns>
determinant_type muu::matrix::determinant() constexpr noexcept

Calculates the determinant of a matrix.

template <typename Scalar, size_t Rows, size_t Columns>
matrix& muu::matrix::invert() constexpr noexcept

Inverts the matrix (in-place).

template <typename Scalar, size_t Rows, size_t Columns>
matrix& muu::matrix::operator*=(const matrix& rhs) constexpr noexcept

Multiplies this matrix with another and assigns the result.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t C>
matrix<scalar_type, rows, C> muu::matrix::operator*(const matrix& lhs, const matrix<scalar_type, columns, C>& rhs) constexpr noexcept

Multiplies two matrices.

Template parameters
C The number of columns in the RHS matrix.
Parameters
lhs The LHS matrix.
rhs The RHS matrix.
Returns The result of lhs * rhs.

template <typename Scalar, size_t Rows, size_t Columns>
column_type muu::matrix::operator*(const matrix& lhs, const vector<scalar_type, columns>& rhs) constexpr noexcept

Multiplies a matrix and a column vector.

Parameters
lhs The LHS matrix.
rhs The RHS column vector.
Returns The result of lhs * rhs.

template <typename Scalar, size_t Rows, size_t Columns>
row_type muu::matrix::operator*(const vector<scalar_type, rows>& lhs, const matrix& rhs) constexpr noexcept

Multiplies a row vector and a matrix.

Parameters
lhs The LHS row vector.
rhs The RHS matrix.
Returns The result of lhs * rhs.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::orthonormalize(const matrix&) constexpr noexcept

Orthonormalizes the 3x3 part of a rotation or transformation matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static bool muu::matrix::orthonormalized(const matrix&) constexpr noexcept

Returns true if the 3x3 part of a matrix is orthonormalized.

template <typename Scalar, size_t Rows, size_t Columns>
matrix& muu::matrix::orthonormalize() constexpr noexcept

Orthonormalizes the 3x3 part of the matrix.

template <typename Scalar, size_t Rows, size_t Columns>
bool muu::matrix::orthonormalized() const constexpr noexcept

Returns true if the 3x3 part of the matrix is orthonormalized.

template <typename Scalar, size_t Rows, size_t Columns>
template <math_apis Mode = (math_apis::directx | math_apis::right_handed)>
static matrix muu::matrix::perspective_projection(scalar_type vertical_fov, scalar_type aspect_ratio, scalar_type near_clip, scalar_type far_clip) constexpr noexcept

Creates a perspective projection matrix.

Template parameters
Mode Select the combination of flags for your math/graphics API.
Parameters
vertical_fov Vertical field-of-view in radians.
aspect_ratio Screen aspect ratio (width / height).
near_clip The camera's near-clip plane distance.
far_clip The camera's far-clip plane distance.

template <typename Scalar, size_t Rows, size_t Columns>
template <math_apis Mode = (math_apis::directx | math_apis::right_handed)>
static matrix muu::matrix::perspective_projection(scalar_type vertical_fov, const vector<scalar_type, 2>& screen_size, scalar_type near_clip, scalar_type far_clip) constexpr noexcept

Creates a perspective projection matrix.

Template parameters
Mode Select the combination of flags for your math/graphics API.
Parameters
vertical_fov Vertical field-of-view in radians.
screen_size The screen's size (width + height).
near_clip The camera's near-clip plane distance.
far_clip The camera's far-clip plane distance.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t R, size_t C>
static matrix muu::matrix::from_2d_rotation(const matrix<scalar_type, R, C>& rot) constexpr noexcept

Creates a 2D rotation matrix from the lower 2x2 part of a matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_3d_direction(const vector<scalar_type, 3>& dir) constexpr noexcept

Creates a 3D rotation matrix from a forward direction vector.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t R, size_t C>
static matrix muu::matrix::from_3d_rotation(const matrix<scalar_type, R, C>& rot) constexpr noexcept

Creates a 3D rotation matrix from the lower 3x3 part of a matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_axes(const vector<Scalar, 2>& x, const vector<Scalar, 2>& y) constexpr noexcept

Creates a 2D rotation matrix from x and y axis vectors.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_axes(const vector<Scalar, 3>& x, const vector<Scalar, 3>& y, const vector<Scalar, 3>& z) constexpr noexcept

Creates a 3D rotation matrix from x, y and z axis vectors.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_axis_angle(const vector<scalar_type, 3>& axis, scalar_type angle) constexpr noexcept

Creates a 3D rotation matrix from an axis and an angle.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_axis_angle(const axis_angle_type& aa) constexpr noexcept

Creates a 3D rotation matrix from an axis and an angle.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_euler(scalar_type yaw, scalar_type pitch, scalar_type roll) constexpr noexcept

Creates a 3D rotation matrix from a set of euler angles.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_euler(const euler_type& angles) constexpr noexcept

Creates a 3D rotation matrix from a set of euler angles.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_quaternion(const quaternion_type& quat) constexpr noexcept

Creates a 3D rotation matrix from a quaternion.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_rotation(const matrix<scalar_type, 2, 2>& rot) constexpr noexcept

Creates a 2D rotation matrix from a 2x2 matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_rotation(const matrix<scalar_type, 2, 3>& rot) constexpr noexcept

Creates a 2D rotation matrix from a 2x3 matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_rotation(const matrix<scalar_type, 3, 3>& rot) constexpr noexcept

Creates a 3D rotation matrix from a 3x3 matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_rotation(const matrix<scalar_type, 3, 4>& rot) constexpr noexcept

Creates a 3D rotation matrix from a 3x4 matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_rotation(const matrix<scalar_type, 4, 4>& rot) constexpr noexcept

Creates a 3D rotation matrix from a 4x4 matrix.

template <typename Scalar, size_t Rows, size_t Columns>
bool muu::matrix::has_2d_shear() const constexpr noexcept

Returns true if a 2D rotation matrix contains shear.

template <typename Scalar, size_t Rows, size_t Columns>
bool muu::matrix::has_3d_shear() const constexpr noexcept

Returns true if a 3D rotation matrix contains shear.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t R, size_t C>
constscalar_type& muu::matrix::get() const constexpr noexcept

Gets a reference to the scalar component at a specific row and column.

Template parameters
R The row of the scalar component to retrieve.
C The column of the scalar component to retrieve.
Returns A reference to the selected scalar component.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t R, size_t C>
scalar_type& muu::matrix::get() constexpr noexcept

Gets a reference to the scalar component at a specific row and column.

Template parameters
R The row of the scalar component to retrieve.
C The column of the scalar component to retrieve.
Returns A reference to the selected scalar component.

template <typename Scalar, size_t Rows, size_t Columns>
constscalar_type& muu::matrix::operator()(size_t r, size_t c) const constexpr noexcept

Gets a reference to the scalar component at a specific row and column.

Parameters
r The row of the scalar component to retrieve.
c The column of the scalar component to retrieve.
Returns A reference to the selected scalar component.

template <typename Scalar, size_t Rows, size_t Columns>
scalar_type& muu::matrix::operator()(size_t r, size_t c) constexpr noexcept

Gets a reference to the scalar component at a specific row and column.

Parameters
r The row of the scalar component to retrieve.
c The column of the scalar component to retrieve.
Returns A reference to the selected scalar component.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_2d_scale(scalar_type x, scalar_type y) constexpr noexcept

Creates a scale matrix from x and y scalar components.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t D>
static matrix muu::matrix::from_2d_scale(const vector<scalar_type, D>& scale) constexpr noexcept

Creates a scale matrix from the x and y components of a vector of arbitrary size.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_3d_scale(scalar_type x, scalar_type y, scalar_type z = Scalar{ 1 }) constexpr noexcept

Creates a scale matrix from x, y and z scalar components.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t D>
static matrix muu::matrix::from_3d_scale(const vector<scalar_type, D>& scale) constexpr noexcept

Creates a scale matrix from the x, y and z components of a vector of arbitrary size.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_scale(scalar_type x, scalar_type y) constexpr noexcept

Creates a scale matrix from x and y scalar components.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_scale(scalar_type x, scalar_type y, scalar_type z) constexpr noexcept

Creates a scale matrix from x, y and z scalar components.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_scale(const vector<scalar_type, 2>& scale) constexpr noexcept

Creates a scale matrix from a 2D vector.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_scale(const vector<scalar_type, 3>& scale) constexpr noexcept

Creates a scale matrix from a 3D vector.

template <typename Scalar, size_t Rows, size_t Columns>
static vector<scalar_type, 2> muu::matrix::extract_2d_scale(const matrix& mat) constexpr noexcept

Extracts the scale from a 2D transform matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static vector<scalar_type, 3> muu::matrix::extract_3d_scale(const matrix& mat) constexpr noexcept

Extracts the scale from a 3D transform matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static vector<scalar_type, 3> muu::matrix::transform_direction(const matrix& xform, const vector<scalar_type, 3>& dir) constexpr noexcept

Applies a matrix's 3d transformation to the given direction vector, ignorning translation and scale.

Returns The result of transforming the 3D direction by the matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static vector<scalar_type, 3> muu::matrix::transform_position(const matrix& xform, const vector<scalar_type, 3>& pos) constexpr noexcept

Applies a matrix's 3d transformation to the given vector.

Returns The result of transforming the 3D position by the matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static vector<scalar_type, 3> muu::matrix::transform_without_translating(const matrix& xform, const vector<scalar_type, 3>& v) constexpr noexcept

Applies a matrix's 3d transformation to the given position or direction vector, ignorning translation.

Returns The result of transforming the 3D vector by the matrix.

template <typename Scalar, size_t Rows, size_t Columns>
vector<scalar_type, 2> muu::matrix::extract_2d_scale() const constexpr noexcept

Extracts the scale from a 2D transform matrix.

template <typename Scalar, size_t Rows, size_t Columns>
vector<scalar_type, 3> muu::matrix::extract_3d_scale() const constexpr noexcept

Extracts the scale from a 3D transform matrix.

template <typename Scalar, size_t Rows, size_t Columns>
vector<scalar_type, 3> muu::matrix::transform_direction(const vector<scalar_type, 3>& dir) const constexpr noexcept

Applies a matrix's 3d transformation to the direction vector, ignorning translation and scale.

Returns The result of transforming the 3D direction by the matrix.

template <typename Scalar, size_t Rows, size_t Columns>
vector<scalar_type, 3> muu::matrix::transform_position(const vector<scalar_type, 3>& pos) const constexpr noexcept

Applies the matrix's 3d transformation to the given vector.

Returns The result of transforming the 3D position by the matrix.

template <typename Scalar, size_t Rows, size_t Columns>
vector<scalar_type, 3> muu::matrix::transform_without_translating(const vector<scalar_type, 3>& v) const constexpr noexcept

Applies a matrix's 3d transformation to the position or direction vector, ignorning translation.

Returns The result of transforming the 3D vector by the matrix.

template <typename Scalar, size_t Rows, size_t Columns>
vector<scalar_type, 3> muu::matrix::operator*(const matrix& xform, const vector<scalar_type, 3>& pos) constexpr noexcept

Applies the matrix's 3d transformation to the vector.

Returns The result of transforming the 3D position by the matrix.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_2d_translation(scalar_type x, scalar_type y) constexpr noexcept

Creates a translation matrix from x and y scalar components.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t D>
static matrix muu::matrix::from_2d_translation(const vector<scalar_type, D>& xlat) constexpr noexcept

Creates a translation matrix from the x and y components of a vector of arbitrary size.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_3d_translation(scalar_type x, scalar_type y, scalar_type z = Scalar{}) constexpr noexcept

Creates a translation matrix from x, y and z scalar components.

template <typename Scalar, size_t Rows, size_t Columns>
template <size_t D>
static matrix muu::matrix::from_3d_translation(const vector<scalar_type, D>& xlat) constexpr noexcept

Creates a translation matrix from the x, y and z components of a vector of arbitrary size.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_translation(scalar_type x, scalar_type y) constexpr noexcept

Creates a translation matrix from x and y scalar components.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_translation(scalar_type x, scalar_type y, scalar_type z) constexpr noexcept

Creates a translation matrix from x, y and z scalar components.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_translation(const vector<scalar_type, 2>& xlat) constexpr noexcept

Creates a translation matrix from a 2D vector.

template <typename Scalar, size_t Rows, size_t Columns>
static matrix muu::matrix::from_translation(const vector<scalar_type, 3>& xlat) constexpr noexcept

Creates a translation matrix from a 3D vector.

template <typename Scalar, size_t Rows, size_t Columns>
matrix& muu::matrix::transpose() constexpr noexcept

Transposes the matrix (in-place).

template <typename Scalar, size_t Rows, size_t Columns>
template <typename S, size_t R, size_t C>
determinant_type determinant(const matrix<S, R, C>& m) constexpr noexcept

Calculates the determinant of a matrix.

template <typename Scalar, size_t Rows, size_t Columns>
template <typename S, size_t R, size_t C>
inverse_type invert(const matrix<S, R, C>& m) constexpr noexcept

Returns the inverse of a matrix.

template <typename Scalar, size_t Rows, size_t Columns>
template <typename S, size_t R, size_t C>
matrix<S, R, C> orthonormalize(const matrix<S, R, C>& m) constexpr noexcept

Returns a copy of a matrix with the 3x3 part orthonormalized.