Class Matrix3x3

Matrix with 3x3 elements.

Matrix3x3 constructors

Functions which can be used to create new instances of Matrix3x3.

Synopsis

Methods
Matrix3x3()

Default constructor, initializes the matrix to identity matrix

Matrix3x3()

Constructs the matrix from elements in column-major order

Matrix3x3()

Constructs the matrix from three column vectors

Matrix3x3()

Default constructor, initializes the matrix to identity matrix.

Example
local matrix3x3 = Matrix3x3()
Matrix3x3(x0, x1, x2, x3, x4, x5, x6, x7, x8)

Constructs the matrix from elements in column-major order.

Example
local matrix3x3 = Matrix3x3(x0, x1, x2, x3, x4, x5, x6, x7, x8)
Matrix3x3(x, y, translation)

Constructs the matrix from three column vectors.

Example
local matrix3x3 = Matrix3x3(x, y, translation)

Matrix3x3 methods

Methods of Matrix3x3 class.

Synopsis

Methods
Matrix3x3:getRow()

Gets the row of a matrix

Matrix3x3:getColumn()

Gets the column of a matrix

Matrix3x3:setRow()

Sets the row of a matrix

Matrix3x3:setColumn()

Sets the column of a matrix

Matrix3x3:getXAxis()

Get X axis

Matrix3x3:getYAxis()

Get Y axis

Matrix3x3:getScaleX()

Get X scale component

Matrix3x3:getScaleY()

Get Y scale component

Matrix3x3:getScale()

Get scale as a vector

Matrix3x3:scale()

Scales this matrix

Matrix3x3:translate()

Translates this matrix

Matrix3x3:setXAxis()

Set X axis

Matrix3x3:setYAxis()

Set Y axis

Matrix3x3:setTranslation()

Set translation

Matrix3x3:setTranslation()

Set translation

Matrix3x3:getTranslation()

Get translation

Matrix3x3:getTranslationX()

Get translation on X axis

Matrix3x3:setTranslationX()

Set translation on X axis

Matrix3x3:getTranslationY()

Get translation on Y axis

Matrix3x3:setTranslationY()

Set translation on Y axis

Matrix3x3:getRotationAngle()

Get rotation angle of the matrix

Matrix3x3.createTranslation()

Creates translation matrix

Matrix3x3.createTranslation()

Creates translation matrix

Matrix3x3.createScale()

Creates a scaled matrix

Matrix3x3.createIdentity()

Creates identity matrix

Matrix3x3.createRotationInDegrees()

Creates a rotation matrix

Matrix3x3.createRotationInRadians()

Creates a rotation matrix

Matrix3x3.createSRT()

Create an SRT matrix

Matrix3x3.createFilled()

Creates a matrix with all elements set to \p value

Matrix3x3:transposed()

Applies a transpose to a matrix

Matrix3x3:getRow(index)

Gets the row of a matrix.

Parameters
index (size_t)

Index of the accessed row.

Return Values
(Vector3)

The row.

Matrix3x3:getColumn(index)

Gets the column of a matrix.

Parameters
index (size_t)

Index of the accessed column.

Return Values
(Vector3)

The column.

Matrix3x3:setRow(index, row)

Sets the row of a matrix.

Parameters
index (size_t)

Index of the accessed row.

row (Vector3)

The value to set to the row.

Matrix3x3:setColumn(index, column)

Sets the column of a matrix.

Parameters
index (size_t)

Index of the accessed column.

column (Vector3)

The value to set to the column.

Matrix3x3:getXAxis()

Get X axis.

Matrix3x3:getYAxis()

Get Y axis.

Matrix3x3:getScaleX()

Get X scale component.

Matrix3x3:getScaleY()

Get Y scale component.

Matrix3x3:getScale()

Get scale as a vector.

Matrix3x3:scale(v)

Scales this matrix.

Parameters
v (Vector2)

Scaling vector.

Matrix3x3:translate(v)

Translates this matrix.

Parameters
v (Vector2)

Translation vector.

Matrix3x3:setXAxis(v)

Set X axis.

Parameters
v (Vector2)

X axis vector.

Matrix3x3:setYAxis(v)

Set Y axis.

Parameters
v (Vector2)

Y axis vector.

Matrix3x3:setTranslation(translation)

Set translation.

Parameters
translation (Vector2)

Translation vector.

Matrix3x3:setTranslation(translationX, translationY)

Set translation.

Parameters
translationX (float)

Translation X component.

translationY (float)

Translation Y component.

Matrix3x3:getTranslation()

Get translation.

Return Values
(Vector2)

Translation vector.

Matrix3x3:getTranslationX()

Get translation on X axis.

Return Values
(float)

Translation X component.

Matrix3x3:setTranslationX(translationX)

Set translation on X axis.

Parameters
translationX (float)

Translation X component.

Matrix3x3:getTranslationY()

Get translation on Y axis.

Return Values
(float)

Translation Y component.

Matrix3x3:setTranslationY(translationY)

Set translation on Y axis.

Parameters
translationY (float)

Translation Y component.

Matrix3x3:getRotationAngle()

Get rotation angle of the matrix.

Return Values
(float)

Rotation angle of the matrix.

Matrix3x3.createTranslation(translation)

Creates translation matrix.

Parameters
translation (Vector2)

Translation vector.

Return Values
(Matrix3x3)

Translation matrix.

Matrix3x3.createTranslation(x, y)

Creates translation matrix.

Parameters
x (float)

X component of the Translation vector.

y (float)

Y component of the Translation vector.

Return Values
(Matrix3x3)

Translation matrix.

Matrix3x3.createScale(scale)

Creates a scaled matrix.

Parameters
scale (Vector2)

Scaling vector.

Return Values
(Matrix3x3)

