API Docs for: 0.3.0
Show:

Math.Matrix2D Class

Module: Math

Matrix2D class, represent a matrix object for perform geometric calculus. The default matrix is the identity matrix.

Constructor

Math.Matrix2D

()

Example:

new Matrix2D() generate this matrix:

[1 0 0]
[0 1 0]
[0 0 1]

Methods

copyMatrix

() Matrix2D

create a copy of the matrix.

Returns:

Matrix2D: the new matrix

getData

() Array

Get a copy of the current state of the matrix by a 2d array of floats.

Note: if you want to modify the matrix, you can access directly to matrix.data

Returns:

Array: data return the internal data array of the matrix (In column-major order).

identity

() Matrix2D static

This method returns an identity matrix.

Returns:

Matrix2D: return an identity matrix object

identity

() chainable

Set the current matrix to identity.

inverse

() Matrix2D

Compute the inverse matrix of this.

Returns:

Matrix2D: inverse of this matrix if it exist; Otherwise null

isIdentity

() Boolean

Check if the current matrix match the identity.

Returns:

Boolean: true if the current matrix is set to the identity, otherwise it returns false.

multiply

(
  • matrix
)
chainable

Compute the product of two matrix

Parameters:

  • matrix Matrix2D

    the matrix to multiplies

multiplyVector

(
  • vector
)
Vector2D

Multiplies the current matrix by a vector 2d.

Parameters:

  • vector Vector2D

Returns:

Vector2D: a new vector transformed by the current matrix

rotate

(
  • angle
)
chainable

Apply a rotation to this matrix.

Parameters:

  • angle Number

    in degrees

rotation

(
  • angle
)
Matrix2D static

This method returns a rotation matrix Note that the angle is expressed in degree

Parameters:

  • angle Object

    a scalar expressed in degree who represent the angle of rotation of the matrix to generate.

Returns:

Matrix2D: return a rotation matrix object

scale

(
  • x
  • y
)
chainable

multiplies the current matrix by scale matrix

Parameters:

  • x Number

    multiplier of abscissa

  • y Number

    multiplier of ordinate

scale

(
  • x
  • y
)
Matrix2D static

This method return a scale matrix

Parameters:

  • x Object

    the abscissa scale factor to integrate in the matrix

  • y Object

    the ordinate scale factor to integrate in the matrix

Returns:

Matrix2D:

setTransform

(
  • a
  • b
  • c
  • d
  • e
  • f
)
chainable

Set the current matrix to the specified scalars (a, b, c, d, e, f). Note that the parameters are given in column major order.

Parameters:

  • a Object

    represent the top-left scalar in the matrix

  • b Object

    represent the middle-left scalar in the matrix

  • c Object

    represent the top-center scalar in the matrix

  • d Object

    represent the middle-middle scalar in the matrix

  • e Object

    represent the top-left scalar in the matrix

  • f Object

    represent the middle-right scalar in the matrix

skew

(
  • a
  • b
)
Matrix2D chainable

Transform the current matrix to apply a skew.

Parameters:

  • a Object

    the x skew factor

  • b Object

    the y skew factor

Returns:

Matrix2D: return the current matrix that have been transformed by the skew.

skew

(
  • a
  • b
)
Matrix2D static

This method return a skew matrix

Parameters:

  • a Object

    the factor of skew on the y axis

  • b Object

    the factor of skew on the x axis

Returns:

Matrix2D:

toString

() String

give a data representation of Matrix

Returns:

String: data representation of Matrix

transform

(
  • a
  • b
  • c
  • d
  • e
  • f
)
chainable

Transform the current matrix by the scalars a,b,c,d,e,f. If C if our current matrix and B the matrix made by a,b,c,d,e,f scalars. Then, the transform will be :

  C Matrix      B matrix
[Ca, Cc, Ce]   [a, c, e]
[Cb, Cd, Cf] X [b, d, f]
[0,  0,   1]   [0, 0, 1]

Parameters:

  • a Object
  • b Object
  • c Object
  • d Object
  • e Object
  • f Object

transformContext

(
  • context
)

This method transform the context given in parameter by the current matrix.

Parameters:

  • context CanvasRenderingContext2D

    it is the context to transform by the current matrix.

translate

(
  • x
  • y
)
chainable

Apply a translation to this matrix.

Parameters:

  • x Number

    translation in abscissa

  • y Number

    translation in ordinate

translation

(
  • x
  • y
)
Matrix2D static

This method return a translation matrix

Parameters:

  • x Object

    the x translation to integrate in the matrix

  • y Object

    the y translation to integrate in the matrix

Returns:

Matrix2D:

Properties

data

Array

Internal data that represent matrix.

Note that datas are given in column major order.

Example:

[[1, 0, 0],
 [0, 1, 0],
 [0, 0, 1]]