# Matrix2D | data-structure-typed
Documentation for data-structure-typed

# Class Matrix2D

#### Hierarchy

- Matrix2D

- Defined in src/data-structures/matrix/matrix2d.ts:7

#####
Index

### Constructors

constructor

### Properties

_matrix

### Accessors

m
toVector
empty
identity

### Methods

add
multiply
multiplyByValue
multiplyByVector
rotate
scale
subtract
translate
view

## Constructors

### constructor

- new Matrix2D(value?): Matrix2D

- The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix or Vector2D object.

  #### Parameters

  - ##### `Optional` value: number[][] | Vector2D

    The `value` parameter can be either a 2D array of numbers (`number[][]`) or an instance of the `Vector2D` class.

  #### Returns Matrix2D

  - Defined in src/data-structures/matrix/matrix2d.ts:16

## Properties

### `Private` `Readonly` _matrix

_matrix: number[][]

- Defined in src/data-structures/matrix/matrix2d.ts:8

## Accessors

### m

- get m(): number[][]

- The function returns a two-dimensional array of numbers.

  #### Returns number[][]

  The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional array of numbers.

  - Defined in src/data-structures/matrix/matrix2d.ts:53

### toVector

- get toVector(): Vector2D

- The function "toVector" returns a new Vector2D object with the values from the first and second elements of the _matrix array.

  #### Returns Vector2D

  A new instance of the Vector2D class is being returned. The values of the returned vector are taken from the first column of the matrix.

  - Defined in src/data-structures/matrix/matrix2d.ts:63

### `Static` empty

- get empty(): number[][]

- The function returns a 2D array with three empty arrays.

  #### Returns number[][]

  An empty 2-dimensional array with 3 empty arrays inside.

  - Defined in src/data-structures/matrix/matrix2d.ts:33

### `Static` identity

- get identity(): number[][]

- The above function returns a 3x3 identity matrix.

  #### Returns number[][]

  The method is returning a 2-dimensional array of numbers representing the identity matrix.

  - Defined in src/data-structures/matrix/matrix2d.ts:41

## Methods

### `Static` add

- add(matrix1, matrix2): Matrix2D

- The function takes two 2D matrices as input and returns their sum as a new 2D matrix.

  #### Parameters

  - ##### matrix1: Matrix2D

    Matrix2D - The first matrix to be added.

  - ##### matrix2: Matrix2D

    The parameter `matrix2` is a Matrix2D object.

  #### Returns Matrix2D

  a new instance of the Matrix2D class, which is created using the result array.

  - Defined in src/data-structures/matrix/matrix2d.ts:73

### `Static` multiply

- multiply(matrix1, matrix2): Matrix2D

- The function multiplies two 2D matrices and returns the result as a new Matrix2D object.

  #### Parameters

  - ##### matrix1: Matrix2D

    A 2D matrix represented by the Matrix2D class.

  - ##### matrix2: Matrix2D

    The parameter `matrix2` is a 2D matrix of size 3x3.

  #### Returns Matrix2D

  a new instance of the Matrix2D class, created using the result array.

  - Defined in src/data-structures/matrix/matrix2d.ts:106

### `Static` multiplyByValue

- multiplyByValue(matrix, value): Matrix2D

- The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.

  #### Parameters

  - ##### matrix: Matrix2D

    The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D matrix. It contains a property `m` that is a 2D array representing the matrix elements.

  - ##### value: number

    The `value` parameter is a number that you want to multiply each element of the `matrix` by.

  #### Returns Matrix2D

  a new instance of the Matrix2D class, which is created using the result array.

  - Defined in src/data-structures/matrix/matrix2d.ts:126

### `Static` multiplyByVector

- multiplyByVector(matrix, vector): Vector2D

- The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.

  #### Parameters

  - ##### matrix: Matrix2D

    The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.

  - ##### vector: Vector2D

    The "vector" parameter is a 2D vector, represented by an object of type Vector2D.

  #### Returns Vector2D

  a Vector2D.

  - Defined in src/data-structures/matrix/matrix2d.ts:142

### `Static` rotate

- rotate(radians): Matrix2D

- The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.

  #### Parameters

  - ##### radians: number

    The "radians" parameter is the angle in radians by which you want to rotate an object.

  #### Returns Matrix2D

  The code is returning a new instance of a Matrix2D object.

  - Defined in src/data-structures/matrix/matrix2d.ts:181

### `Static` scale

- scale(factor): Matrix2D

- The function scales a matrix by a given factor.

  #### Parameters

  - ##### factor: number

    The factor parameter is a number that represents the scaling factor by which the matrix should be scaled.

  #### Returns Matrix2D

  the result of multiplying a new instance of Matrix2D by the given factor.

  - Defined in src/data-structures/matrix/matrix2d.ts:172

### `Static` subtract

- subtract(matrix1, matrix2): Matrix2D

- The function subtracts two 2D matrices and returns the result as a new Matrix2D object.

  #### Parameters

  - ##### matrix1: Matrix2D

    Matrix2D - The first matrix to subtract from.

  - ##### matrix2: Matrix2D

    Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array representing the matrix elements.

  #### Returns Matrix2D

  a new instance of the Matrix2D class, which is created using the result array.

  - Defined in src/data-structures/matrix/matrix2d.ts:90

### `Static` translate

- translate(vector): Matrix2D

- The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.

  #### Parameters

  - ##### vector: Vector2D

    The parameter "vector" is of type Vector2D. It represents a 2D vector with components x and y, and an optional w component.

  #### Returns Matrix2D

  The method is returning a new instance of the Matrix2D class.

  - Defined in src/data-structures/matrix/matrix2d.ts:197

### `Static` view

- view(width, height): Matrix2D

- The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.

  #### Parameters

  - ##### width: number

    The width parameter represents the width of the view or the canvas. It is a number that specifies the width in pixels or any other unit of measurement.

  - ##### height: number

    The height parameter represents the height of the view or the canvas. It is used to calculate the centerY value, which is the vertical center of the view.

  #### Returns Matrix2D

  a Matrix2D object.

  - Defined in src/data-structures/matrix/matrix2d.ts:154

Generated using TypeDoc