View Source Scenic.Math.Matrix (Scenic v0.11.2)
A collection of functions to work with matrices.
All the matrix fucntions in this module work exclusively with the binary form of a matrix, which is a compact binary of 16 4-byte floats.
If you would like to convert back and forth from the more human friendly list version, then please use the functions in Scenic.Math.Matrix.Utils
Link to this section Summary
Functions
Add two matrices together.
Calculate the adjugate of a matrix
Build a matrix that represents a 2D rotation around a point.
Build a matrix that represents a 2D rotation around the origin.
Build a matrix that represents a scaling operation.
Build a matrix that represents a simple translation.
Test if two matrices are close in value to each other.
Calculate the determinant of a matrix
Divide a matrix by a scalar.
Get a single value out of a binary matrix.
Extract the 2D vector represented by the matrix.
The identity matrix
Inverte a matrix.
Multiply a list of matrices together.
Multiply a matrix by another matrix or a scalar.
Project a vector by a matrix.
Project a list of vectors by a matrix.
Put a single value into a binary matrix.
Multiply a matrix by a rotation.
Multiply a matrix by a scale factor.
Subtract one matrix from another.
Multiply a matrix by a translation.
Transpose a matrix
A matrix where all the values are 0
Link to this section Functions
@spec add(matrix_a :: Scenic.Math.matrix(), matrix_b :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
Add two matrices together.
This operation is implemented as a NIF for performance.
Parameters:
- matrix_a: The first matrix
- matrix_b: The second matrix
Returns: The resulting matrix
@spec adjugate(matrix :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
Calculate the adjugate of a matrix
This operation is implemented as a NIF for performance.
Parameters:
- matrix: A matrix
Returns: The resulting matrix
@spec build_rotate_around(angle :: number(), pin :: Scenic.Math.point()) :: Scenic.Math.matrix()
Build a matrix that represents a 2D rotation around a point.
Parameters:
- angle: the amount to rotate, in radians
- pin: position to pin the rotation around
Returns: A binary matrix
@spec build_rotation(angle :: number()) :: Scenic.Math.matrix()
Build a matrix that represents a 2D rotation around the origin.
Parameters:
- angle: the amount to rotate, in radians
Returns: A binary matrix
@spec build_scale(scale :: number() | Scenic.Math.vector_2()) :: Scenic.Math.matrix()
Build a matrix that represents a scaling operation.
Parameters:
- scale: the amount to scale by. Can be either a number or a vector_2
Returns: A binary matrix
@spec build_translation(vector_2 :: Scenic.Math.vector_2()) :: Scenic.Math.matrix()
Build a matrix that represents a simple translation.
Parameters:
- vector_2: the vector defining how much to translate
Returns: A binary matrix
@spec close?( matrix_a :: Scenic.Math.matrix(), matrix_a :: Scenic.Math.matrix(), tolerance :: number() ) :: boolean()
Test if two matrices are close in value to each other.
Parameters:
- matrix_a: The first matrix
- matrix_b: The second matrix
- tolerance: Defines what close means. Defaults to: 0.000001
Returns: A boolean
@spec determinant(matrix :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
Calculate the determinant of a matrix
This operation is implemented as a NIF for performance.
Parameters:
- matrix: A matrix
Returns: The resulting matrix
@spec div(matrix :: Scenic.Math.matrix(), divisor :: number()) :: Scenic.Math.matrix()
Divide a matrix by a scalar.
This operation is implemented as a NIF for performance.
Parameters:
- matrix: A matrix
- divisor: A number (scalar) to divide by
Returns: The resulting matrix
@spec get(matrix :: Scenic.Math.matrix(), x :: number(), y :: number()) :: number()
Get a single value out of a binary matrix.
Parameters:
- matrix: The source matrix
- x: the column to pull the data from
- y: the row to pull the data from
Returns: A number
@spec get_xy(matrix :: Scenic.Math.matrix()) :: Scenic.Math.vector_2()
Extract the 2D vector represented by the matrix.
Parameters:
- matrix: The source matrix
Returns: A vector_2
@spec identity() :: Scenic.Math.matrix()
The identity matrix
@spec invert(matrix :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
Inverte a matrix.
This operation is implemented as a NIF for performance.
Parameters:
- matrix: A matrix
Returns: The resulting matrix
@spec mul(matrix_list :: [Scenic.Math.matrix()]) :: Scenic.Math.matrix()
Multiply a list of matrices together.
This operation is implemented as a NIF for performance.
Parameters:
- matrix_list: A list of matrices
Returns: The resulting matrix
@spec mul( matrix :: Scenic.Math.matrix(), multiplier :: number() | Scenic.Math.matrix() ) :: Scenic.Math.matrix()
Multiply a matrix by another matrix or a scalar.
This operation is implemented as a NIF for performance.
Parameters:
- matrix: A matrix
- multiplier: A number (scalar) or a matrix to multiply by
Returns: The resulting matrix
@spec project_vector( matrix :: Scenic.Math.matrix(), vector_2 :: Scenic.Math.vector_2() ) :: Scenic.Math.vector_2()
@spec project_vector( matrix :: Scenic.Math.matrix(), vector_list :: [Scenic.Math.vector_2()] ) :: [ Scenic.Math.vector_2() ]
Project a vector by a matrix.
This operation is implemented as a NIF for performance.
Parameters:
- matrix: A matrix
- vector: The vector to project
Returns: The projected vector
Project a list of vectors by a matrix.
This operation is implemented as a NIF for performance.
Parameters:
- matrix: A matrix
- vectors: The list of vectors to project
Returns: A list of projected vectors
@spec put(matrix :: Scenic.Math.matrix(), x :: number(), y :: number(), v :: number()) :: Scenic.Math.matrix()
Put a single value into a binary matrix.
Parameters:
- matrix: The source matrix
- x: the column to pull the data from
- y: the row to pull the data from
- v: the value to put into the matrix. Must be a number.
Returns: A number
@spec rotate(matrix :: Scenic.Math.matrix(), angle :: number() | nil) :: Scenic.Math.matrix()
Multiply a matrix by a rotation.
Parameters:
- matrix: The incoming source matrix
- angle: the amount to rotate, in radians or nil (which does nothing
Returns: A binary matrix
@spec scale( matrix :: Scenic.Math.matrix(), scale :: number() | Scenic.Math.vector_2() | nil ) :: Scenic.Math.matrix()
Multiply a matrix by a scale factor.
Parameters:
- matrix: The incoming source matrix
- scale: the amount to scale by. Can be either a number, a vector, or nil (which does nothing)
Returns: A binary matrix
@spec sub(matrix_a :: Scenic.Math.matrix(), matrix_b :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
Subtract one matrix from another.
This operation is implemented as a NIF for performance.
Parameters:
- matrix_a: The first matrix
- matrix_b: The second matrix, which is subtracted from the first
Returns: The resulting matrix
@spec translate( matrix :: Scenic.Math.matrix(), vector_2 :: Scenic.Math.vector_2() | nil ) :: Scenic.Math.matrix()
Multiply a matrix by a translation.
Parameters:
- matrix: The incoming source matrix
- vector_2: the vector to translate by or nil (which does nothing)
Returns: A binary matrix
@spec transpose(matrix :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
Transpose a matrix
This operation is implemented as a NIF for performance.
Parameters:
- matrix: A matrix
Returns: The resulting matrix
@spec zero() :: Scenic.Math.matrix()
A matrix where all the values are 0