---
title: Namespace: mat2d
source: https://vjmap.com/en/doc/Namespace_mat2d.html
---

# Namespace: mat2d

### Table of contents

#### Type aliases

- [valueType](#valuetype)

#### Functions

- [add](#add)
- [clone](#clone)
- [copy](#copy)
- [create](#create)
- [determinant](#determinant)
- [equals](#equals)
- [exactEquals](#exactequals)
- [frob](#frob)
- [fromRotation](#fromrotation)
- [fromScaling](#fromscaling)
- [fromTranslation](#fromtranslation)
- [fromValues](#fromvalues)
- [identity](#identity)
- [invert](#invert)
- [multiply](#multiply)
- [multiplyScalar](#multiplyscalar)
- [multiplyScalarAndAdd](#multiplyscalarandadd)
- [rotate](#rotate)
- [scale](#scale)
- [set](#set)
- [str](#str)
- [subtract](#subtract)
- [translate](#translate)

### Type aliases

#### valueType

Ƭ **valueType**: [*mat2dtype*](#mat2dtype)

### Functions

#### add

▸ **add**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype), `b`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Adds two mat2d's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the first operand |
| `b` | [*mat2dtype*](#mat2dtype) | the second operand |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### clone

▸ **clone**(`a`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Creates a new mat2d initialized with values from an existing matrix

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*mat2dtype*](#mat2dtype) | matrix to clone |

**Returns:** [*mat2dtype*](#mat2dtype)

a new 2x3 matrix

___

#### copy

▸ **copy**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Copy the values from one mat2d to another

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the source matrix |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### create

▸ **create**(): [*mat2dtype*](#mat2dtype)

Creates a new identity mat2d

**Returns:** [*mat2dtype*](#mat2dtype)

a new 2x3 matrix

___

#### determinant

▸ **determinant**(`a`: [*mat2dtype*](#mat2dtype)): *number*

Calculates the determinant of a mat2d

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*mat2dtype*](#mat2dtype) | the source matrix |

**Returns:** *number*

determinant of a

___

#### equals

▸ **equals**(`a`: [*mat2dtype*](#mat2dtype), `b`: [*mat2dtype*](#mat2dtype)): *boolean*

Returns whether or not the matrices have approximately the same elements in the same position.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*mat2dtype*](#mat2dtype) | The first matrix. |
| `b` | [*mat2dtype*](#mat2dtype) | The second matrix. |

**Returns:** *boolean*

True if the matrices are equal, false otherwise.

___

#### exactEquals

▸ **exactEquals**(`a`: [*mat2dtype*](#mat2dtype), `b`: [*mat2dtype*](#mat2dtype)): *boolean*

Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*mat2dtype*](#mat2dtype) | The first matrix. |
| `b` | [*mat2dtype*](#mat2dtype) | The second matrix. |

**Returns:** *boolean*

True if the matrices are equal, false otherwise.

___

#### frob

▸ **frob**(`a`: [*mat2dtype*](#mat2dtype)): *number*

Returns Frobenius norm of a mat2d

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*mat2dtype*](#mat2dtype) | the matrix to calculate Frobenius norm of |

**Returns:** *number*

Frobenius norm

___

#### fromRotation

▸ **fromRotation**(`out`: [*mat2dtype*](#mat2dtype), `rad`: *number*): [*mat2dtype*](#mat2dtype)

Creates a matrix from a given angle
This is equivalent to (but much faster than):

    mat2d.identity(dest);
    mat2d.rotate(dest, dest, rad);

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | mat2d receiving operation result |
| `rad` | *number* | the angle to rotate the matrix by |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### fromScaling

▸ **fromScaling**(`out`: [*mat2dtype*](#mat2dtype), `v`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Creates a matrix from a vector scaling
This is equivalent to (but much faster than):

    mat2d.identity(dest);
    mat2d.scale(dest, dest, vec);

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | mat2d receiving operation result |
| `v` | [*mat2dtype*](#mat2dtype) | Scaling vector |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### fromTranslation

▸ **fromTranslation**(`out`: [*mat2dtype*](#mat2dtype), `v`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Creates a matrix from a vector translation
This is equivalent to (but much faster than):

    mat2d.identity(dest);
    mat2d.translate(dest, dest, vec);

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | mat2d receiving operation result |
| `v` | [*mat2dtype*](#mat2dtype) | Translation vector |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### fromValues

▸ **fromValues**(`a`: *number*, `b`: *number*, `c`: *number*, `d`: *number*, `tx`: *number*, `ty`: *number*): [*mat2dtype*](#mat2dtype)

Create a new mat2d with the given values

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | *number* | Component A (index 0) |
| `b` | *number* | Component B (index 1) |
| `c` | *number* | Component C (index 2) |
| `d` | *number* | Component D (index 3) |
| `tx` | *number* | Component TX (index 4) |
| `ty` | *number* | Component TY (index 5) |

**Returns:** [*mat2dtype*](#mat2dtype)

A new mat2d

___

#### identity

▸ **identity**(`out`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Set a mat2d to the identity matrix

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### invert

▸ **invert**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype) \| ``null``

Inverts a mat2d

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the source matrix |

**Returns:** [*mat2dtype*](#mat2dtype) \| ``null``

out

___

#### multiply

▸ **multiply**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype), `b`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Multiplies two mat2d's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the first operand |
| `b` | [*mat2dtype*](#mat2dtype) | the second operand |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### multiplyScalar

▸ **multiplyScalar**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype), `b`: *number*): [*mat2dtype*](#mat2dtype)

Multiply each element of the matrix by a scalar.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the matrix to scale |
| `b` | *number* | amount to scale the matrix's elements by |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### multiplyScalarAndAdd

▸ **multiplyScalarAndAdd**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype), `b`: [*mat2dtype*](#mat2dtype), `scale`: *number*): [*mat2dtype*](#mat2dtype)

Adds two mat2d's after multiplying each element of the second operand by a scalar value.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving vector |
| `a` | [*mat2dtype*](#mat2dtype) | the first operand |
| `b` | [*mat2dtype*](#mat2dtype) | the second operand |
| `scale` | *number* | the amount to scale b's elements by before adding |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### rotate

▸ **rotate**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype), `rad`: *number*): [*mat2dtype*](#mat2dtype)

Rotates a mat2d by the given angle

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the matrix to rotate |
| `rad` | *number* | the angle to rotate the matrix by |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### scale

▸ **scale**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype), `v`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Scales the mat2d by the dimensions in the given vec2

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the matrix to translate |
| `v` | [*mat2dtype*](#mat2dtype) | the vec2 to scale the matrix by |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### set

▸ **set**(`out`: [*mat2dtype*](#mat2dtype), `a`: *number*, `b`: *number*, `c`: *number*, `d`: *number*, `tx`: *number*, `ty`: *number*): [*mat2dtype*](#mat2dtype)

Set the components of a mat2d to the given values

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | *number* | Component A (index 0) |
| `b` | *number* | Component B (index 1) |
| `c` | *number* | Component C (index 2) |
| `d` | *number* | Component D (index 3) |
| `tx` | *number* | Component TX (index 4) |
| `ty` | *number* | Component TY (index 5) |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### str

▸ **str**(`a`: [*mat2dtype*](#mat2dtype)): *string*

Returns a string representation of a mat2d

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*mat2dtype*](#mat2dtype) | matrix to represent as a string |

**Returns:** *string*

string representation of the matrix

___

#### subtract

▸ **subtract**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype), `b`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Subtracts matrix b from matrix a

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the first operand |
| `b` | [*mat2dtype*](#mat2dtype) | the second operand |

**Returns:** [*mat2dtype*](#mat2dtype)

out

___

#### translate

▸ **translate**(`out`: [*mat2dtype*](#mat2dtype), `a`: [*mat2dtype*](#mat2dtype), `v`: [*mat2dtype*](#mat2dtype)): [*mat2dtype*](#mat2dtype)

Translates the mat2d by the dimensions in the given vec2

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*mat2dtype*](#mat2dtype) | the receiving matrix |
| `a` | [*mat2dtype*](#mat2dtype) | the matrix to translate |
| `v` | [*mat2dtype*](#mat2dtype) | the vec2 to translate the matrix by |

**Returns:** [*mat2dtype*](#mat2dtype)

out


<a name="modulesmat3md"></a>

[vjmap](#readmemd) / [Exports](#modulesmd) / mat3
