Skip to content

Matrix3

Represents a 3×3 floating-point matrix.

This class represents a 3×3 matrix stored in column-major order, consistent with the rest of the math module. It is commonly used for linear transforms such as rotation, scaling, or for extracting the upper-left 3×3 portion of a Matrix4. The class supports construction from individual components, vectors, or a full 4×4 matrix, as well as element access and comparison.

Construction

Constructors


Matrix3() constexpr

Extracts the upper-left 3×3 block from a 4×4 matrix.

cpp
Matrix3::Matrix3(const Matrix4& mat);
ParameterDescription
matSource matrix.

Matrix3() constexpr

Constructs a matrix from three column vectors.

cpp
Matrix3::Matrix3(const Vector3& vec0, const Vector3& vec1, const Vector3& vec2);
ParameterDescription
vec0
vec1First column.
vec2Second column.

Matrix3() constexpr

Constructs a matrix from individual components (row-major).

cpp
Matrix3::Matrix3(float n00, float n01, float n02, float n10, float n11, float n12, float n20, float n21, float n22);
ParameterDescription
n00First row, first element.
n01First row, second element.
n02First row, third element.
n10Second row, first element.
n11Second row, second element.
n12Second row, third element.
n20Third row, first element.
n21Third row, second element.
n22Third row, third element.

Matrix3() constexpr

Constructs a diagonal matrix.

cpp
Matrix3::Matrix3(float value);
ParameterDescription
valueValue to place on the diagonal.

Functions

operator()() float &

Accesses an element by (row, column).

cpp
float& Matrix3::operator()(int row, int col);
ParameterDescription
rowRow index.
colColumn index.

operator()() const float

Accesses an element by (row, column).

cpp
const float Matrix3::operator()(int row, int col) const;
ParameterDescription
rowRow index.
colColumn index.

operator[]() Vector3&

Accesses a column vector.

cpp
Vector3& Matrix3::operator[](int col);
ParameterDescription
colColumn index.

operator[]() constVector3&

Accesses a column vector.

cpp
const Vector3& Matrix3::operator[](int col) const;
ParameterDescription
colColumn index.

Matrix3::Identity() Matrix3

Returns the identity matrix.

cpp
static constexpr Matrix3 Matrix3::Identity();

Determinant() float

Computes the determinant of a 3×3 matrix.

cpp
float Determinant(const Matrix3& mat);
ParameterDescription
matInput matrix.

Inverse() Matrix3

Computes the inverse of a 3×3 matrix.

cpp
Matrix3 Inverse(const Matrix3& mat);
ParameterDescription
matInput matrix.

operator*() Matrix3

Multiplies two 3×3 matrices.

cpp
Matrix3 operator* (const Matrix3& a, const Matrix3& b);
ParameterDescription
aLeft matrix.
bRight matrix.

operator*() Vector3

Multiplies a matrix by a vector.

cpp
Vector3 operator* (const Matrix3& mat, const Vector3& vec);
ParameterDescription
matInput matrix.
vecInput vector.

Transpose() Matrix3

Returns the transpose of a 3×3 matrix.

cpp
Matrix3 Transpose(const Matrix3& mat);
ParameterDescription
matInput matrix.

Released under the MIT License.