Matrix
Extends:
A class for storing values in rows and columns and for doing common matrix operations. As the Vector class, this extends the js Array class.
Values are stores columns-first internally, but is normally instantiated by supplying values in rows-first order.
Static Method Summary
Static Public Methods | ||
public static |
Instantiate a matrix from an array. |
|
public static |
fromVectors(vectors: ...number[]): Matrix Create a matrix from vectors. |
|
public static |
Creates an identity matrix with rows and columns equal to size. |
|
public static |
Traverse an array as a matrix, either rows-first or columns first. |
Constructor Summary
Public Constructor | ||
public |
Constructs a new instance of Matrix. |
Member Summary
Public Members | ||
public |
[i]: * assign value |
|
public |
[idx]: * assign value |
|
public get |
Get the number of columns in this matrix. |
|
public get |
isSquare: boolan: * This function returns true if this matrix has the same number of rows as columns, otherwise false. |
|
public get |
Get the number of rows in this matrix. |
Private Members | ||
private |
_c: * internal property to hold number of columns of this matrix |
|
private |
_r: * internal property to hold number of rows of this matrix |
Method Summary
Public Methods | ||
public |
Clone/copy this matrix |
|
public |
Get the values from a specific column. |
|
public |
columnsFirst(): number[] Returns a native javascript Array representation of this matrix, in rows-first order |
|
public |
Set values of this matrix from an array |
|
public |
Calculate this matrix's determinant (where applicable) |
|
public |
Calculate the matrix-matrix or matrix-vector product, depending on the type of the argument passed to the other-parameter. |
|
public |
Calculate the matrix matrix product between this matrix and the passed matrices. |
|
public |
Calculate the matrix vector product between this matrix and the passed arrays/vectors. |
|
public |
Get a matrix element value by row and column |
|
public |
Calculate the internal 1d array index |
|
public |
Invert this matrix (where applicable) |
|
public |
Remove a row and/or column from this matrix |
|
public |
Get the values from a specific row. |
|
public |
Returns a native javascript Array representation of this matrix, in column-first order |
|
public |
Scale this vector by a factor |
|
public |
Set a value at the specified row and column |
|
public |
Create a submatrix from this matrix. |
|
public |
Return a native javascript Array representation of this matrix. |
|
public |
Returns a 2d native javascript Array representation of this matrix. |
|
public |
Transpose this matrix (switch rows and columns) |
|
public |
Traverse this matrix |
Static Public Methods
public static fromArray(arr: number[], columns: number, rowsFirst: boolean, mutateArgs: boolean): Matrix source
Instantiate a matrix from an array.
public static fromVectors(vectors: ...number[]): Matrix source
Create a matrix from vectors. Each vector will be a column in the matrix and the number of rows are determined by the vector dimension.
Params:
Name | Type | Attribute | Description |
vectors | ...number[] |
public static identity(size: number): Matrix source
Creates an identity matrix with rows and columns equal to size.
Params:
Name | Type | Attribute | Description |
size | number | dimension |
Public Constructors
Public Members
public get isSquare: boolan: * source
This function returns true if this matrix has the same number of rows as columns, otherwise false.
Return:
boolan |
Private Members
Public Methods
public col(j: number, target: Vector | number[]): number[] source
Get the values from a specific column.
public columnsFirst(): number[] source
Returns a native javascript Array representation of this matrix, in rows-first order
public copyFrom(values: number[], rowsFirst: boolean, mutateArgs: number): * source
Set values of this matrix from an array
Return:
* |
public dot(other: number[] | Vector | Matrix, target: Vector | number[]): Matrix | Vector | number[] source
Calculate the matrix-matrix or matrix-vector product, depending on the type of the argument passed to the other-parameter.
public dotMat(matrices: ...Matrix): Matrix source
Calculate the matrix matrix product between this matrix and the passed matrices. in the order they appear.
The left hand matrix number of columns must always match the right hand matrix number of rows.
Params:
Name | Type | Attribute | Description |
matrices | ...Matrix |
public dotVec(vec: number[], target: Vector | number[]): number[] source
Calculate the matrix vector product between this matrix and the passed arrays/vectors.
Since it is common to use homogeneous coordinates when doing matrix-vector multiplication, i.e. use 4x4 matrix for transforming 3d vectors, the vectors will be treated as if they had the same number of components as the matrix has columns. For vectors with a lower dimension than the number of columns in the matrix, the last component will be iterpreted as 1 and any in between as 0. In the opposite case, it will simply neglect excessive components.
public inverse(target: Matrix): Matrix source
Invert this matrix (where applicable)
Params:
Name | Type | Attribute | Description |
target | Matrix | optional matrix to avoid mutating this matrix |
public remove(row: number, col: number, target: Matrix): Matrix source
Remove a row and/or column from this matrix
public row(i: number, target: Vector | number[]): number[] source
Get the values from a specific row.
public rowsFirst(): number[] source
Returns a native javascript Array representation of this matrix, in column-first order
public scale(factor: number, target: Matrix | number[]): Matrix source
Scale this vector by a factor
public set(row: number, col: number, value: number): Matrix source
Set a value at the specified row and column
public submatrix(row: number, col: number, rows: number, cols: number, target: Matrix | number[]): Matrix source
Create a submatrix from this matrix.
public toArray(rowsFirst: boolean): number[] source
Return a native javascript Array representation of this matrix.
Params:
Name | Type | Attribute | Description |
rowsFirst | boolean | if the output should be rows-first or columns-first |
public toArray2d(rowsFirst: boolean): Array<Array> source
Returns a 2d native javascript Array representation of this matrix.
Params:
Name | Type | Attribute | Description |
rowsFirst | boolean | if the output should be rows-first or columns-first |
public transpose(target: Matrix | number[]): Matrix source
Transpose this matrix (switch rows and columns)