mat3

Header file: include/mat3.h

mat3 is a column-major matrix with 3 columns and 3 rows.

\(mat3 = \begin{bmatrix} x.x & y.x & z.x \\ x.y & y.y & z.y \\ x.z & y.z & z.z \end{bmatrix}\)

Class variables

Type

Name

Description

nml::vec3

x

The first column of the mat3.

nml::vec3

y

The second column of the mat3.

nml::vec3

z

The third column of the mat3.

Class functions

Constructors

Name

Description

mat3()

Construct a ([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]) matrix.

mat3(float _value)

Construct a ([_value, _value, _value], [_value, _value, _value], [_value, _value, _value]) matrix.

mat3(float _xx, float _xy, float _xz, float _yx, float _yy, float _yz, float _zx, float _zy, float _zz)

Construct a ([_xx, _xy, _xz], [_yx, _yy, _yz], [_zx, _zy, _zz]) matrix.

mat3(float _xx, float _xy, float _xz, float _yx, float _yy, float _yz, const nml::vec3& _z)

Construct a ([_xx, _xy, _xz], [_yx, _yy, _yz], [_z.x, _z.y, _z.z]) matrix.

mat3(float _xx, float _xy, float _xz, const nml::vec3& _y, float _zx, float _zy, float _zz)

Construct a ([_xx, _xy, _xz], [_y.x, _y.y, _y.z], [_zx, _zy, _zz]) matrix.

mat3(const nml::vec3& _x, float _yy, float _yz, float _zx, float _zy, float _zz)

Construct a ([_x.x, _x.y, _x.z], [_yx, _yy, _yz], [_zx, _zy, _zz]) matrix.

mat3(float _xx, float _xy, float _xz, const nml::vec3& _y, const nml::vec3& _z)

Construct a ([_xx, _xy, _xz], [_y.x, _y.y, _y.z], [_z.x, _z.y, _z.z]) matrix.

mat3(const nml::vec3& _x, const nml::vec3& _y, float _zx, float _zy, float _zz)

Construct a ([_x.x, _x.y, _x.z], [_y.x, _y.y, _y.z], [_zx, _zy, _zz]) matrix.

mat3(const nml::vec3& _x, float _yx, float _yy, float _yz, const nml::vec3& _z)

Construct a ([_x.x, _x.y, _x.z], [_yx, _yy, _yz], [_z.x, _z.y, _z.z]) matrix.

mat3(const nml::vec3& _x, const nml::vec3& _y, const nml::vec3& _z)

Construct a ([_x.x, _x.y, _x.z], [_y.x, _y.y, _y.z], [_z.x, _z.y, _z.z]) matrix.

mat3(const float* _ptr)

Construct a matrix from a pointer.

mat3(const nml::mat4& _mat)

Construct a ([_mat.x.x, _mat.x.y, _mat.x.z], [_mat.y.x, _mat.y.y, _mat.y.z], [_mat.z.x, _mat.z.y, _mat.z.z]) matrix.

Operators

Name

Description

nml::mat3& operator+=(const nml::mat3& other)

Add a mat3 to the current mat3.

nml::mat3& operator-=(const nml::mat3& other)

Substract a mat3 from the current mat3.

nml::mat3& operator*=(const nml::mat3& other)

Multiply the current mat3 by a mat3.

nml::mat3& operator*=(const float other)

Multiply the current mat3 by a scalar.

nml::mat3& operator/=(const float other)

Divide the current mat3 by a scalar.

nml::vec3& operator[](size_t index)

Return a reference to x if index is 0, a reference to y if index is 1 or a reference to z if index is 2, else, throw an exception.

const nml::vec3& operator[](size_t index) const

Return a const reference to x if index is 0, a const reference to y if index is 1 or a const reference to z if index is 2, else, throw an exception.

Functions

Name

Description

float det() const

Return the determinant of the matrix.

std::array<std::pair<float, vec3>, 3> eigen() const

Return three eigenvalues and eigenvectors of the matrix. The matrix must be symmetrical.

float* data()

Return a pointer to the matrix’s elements.

Static Functions

Name

Description

nml::mat3 nml::mat3::identity()

Return a ([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]) identity matrix.

Namespace functions

Operators

Name

Description

nml::mat3 operator+(nml::mat3 lhs, const nml::mat3& rhs)

Return a mat3 that is the sum between two mat3.

nml::mat3 operator-(nml::mat3 lhs, const nml::mat3& rhs)

Return a mat3 that is the difference between two mat3.

nml::mat3 operator*(nml::mat3 lhs, const nml::mat3& rhs)

Return a mat3 that is the product between two mat3.

nml::vec3 operator*(nml::mat3 lhs, const nml::vec3& rhs)

Return a vec3 that is the product between a mat3 and a vec3.

nml::mat3 operator*(nml::mat3 lhs, const float rhs)

Return a mat3 that is the product between a mat3 and a scalar.

nml::mat3 operator*(float lhs, const nml::mat3& rhs)

Return a mat3 that is the product between a scalar and a mat3.

nml::mat3 operator/(nml::mat3 lhs, const float rhs)

Return a mat3 that is the quotient between a mat3 and a scalar.

bool operator==(const nml::mat3& lhs, const nml::mat3& rhs)

Return true if the two mat3 are identical, else, return false.

bool operator!=(const nml::mat3& lhs, const nml::mat3& rhs)

Return true if the two mat3 are different, else, return false.

Functions

Name

Description

nml::mat3 transpose(const nml::mat3& mat)

Return a mat3 where the columns of mat are the rows and the rows of mat are the columns.

nml::mat3 inverse(const nml::mat3& mat)

Return the inverse of a mat3.

nml::mat3 translate(const nml::vec2& translation)

Return a 2D translation matrix according to the translation vector.

nml::mat3 rotate(const float angle)

Return a 2D rotation matrix according to the angle (in radians).

nml::mat3 scale(const nml::vec2& scaling)

Return a 2D scaling matrix according to the scaling factors.

std::string nml::to_string(const nml::mat3& mat)

Return a mat3 as a string under the format “[[x.x, x.y, x.z], [y.x, y.y, y.z], [z.x, z.y, z.z]]”.