Skip to content

Commit

Permalink
Matrix Math API documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Lindberg committed May 5, 2016
1 parent 597aa38 commit c77140a
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 4 deletions.
4 changes: 2 additions & 2 deletions MatrixMath/1.0/matrixMath.js
Expand Up @@ -26,8 +26,8 @@ var MatrixMath = (function() {

/**
* Gets the adjugate of a matrix, the tranpose of its cofactor matrix.
* @param {[type]} mat
* @return {[type]}
* @param {Matrix} mat
* @return {Matrix}
*/
function adjoint(mat) {
var cofactorMat = MatrixMath.cofactorMatrix(mat);
Expand Down
194 changes: 193 additions & 1 deletion MatrixMath/README.md
Expand Up @@ -9,10 +9,202 @@ All of this scripts operations are exposed through the ```MatrixMath``` object.

## Other scripts

MatrixMath has no dependencies, but it does play nice with the ```VectorMath```
MatrixMath has no dependencies, but it does play nice with the ```Vector Math```
script's library, particularly for ```MatrixMath.multiply()``` when used to
transform a vector.

## Unit tests
Unit tests are implemented for all its operations, and they run automatically
when the script is loaded.

## API Documentation

This script's documentation makes use of the follow typedefs:

```
/**
* An NxN square matrix, represented as a 2D array of numbers in column-major
* order. For example, mat[3][2] would get the value in column 3 and row 2.
* order.
* @typedef {number[][]} Matrix
*/
```

```
/**
* An N-degree vector.
* @typedef {number[]} Vector
*/
```

The following functions are exposed by the ```MatrixMath``` object:

```
/**
* Gets the adjugate of a matrix, the tranpose of its cofactor matrix.
* @param {Matrix} mat
* @return {Matrix}
*/
function adjoint(mat)
```

```
/**
* Produces a clone of an NxN square matrix.
* @param {Matrix} mat
* @return {Matrix}
*/
function clone(mat)
```

```
/**
* Gets the cofactor of a matrix at a specified column and row.
* @param {Matrix} mat
* @param {uint} col
* @param {uint} row
* @return {number}
*/
function cofactor(mat, col, row)
```

```
/**
* Gets the cofactor matrix of a matrix.
* @param {Matrix} mat
* @return {Matrix}
*/
function cofactorMatrix(mat)
```

```
/**
* Gets the determinant of an NxN matrix.
* @param {Matrix} mat
* @return {number}
*/
function determinant(mat)
```

```
/**
* Tests if two matrices are equal.
* @param {Matrix} a
* @param {Matrix} b
* @param {number} [tolerance=0]
* If specified, this specifies the amount of tolerance to use for
* each value of the matrices when testing for equality.
* @return {boolean}
*/
function equal(a, b, tolerance)
```

```
/**
* Produces an identity matrix of some size.
* @param {uint} size
* @return {Matrix}
*/
function identity(size)
```

```
/**
* Gets the inverse of a matrix.
* @param {Matrix} mat
* @return {Matrix}
*/
function inverse(mat)
```

```
/**
* Gets the determinant of a matrix omitting some column and row.
* @param {Matrix} mat
* @param {uint} col
* @param {uint} row
* @return {number}
*/
function minor(mat, col, row)
```

```
/**
* Returns the matrix multiplication of a*b.
* This function works for non-square matrices (and also for transforming
* vectors by a matrix).
* For matrix multiplication to work, the # of columns in A must be equal
* to the # of rows in B.
* The resulting matrix will have the same number of rows as A and the
* same number of columns as B.
* If b was given as a vector, then the result will also be a vector.
* @param {Matrix} a
* @param {Matrix|Vector} b
* @return {Matrix|Vector}
*/
function multiply(a, b)
```

```
/**
* Returns a matrix with a column and row omitted.
* @param {Matrix} mat
* @param {uint} col
* @param {uint} row
* @return {Matrix}
*/
function omit(mat, col, row)
```

```
/**
* Produces a 2D rotation affine transformation. The direction of the
* rotation depends upon the coordinate system.
* @param {number} angle
* The angle, in radians.
* @return {Matrix}
*/
function rotate(angle)
```

```
/**
* Produces a 2D scale affine transformation matrix.
* The matrix is used to transform homogenous coordinates, so it is
* actually size 3 instead of size 2, despite being used for 2D geometry.
* @param {(number|Vector)} amount
* If specified as a number, then it is a uniform scale. Otherwise,
* it defines a scale by parts.
* @return {Matrix}
*/
function scale(amount)
```

```
/**
* Gets the size N of a NxN square matrix.
* @param {Matrix} mat
* @return {uint}
*/
function size(mat)
```

```
/**
* Produces a 2D translation affine transformation matrix.
* The matrix is used to transform homogenous coordinates, so it is
* actually size 3 instead of size 2, despite being used for 2D geometry.
* @param {Vector} vec
* @return {Matrix}
*/
function translate(vec)
```

```
/**
* Returns the transpose of a matrix.
* @param {Matrix} mat
* @return {Matrix}
*/
function transpose(mat)
```
2 changes: 1 addition & 1 deletion MatrixMath/script.json
Expand Up @@ -3,7 +3,7 @@
"script": "matrixMath.js",
"version": "1.0",
"previousversions": [],
"description": "# Matrix Math\r\rThis script provides a library of matrix mathematical operations for linear algebra and 2D affine transformations. It has no behavior on its own and is meant to be used by other scripts to do neat things, particularly for transforming geometric systems.\r\rAll of this scripts operations are exposed through the ```MatrixMath``` object.\r\r## Other scripts\r\rMatrixMath has no dependencies, but it does play nice with the ```VectorMath``` script's library, particularly for ```MatrixMath.multiply()``` when used to transform a vector.\r\r## Unit tests\rUnit tests are implemented for all its operations, and they run automatically when the script is loaded.\r",
"description": "# Matrix Math\r\rThis script provides a library of matrix mathematical operations for\rlinear algebra and 2D affine transformations. It has no behavior on its own\rand is meant to be used by other scripts to do neat things, particularly\rfor transforming geometric systems.\r\rAll of this scripts operations are exposed through the ```MatrixMath``` object.\r\r## Other scripts\r\rMatrixMath has no dependencies, but it does play nice with the ```Vector Math```\rscript's library, particularly for ```MatrixMath.multiply()``` when used to\rtransform a vector.\r\r## Unit tests\rUnit tests are implemented for all its operations, and they run automatically\rwhen the script is loaded.\r\r## API Documentation\r\rThis script's documentation makes use of the follow typedefs:\r\r```\r/**\r * An NxN square matrix, represented as a 2D array of numbers in column-major\r * order. For example, mat[3][2] would get the value in column 3 and row 2.\r * order.\r * @typedef {number[][]} Matrix\r */\r```\r\r```\r/**\r * An N-degree vector.\r * @typedef {number[]} Vector\r */\r```\r\rThe following functions are exposed by the ```MatrixMath``` object:\r\r```\r/**\r * Gets the adjugate of a matrix, the tranpose of its cofactor matrix.\r * @param {Matrix} mat\r * @return {Matrix}\r */\rfunction adjoint(mat)\r```\r\r```\r/**\r * Produces a clone of an NxN square matrix.\r * @param {Matrix} mat\r * @return {Matrix}\r */\rfunction clone(mat)\r```\r\r```\r/**\r * Gets the cofactor of a matrix at a specified column and row.\r * @param {Matrix} mat\r * @param {uint} col\r * @param {uint} row\r * @return {number}\r */\rfunction cofactor(mat, col, row)\r```\r\r```\r/**\r * Gets the cofactor matrix of a matrix.\r * @param {Matrix} mat\r * @return {Matrix}\r */\rfunction cofactorMatrix(mat)\r```\r\r```\r/**\r * Gets the determinant of an NxN matrix.\r * @param {Matrix} mat\r * @return {number}\r */\rfunction determinant(mat)\r```\r\r```\r/**\r * Tests if two matrices are equal.\r * @param {Matrix} a\r * @param {Matrix} b\r * @param {number} [tolerance=0]\r * If specified, this specifies the amount of tolerance to use for\r * each value of the matrices when testing for equality.\r * @return {boolean}\r */\rfunction equal(a, b, tolerance)\r```\r\r```\r/**\r * Produces an identity matrix of some size.\r * @param {uint} size\r * @return {Matrix}\r */\rfunction identity(size)\r```\r\r```\r/**\r * Gets the inverse of a matrix.\r * @param {Matrix} mat\r * @return {Matrix}\r */\rfunction inverse(mat)\r```\r\r```\r/**\r * Gets the determinant of a matrix omitting some column and row.\r * @param {Matrix} mat\r * @param {uint} col\r * @param {uint} row\r * @return {number}\r */\rfunction minor(mat, col, row)\r```\r\r```\r/**\r * Returns the matrix multiplication of a*b.\r * This function works for non-square matrices (and also for transforming\r * vectors by a matrix).\r * For matrix multiplication to work, the # of columns in A must be equal\r * to the # of rows in B.\r * The resulting matrix will have the same number of rows as A and the\r * same number of columns as B.\r * If b was given as a vector, then the result will also be a vector.\r * @param {Matrix} a\r * @param {Matrix|Vector} b\r * @return {Matrix|Vector}\r */\rfunction multiply(a, b)\r```\r\r```\r/**\r * Returns a matrix with a column and row omitted.\r * @param {Matrix} mat\r * @param {uint} col\r * @param {uint} row\r * @return {Matrix}\r */\rfunction omit(mat, col, row)\r```\r\r```\r/**\r * Produces a 2D rotation affine transformation. The direction of the\r * rotation depends upon the coordinate system.\r * @param {number} angle\r * The angle, in radians.\r * @return {Matrix}\r */\rfunction rotate(angle)\r```\r\r```\r/**\r * Produces a 2D scale affine transformation matrix.\r * The matrix is used to transform homogenous coordinates, so it is\r * actually size 3 instead of size 2, despite being used for 2D geometry.\r * @param {(number|Vector)} amount\r * If specified as a number, then it is a uniform scale. Otherwise,\r * it defines a scale by parts.\r * @return {Matrix}\r */\rfunction scale(amount)\r```\r\r```\r/**\r * Gets the size N of a NxN square matrix.\r * @param {Matrix} mat\r * @return {uint}\r */\rfunction size(mat)\r```\r\r```\r/**\r * Produces a 2D translation affine transformation matrix.\r * The matrix is used to transform homogenous coordinates, so it is\r * actually size 3 instead of size 2, despite being used for 2D geometry.\r * @param {Vector} vec\r * @return {Matrix}\r */\rfunction translate(vec)\r```\r\r```\r/**\r * Returns the transpose of a matrix.\r * @param {Matrix} mat\r * @return {Matrix}\r */\rfunction transpose(mat)\r```\r",
"authors": "Stephen Lindberg",
"roll20userid": 46544,
"useroptions": [],
Expand Down

0 comments on commit c77140a

Please sign in to comment.