Scenic v0.10.2 Scenic.Math.Matrix View Source
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
add(matrix_a, matrix_b)
View Source
add(matrix_a :: Scenic.Math.matrix(), matrix_b :: Scenic.Math.matrix()) ::
Scenic.Math.matrix()
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
adjugate(matrix)
View Source
adjugate(matrix :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
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
build_rotate_around(angle, pin)
View Source
build_rotate_around(angle :: number(), pin :: Scenic.Math.point()) ::
Scenic.Math.matrix()
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
build_rotation(angle)
View Source
build_rotation(angle :: number()) :: Scenic.Math.matrix()
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
build_scale(scale)
View Source
build_scale(scale :: number() | Scenic.Math.vector_2()) :: Scenic.Math.matrix()
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
build_translation(vector_2)
View Source
build_translation(vector_2 :: Scenic.Math.vector_2()) :: Scenic.Math.matrix()
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
close?(matrix_a, matrix_b, tolerance \\ 1.0e-6)
View Source
close?(
matrix_a :: Scenic.Math.matrix(),
matrix_a :: Scenic.Math.matrix(),
tolerance :: number()
) :: boolean()
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
determinant(matrix)
View Source
determinant(matrix :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
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
div(matrix, scalar)
View Source
div(matrix :: Scenic.Math.matrix(), divisor :: number()) :: Scenic.Math.matrix()
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
get(matrix, x, y)
View Source
get(matrix :: Scenic.Math.matrix(), x :: number(), y :: number()) :: number()
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
get_xy(matrix)
View Source
get_xy(matrix :: Scenic.Math.matrix()) :: Scenic.Math.vector_2()
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
identity()
View Source
identity() :: Scenic.Math.matrix()
identity() :: Scenic.Math.matrix()
The identity matrix
invert(matrix)
View Source
invert(matrix :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
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
mul(matrix_list)
View Source
mul(matrix_list :: [Scenic.Math.matrix()]) :: Scenic.Math.matrix()
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
mul(matrix, multiplier)
View Source
mul(
matrix :: Scenic.Math.matrix(),
multiplier :: number() | Scenic.Math.matrix()
) :: Scenic.Math.matrix()
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
project_vector(matrix, arg)
View Source
project_vector(
matrix :: Scenic.Math.matrix(),
vector_2 :: Scenic.Math.vector_2()
) :: Scenic.Math.vector_2()
project_vector(
matrix :: Scenic.Math.matrix(),
vector_list :: [Scenic.Math.vector_2()]
) :: [Scenic.Math.vector_2()]
project_vector( matrix :: Scenic.Math.matrix(), vector_2 :: Scenic.Math.vector_2() ) :: Scenic.Math.vector_2()
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_vectors(a, vector_bin) View Source
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
put(matrix, x, y, v)
View Source
put(matrix :: Scenic.Math.matrix(), x :: number(), y :: number(), v :: number()) ::
Scenic.Math.matrix()
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
rotate(matrix, angle)
View Source
rotate(matrix :: Scenic.Math.matrix(), angle :: number() | nil) ::
Scenic.Math.matrix()
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
scale(matrix, scale)
View Source
scale(
matrix :: Scenic.Math.matrix(),
scale :: number() | Scenic.Math.vector_2() | nil
) :: Scenic.Math.matrix()
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
sub(matrix_a, matrix_b)
View Source
sub(matrix_a :: Scenic.Math.matrix(), matrix_b :: Scenic.Math.matrix()) ::
Scenic.Math.matrix()
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
translate(matrix, vector_2)
View Source
translate(
matrix :: Scenic.Math.matrix(),
vector_2 :: Scenic.Math.vector_2() | nil
) :: Scenic.Math.matrix()
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
transpose(matrix)
View Source
transpose(matrix :: Scenic.Math.matrix()) :: Scenic.Math.matrix()
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
zero()
View Source
zero() :: Scenic.Math.matrix()
zero() :: Scenic.Math.matrix()
A matrix where all the values are 0