Skip to main content

Matrix2

A matrix with 2 rows and 2 columns

warning

This page is a WIP. It contains all the information in Figura's documentation but we're working on adding more helpful descriptions.

For this entire page assume:

local myMat = matrices.mat2()

Math

add()

Adds the other matrix to this one

Returns self for chaining

add(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix2--

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:add(matrices.mat2():scale(2))

sub()

Subtracts the other matrix from this one

Returns self for chaining

sub(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix2--

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:sub(matrices.mat2():scale(2))

det()

Calculates and returns the determinant of this matrix

det()

Returns:

TypeDescription
Number-

Example:

myMat:det()

invert()

Inverts this matrix, changing the values inside

Returns self for chaining

invert()

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:invert()

inverted()

Returns a copy of this matrix, but inverted

inverted()

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:inverted()

multiply()

Multiplies this matrix by the other matrix, with the other matrix on the left

Returns self for chaining

multiply(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix2--

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:multiply(matrices.mat2():scale(2))

rightMultiply()

Multiplies this matrix by the other matrix, with the other matrix on the right

Returns self for chaining

rightMultiply(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix2--

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:rightMultiply(matrices.mat2():scale(2))

Accessors

getColumn()

Gets the given column of this matrix, as a vector

Indexing starts at 1, as usual

getColumn(col)

Parameters:

NameTypeDescriptionDefault
colInteger--

Returns:

TypeDescription
Vector2-

Example:

myMat:getColumn(1)

getRow()

Gets the given row of this matrix, as a vector

Indexing starts at 1, as usual

getRow(row)

Parameters:

NameTypeDescriptionDefault
rowInteger--

Returns:

TypeDescription
Vector2-

Example:

myMat:getRow(1)

Transformation

apply()

Treats the given values as a vector, augments this vector with a 1, multiplies it against the matrix, and returns a deaugmented vector of the first values

apply(x)

Parameters:

NameTypeDescriptionDefault
xNumber--

Returns:

TypeDescription
Number-

Example:

myMat:apply()

applyDir()

Treats the given values as a vector, augments this vector with a 0, multiplies it against the matrix, and returns a deaugmented vector of the first values

applyDir(x)

Parameters:

NameTypeDescriptionDefault
xNumber--

Returns:

TypeDescription
Number-

Example:

myMat:applyDir()

rotate()

Rotates this matrix by the specified amount, changing the values inside

Angles are given in degrees

Returns self for chaining

rotate(degrees)

Parameters:

NameTypeDescriptionDefault
degreesNumber--

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:rotate(90)

scale()

Scales this matrix by the specified amount, changing the values inside

Returns self for chaining

scale(vec)

Parameters:

NameTypeDescriptionDefault
vecVector2--

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:scale(2, 2)

transpose()

Transposes this matrix, changing the values inside

Transposing means to swap the rows and the columns

Returns self for chaining

transpose()

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:transpose()

transposed()

Returns a copy of this matrix, but transposed

Transposing means to swap the rows and the columns

transposed()

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:transposed()

Utility

set()

Sets this matrix to have the same values as the matrix passed in

Returns self for chaining

set(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix2--

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:set()

augmented()

Augments this matrix, adding an additional row and column

Puts a 1 along the diagonal in the new spot, and the rest are zero

augmented()

Returns:

TypeDescription
Matrix3-

Example:

myMat:augmented()

copy()

Creates and returns a new copy of this matrix

copy()

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:copy()

reset()

Resets this matrix back to the identity matrix

Returns self for chaining

reset()

Returns:

TypeDescription
Matrix2Returns self for chaining

Example:

myMat:reset()