Scaled matrix.

Matrix3x3.createIdentity()

Creates identity matrix.

Return Values
(Matrix3x3)

Identity matrix.

Matrix3x3.createRotationInDegrees(angleInDegrees)

Creates a rotation matrix.

Parameters
angleInDegrees (float)

Rotation angle in degrees.

Return Values
(Matrix3x3)

Rotation matrix.

Matrix3x3.createRotationInRadians(angleInRadians)

Creates a rotation matrix.

Parameters
angleInRadians (float)

Rotation angle in radians.

Return Values
(Matrix3x3)

Rotation matrix.

Matrix3x3.createSRT(scale, rotationInRadians, translation)

Create an SRT matrix.

Parameters
scale (Vector2)

Scales by axises.

rotationInRadians (float)

Rotation component in radians.

translation (Vector2)

Translation component.

Return Values
(Matrix3x3)

Newly constructed matrix.

Matrix3x3.createFilled(value)

Creates a matrix with all elements set to \p value.

Parameters
value (float)

Value to set to all elements.

Return Values
(Matrix3x3)

The constructed matrix.

Matrix3x3:transposed()

Applies a transpose to a matrix.

Return Values
(Matrix3x3)

Newly constructed transpose matrix.

Matrix3x3 functions

Matrix3x3 specific standalone functions, which are not a part of the Matrix3x3 class.

Synopsis

Functions
inverse()

Applies an inversion to a matrix

inverseAffine()

Applies an inversion to an affine matrix

isTranslationOnly()

Determines whether a matrix is translation-only

isScalingOnly()

Determines whether a matrix is scaling-only

extractSRT()

Extracts scale, rotation and translation information from a matrix

normalized()

Normalizes the input matrix

matrixMultiplyVectorBy2x2()

Multiply a 2D vector with the top 2x2 part of a given matrix

getDeterminant()

Calculates the determinant of the matrix

getDeterminant2x2()

Calculates the determinant of the 2X2 part of a matrix

getTrace()

Calculates the trace of a matrix

componentWiseMultiply()

Multiplies matrix components component-wise and returns the resulting matrix

componentWiseDivide()

Divides matrix components component-wise and returns the resulting matrix

componentWiseMax()

Calculates the component-wise maximum for all matrix elements and returns the resulting matrix

componentWiseMin()

Calculates the component-wise minimum for all matrix elements and returns the resulting matrix

inverse(matrix)

Applies an inversion to a matrix.

Parameters
matrix (Matrix3x3)

Input matrix.

Return Values
(Matrix3x3 or nil)

Inverted matrix if the input matrix is invertible, nil otherwise.

inverseAffine(matrix)

Applies an inversion to an affine matrix.

Parameters
matrix (Matrix3x3)

Input matrix.

Return Values
(Matrix3x3 or nil)

Inverted matrix if the input matrix is invertible, nil otherwise.

isTranslationOnly(matrix)

Determines whether a matrix is translation-only.

Parameters
matrix (Matrix3x3)

Input matrix.

Return Values
(bool)

If the input matrix is translation-only, true, otherwise false.

isScalingOnly(matrix)

Determines whether a matrix is scaling-only. Note: This function allows translation.

Parameters
matrix (Matrix3x3)

Input matrix.

Return Values
(bool)

If the input matrix is scaling-only, true, otherwise false.

extractSRT(matrix)

Extracts scale, rotation and translation information from a matrix.

Example
local result, scale, rotationInRadians, translation = extractSRT(matrix)
Parameters
matrix (Matrix3x3)

Input matrix.

Return Values
1. (boolean)

True if the matrix could be decomposed and the extraction of SRT components succeeded, false otherwise.

2. (Vector2)

Scale vector.

3. (float)

Rotation angle, in radians.

4. (Vector2)

Translation vector.

normalized(matrix)

Normalizes the input matrix. The matrix must be an affine transformation.

Return Values
(Matrix3x3 or nil)

A normalized Matrix3x3.

matrixMultiplyVectorBy2x2(matrix, vector)

Multiply a 2D vector with the top 2x2 part of a given matrix.

Parameters
matrix (Matrix3x3)

The matrix that you want to multiply with a 2D vector.

vector (Vector2)

The 2D vector that you want to multiply with a matrix.

Return Values
(Vector2)

The result of the multiplication.

getDeterminant(matrix)

Calculates the determinant of the matrix.

Return Values
(float)

Determinant of the matrix.

getDeterminant2x2(matrix)

Calculates the determinant of the 2X2 part of a matrix.

Return Values
(float)

Determinant of the matrix.

getTrace(matrix)

Calculates the trace of a matrix.

Return Values
(float)

Trace of the matrix

componentWiseMultiply(m1, m2)

Multiplies matrix components component-wise and returns the resulting matrix.

Parameters
m1 (Matrix3x3)

The first matrix.

m2 (Matrix3x3)

The second matrix.

Return Values
(Matrix3x3)

The result matrix.

componentWiseDivide(m1, m2)

Divides matrix components component-wise and returns the resulting matrix.

Parameters
m1 (Matrix3x3)

The first matrix.

m2 (Matrix3x3)

The second matrix.

Return Values
(Matrix3x3)

The result matrix.

componentWiseMax(v1, v2)

Calculates the component-wise maximum for all matrix elements and returns the resulting matrix.

Parameters
v1 (Matrix3x3)

The first matrix.

v2 (Matrix3x3)

The second matrix.

Return Values
(Matrix3x3)

The result matrix.

componentWiseMin(v1, v2)

Calculates the component-wise minimum for all matrix elements and returns the resulting matrix.

Parameters
v1 (Matrix3x3)

The first matrix.

v2 (Matrix3x3)

The second matrix.

Return Values
(Matrix3x3)

The result matrix.