Matrix2
A matrix with 2 rows and 2 columns
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:
Name | Type | Description | Default |
---|---|---|---|
other | Matrix2 | - | - |
Returns:
Type | Description |
---|---|
Matrix2 | Returns 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:
Name | Type | Description | Default |
---|---|---|---|
other | Matrix2 | - | - |
Returns:
Type | Description |
---|---|
Matrix2 | Returns self for chaining |
Example:
myMat:sub(matrices.mat2():scale(2))
det()
Calculates and returns the determinant of this matrix
det()
Returns:
Type | Description |
---|---|
Number | - |
Example:
myMat:det()
invert()
Inverts this matrix, changing the values inside
Returns self for chaining
invert()
Returns:
Type | Description |
---|---|
Matrix2 | Returns self for chaining |
Example:
myMat:invert()
inverted()
Returns a copy of this matrix, but inverted
inverted()
Returns:
Type | Description |
---|---|
Matrix2 | Returns 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:
Name | Type | Description | Default |
---|---|---|---|
other | Matrix2 | - | - |
Returns:
Type | Description |
---|---|
Matrix2 | Returns 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:
Name | Type | Description | Default |
---|---|---|---|
other | Matrix2 | - | - |
Returns:
Type | Description |
---|---|
Matrix2 | Returns 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:
Name | Type | Description | Default |
---|---|---|---|
col | Integer | - | - |
Returns:
Type | Description |
---|---|
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:
Name | Type | Description | Default |
---|---|---|---|
row | Integer | - | - |
Returns:
Type | Description |
---|---|
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:
Name | Type | Description | Default |
---|---|---|---|
x | Number | - | - |
Returns:
Type | Description |
---|---|
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:
Name | Type | Description | Default |
---|---|---|---|
x | Number | - | - |
Returns:
Type | Description |
---|---|
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:
Name | Type | Description | Default |
---|---|---|---|
degrees | Number | - | - |
Returns:
Type | Description |
---|---|
Matrix2 | Returns self for chaining |
Example:
myMat:rotate(90)
scale()
Scales this matrix by the specified amount, changing the values inside
Returns self for chaining
- Overload 1
- Overload 2
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:
Type | Description |
---|---|
Matrix2 | Returns 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:
Type | Description |
---|---|
Matrix2 | Returns 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:
Name | Type | Description | Default |
---|---|---|---|
other | Matrix2 | - | - |
Returns:
Type | Description |
---|---|
Matrix2 | Returns 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:
Type | Description |
---|---|
Matrix3 | - |
Example:
myMat:augmented()
copy()
Creates and returns a new copy of this matrix
copy()
Returns:
Type | Description |
---|---|
Matrix2 | Returns self for chaining |
Example:
myMat:copy()
reset()
Resets this matrix back to the identity matrix
Returns self for chaining
reset()
Returns:
Type | Description |
---|---|
Matrix2 | Returns self for chaining |
Example:
myMat:reset()