# Scenic.Math.Matrix (Scenic v0.10.3) 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

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

View Source

## Specs

```add(matrix_a :: Scenic.Math.matrix(), matrix_b :: Scenic.Math.matrix()) ::
Scenic.Math.matrix()```

This operation is implemented as a NIF for performance.

Parameters:

• matrix_a: The first matrix
• matrix_b: The second matrix

Returns: The resulting matrix

View Source

## Specs

`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

## Specs

```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

## Specs

`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

## Specs

`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

## Specs

`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

## Specs

```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

## Specs

`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

## Specs

`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

## Specs

`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

## Specs

`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

## Specs

`identity() :: Scenic.Math.matrix()`

The identity matrix

# invert(matrix)

View Source

## Specs

`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

## Specs

`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

## Specs

```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

## Specs

```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

## Specs

```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

## Specs

```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

## Specs

```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

## Specs

```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

## Specs

```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

## Specs

`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() :: Scenic.Math.matrix()`