new Matrix(mopt, nopt)
General matrix type.
This Matrix type stores values in row-major order, so a Matrix must be
transposed before sending its values to an OpenGL shader.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
m |
number |
<optional> |
4 | The number of rows in the matrix. |
n |
number |
<optional> |
4 | The number of columns in the matrix. |
Extends
Methods
(static) copy(matrix, outopt) → {Matrix}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
matrix |
Matrix | The matrix that will be copied. | |
out |
Matrix |
<optional> |
The Matrix to copy into. If undefined, a new Matrix is created. |
Returns:
The out Matrix.
- Type
- Matrix
(static) det(matrix) → {number}
Parameters:
Name | Type | Description |
---|---|---|
matrix |
Matrix | The Matrix. |
Throws:
-
if matrix is not square.
- Type
- DimensionError
Returns:
The determinant of matrix.
- Type
- number
(static) invert(matrix, outopt) → {Matrix}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
matrix |
Matrix | The matrix to invert. | |
out |
Matrix |
<optional> |
The Matrix whose entries will be set to the inverse of matrix. If undefined, a new Matrix will be created. |
Throws:
-
-
if matrix is undefined.
- Type
- ReferenceError
-
-
-
if matrix is not square.
- Type
- DimensionError
-
-
-
if matrix is singular.
- Type
- RangeError
-
Returns:
The out Matrix.
- Type
- Matrix
(static) minor(matrix, di, dj, outopt) → {Matrix}
Finds a minor of a Matrix. The index arguments begin at 0, so to remove the
first row of matrix, pass 0 as the argument to di.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
matrix |
Matrix | The matrix. | |
di |
number | The index of the row to be removed from matrix. | |
dj |
number | The index of the column to be removed from matrix. | |
out |
Matrix |
<optional> |
The matrix whose Dimensions and entries will be set to the specified minor of matrix. If undefined, a new Matrix is created. |
Returns:
The out Matrix.
- Type
- Matrix
(static) mul(mat1, mat2, out) → {Matrix}
Parameters:
Name | Type | Description |
---|---|---|
mat1 |
Matrix | The left Matrix. |
mat2 |
matrix | Vector | The right Matrix. |
out |
Matrix | undefined | The result of the matrix multiplication. If undefined, a new Matrix is created. |
Throws:
-
-
if mat2 is not an instance of Matrix or Vector.
- Type
- TypeError
-
-
-
if mat1 and mat2 are not compatable for multiplication.
- Type
- DimensionError
-
Returns:
The out matrix.
- Type
- Matrix
asOrtographic(left, right, bottom, top, near, far) → {Matrix}
Parameters:
Name | Type | Description |
---|---|---|
left |
number | The x coordinate of the left frustum plane. |
right |
number | The x coordinate of the right frustum plane. |
bottom |
number | The y coordinate of the bottom frustum plane. |
top |
number | The y coordinate of the top frustum plane. |
near |
number | The z coordinate of the near frustum plane. |
far |
number | The z coordinate of the far frustum plane. |
Throws:
-
-
if this Matrix is not a 4x4 Matrix.
- Type
- DimensionError
-
-
-
if the arguments to right and left, top and bottom, or far and near are equal.
- Type
- RangeError
-
Returns:
This Matrix.
- Type
- Matrix
asPerspective(near, far, aspect, fov) → {Matrix}
Parameters:
Name | Type | Description |
---|---|---|
near |
number | The distance from the camera to the near clipping plane. |
far |
number | The distance from the camera to the far clipping plane. |
aspect |
number | The aspect ratio. |
fov |
number | The field of view angle. |
Throws:
-
-
if this Matrix is not a 4x4 Matrix.
- Type
- DimensionError
-
-
-
if the arguments to near and far are equal or if the argument to aspect is 0.
- Type
- RangeError
-
Returns:
This Matrix.
- Type
- Matrix
asRotation(angle) → {Matrix}
If this Matrix is a 2x2 Matrix, sets this Matrix as a non-homogeneous
rotation Matrix. Else if this Matrix is a 3x3 Matrix, sets this Matrix as a
homogeneous rotation Matrix.
Parameters:
Name | Type | Description |
---|---|---|
angle |
number | The angle of rotation. |
Throws:
-
if this Matrix not square or if it is not a 2x2 or 3x3 Matrix.
- Type
- DimensionError
Returns:
This Matrix.
- Type
- Matrix
asRotation^2(axis, angle) → {Matrix}
If this Matrix is a 3x3 Matrix, sets this Matrix as a non-homogeneous
rotation Matrix. Else if this Matrix is a 4x4 Matrix, sets this Matrix as a
homogeneous rotation Matrix.
Parameters:
Name | Type | Description |
---|---|---|
axis |
Array | The axis of rotation. |
angle |
number | The angle of rotation. |
Throws:
-
if this Matrix is not square or if it is not a 3x3 or 4x4 Matrix.
- Type
- DimensionError
Returns:
This Matrix.
- Type
- Matrix
asScale(array) → {Matrix}
Sets the scale values for each dimension or this matrix to the values of
array.
Parameters:
Name | Type | Description |
---|---|---|
array |
Array | An array containing the x, y, [...] scale values. |
Throws:
-
if the array argument's length is not one less than the number of columns in this Matrix.
- Type
- RangeError
Returns:
This Matrix.
- Type
- Matrix
asScale^2(number) → {Matrix}
Sets the scale values for each dimension of this matrix to the value of the
number argument.
Parameters:
Name | Type | Description |
---|---|---|
number |
number | The number to set as the scale value for each dimension of this Matrix. |
Returns:
This Matrix.
- Type
- Matrix
asTranslation(array) → {Matrix}
Parameters:
Name | Type | Description |
---|---|---|
array |
Array | An array containing the x, y, [...] translation coordinates. |
Throws:
-
if this Matrix is not square, if this Matrix is a 2x2 Matrix, or if the array argument's length is not one less than the number of columns in this Matrix.
- Type
- DimensionError
Returns:
This Matrix.
- Type
- Matrix
asView(position) → {Matrix}
Sets this matrix as a view Matrix.
Parameters:
Name | Type | Description |
---|---|---|
position |
Array | An array containing the starting x, y, and z coordinates of this view Matrix. |
Throws:
-
-
if this Matrix is not a 4x4 Matrix.
- Type
- DimensionError
-
-
-
if position is not and instance of Array.
- Type
- TypeError
-
Returns:
This Matrix.
- Type
- Matrix
det() → {number}
Returns:
The determinant of this Matrix.
- Type
- number
equals(array) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
array |
Array | The array to compare this Dimensional to. |
- Inherited From:
- Source:
Returns:
True if all entries are equal, false otherwise.
- Type
- boolean
identity() → {Matrix}
Sets this Matrix to the identity matrix or its analogue of this Matrix os
not square. (i.e., acts like the Kronecker delta over the indicies)
Returns:
This Matrix.
- Type
- Matrix
invert() → {Matrix}
Inverts this Matrix.
Returns:
This Matrix.
- Type
- Matrix
mul(matrix) → {Matrix}
Multiplies this Matrix by matrix.
Parameters:
Name | Type | Description |
---|---|---|
matrix |
Matrix | The right-side multiplicand. |
Throws:
-
-
if matrix is undefined.
- Type
- ReferenceError
-
-
-
if matrix is not an instance of Matrix.
- Type
- TypeError
-
-
-
if this Matrix and matrix are not compatable for multiplication.
- Type
- DimensionError
-
Returns:
- This Matrix.
- Type
- Matrix
rotate(axis, angle) → {Matrix}
Rotates this Matrix around axis by angle.
Parameters:
Name | Type | Description |
---|---|---|
axis |
Array | The axis of rotation. |
angle |
number | The angle of rotation. |
Throws:
-
if this Matrix is not square or if it is not a 3x3 or 4x4 Matrix.
- Type
- DimensionError
Returns:
This Matrix.
- Type
- Matrix
rotate(angle) → {Matrix}
Rotates this Matrix by angle.
Parameters:
Name | Type | Description |
---|---|---|
angle |
number | The angle of rotation. |
Throws:
-
if this Matrix not square or if it is not a 2x2 or 3x3 Matrix.
- Type
- DimensionError
Returns:
This Matrix.
- Type
- Matrix
scale(array) → {Matrix}
Scales this Matrix by the values of array.
Parameters:
Name | Type | Description |
---|---|---|
array |
Array | An array containing the x, y, [...] scale values. |
Throws:
-
if the array argument's length is not one less than the number of columns in this Matrix.
- Type
- RangeError
Returns:
This Matrix.
- Type
- Matrix
scale^2(number) → {Matrix}
Scales each dimension of this matrix by the value of the number argument.
Parameters:
Name | Type | Description |
---|---|---|
number |
number | The number to set as the scale value for each dimension of this Matrix. |
Returns:
This Matrix.
- Type
- Matrix
set(array, offsetopt) → {Matrix}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
array |
Array | The array whose values will be set in this Matrix. | |
offset |
number |
<optional> |
The offset to begin filling. If undefined, offset will be set to 0. |
Throws:
-
if array.length + offset > the number of entries in this Matrix.
- Type
- RangeError
Returns:
This Matrix.
- Type
- Matrix
setEntry(m, n, val) → {Matrix}
Sets the ij entry of this Matrix. The index arguments begin at 1, so to set
the entry in the second row and third column, pass 2 and 3 as the arguments
to i and j, respectively.
Parameters:
Name | Type | Description |
---|---|---|
m |
number | The row index. |
n |
number | The column index. |
val |
number | The value. |
Returns:
This Matrix.
- Type
- Matrix
toString() → {string}
Returns:
A string representation of this Matrix.
- Type
- string
translate(vector) → {Matrix}
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector | A vector whose entries represent the x, y, [...] translation values. |
Throws:
-
if this Matrix is not square, if this Matrix is a 2x2 Matrix, or if the array argument's length is not one less than the number of columns in this Matrix.
- Type
- DimensionError
Returns:
This Matrix.
- Type
- Matrix
transpose() → {Matrix}
Transposes this Matrix.
Returns:
This Matrix.
- Type
- Matrix
zero() → {Matrix}
Sets every entry of this Matrix to 0.
Returns:
This Matrix.
- Type
- Matrix