API Docs for: 1.0.1
Show:

Kiwi.Geom.Matrix Class

Defined in: src\geom\Matrix.ts:9
Module: Geom
Parent Module: Kiwi

Represents a 2d transformation matrix. This can be used to map points between different coordinate spaces. Matrices are used by Transform objects to represent translation, scale and rotation transformations, and to determine where objects are in world space or camera space. Objects such as entities and groups may be nested, and their associated transforms may represent how they are scaled, translated and rotated relative to a parent transform. By concatenating an object's transformation matrix with it's ancestors matrices, it is possible to determine the absolute position of the object in world space. See http://en.wikipedia.org/wiki/Transformation_matrix#Examples_in_2D_graphics for an in depth discussion of 2d tranformation matrices.

Constructor

Kiwi.Geom.Matrix

(
  • [a
  • [b
  • [c
  • [d
  • [tx
  • [ty
)

Parameters:

  • [a Number

    = 1] position 0,0 of the matrix, affects scaling and rotation.

  • [b Number

    = 0] position 0,1 of the matrix, affects scaling and rotation.

  • [c Number

    = 0] position 1,0 of the matrix, affects scaling and rotation.

  • [d Number

    = 1] position 1,1 of the matrix, affects scaling and rotation.

  • [tx Number

    = 0] position 2,0 of the matrix, affects translation on x axis.

  • [ty Number

    = 0] position 2,1 of the matrix, affects translation on y axis.

Returns:

(Object) This object.

Methods

append

(
  • [a
  • [b
  • [c
  • [d
  • [tx
  • [ty
)
Object

Append values to this matrix, paramters supplied individually.

Parameters:

  • [a Number

    = 1] position 0,0 of the matrix, affects scaling and rotation.

  • [b Number

    = 0] position 0,1 of the matrix, affects scaling and rotation.

  • [c Number

    = 0] position 1,0 of the matrix, affects scaling and rotation.

  • [d Number

    = 1] position 1,1 of the matrix, affects scaling and rotation.

  • [tx Number

    = 0] position 2,0 of the matrix, affects translation on x axis.

  • [ty Number

    = 0] position 2,1 of the matrix, affects translation on y axis.

Returns:

Object:

This object.

appendMatrix

(
  • m
)
Object

Append a matrix to this matrix.

Parameters:

  • m Object

    The matrix to append.

Returns:

Object:

This object.

clone

() Object

Clone this matrix

Returns:

Object:

The new clone of this matrix.

copyFrom

(
  • m
)
Object

Copy another matrix to this matrix.

Parameters:

  • m Object

    The matrixto be copied from.

Returns:

Object:

This object.

copyTo

(
  • m
)
Object

Copy this matrix to another matrix.

Parameters:

  • m Object

    The matrix to copy to.

Returns:

Object:

This object.

identity

() Object

Set the matrix to the identity matrix - when appending or prepending this matrix to another there will be no change in the resulting matrix

Returns:

Object:

This object.

prepend

(
  • [a
  • [b
  • [c
  • [d
  • [tx
  • [ty
)
Object

Prepend values to this matrix, paramters supplied individually.

Parameters:

  • [a Number

    = 1] position 0,0 of the matrix, affects scaling and rotation.

  • [b Number

    = 0] position 0,1 of the matrix, affects scaling and rotation.

  • [c Number

    = 0] position 1,0 of the matrix, affects scaling and rotation.

  • [d Number

    = 0] position 1,1 of the matrix, affects scaling and rotation.

  • [tx Number

    = 0] position 2,0 of the matrix, affects translation on x axis.

  • [ty Number

    = 0] position 2,1 of the matrix, affects translation on y axis.

Returns:

Object:

This object.

prependMatrix

(
  • m.
)
Object

Prepend a matrix to this matrix.

Parameters:

  • m. Object

    The matrix to prepend.

Returns:

Object:

This object.

rotate

(
  • radians
)
Object

Rotate the matrix by "radians" degrees

Parameters:

  • radians Number

    radians.

Returns:

Object:

This object.

scale

(
  • scaleX.
  • scaleY.
)
Object

Scale the matrix

Parameters:

  • scaleX. Number

    The amount to scale on the x axis.

  • scaleY. Number

    The amount to scale on the y axis.

Returns:

Object:

This object.

setFromOffsetTransform

(
  • tx
  • ty
  • scaleX
  • scaleY
  • rotation
  • rotPointX
  • rotPointY
)
Object

Set matrix values from transform values, with rotation point data included

Parameters:

  • tx Number

    tx. Translation on x axis.

  • ty Number

    ty. Translation on y axis.

  • scaleX Number

    scaleX. Scale on x axis.

  • scaleY Number

    scaleY. Scale on y axis.

  • rotation Number

    rotation.

  • rotPointX Number

    Rotation point offset on x axis.

  • rotPointY Number

    Rotation point offset on y axis.

Returns:

Object:

This object.

setFromTransform

(
  • tx
  • ty
  • scaleX
  • scaleY
  • rotation
)
Object

Set matrix values from transform values

Parameters:

  • tx Number

    tx. Translation on x axis.

  • ty Number

    ty. Translation on y axis.

  • scaleX Number

    scaleX. Scale on x axis.

  • scaleY Number

    scaleY. Scale on y axis.

  • rotation Number

    rotation.

Returns:

Object:

This object.

setPosition

(
  • x
  • y
)
Object

Set the tx and ty elements of the matrix

Parameters:

  • x Number

    Translation on x axis.

  • y Number

    Translation on y axis.

Returns:

Object:

This object.

setPositionVector

() Object

Get the x and y position of the matrix as an object with x and y properties

Returns:

Object:

An object constructed from a literal with x and y properties.

setPositionVector

(
  • p
)
Object

Set the tx and ty elements of the matrix from an object with x and y properties.

Parameters:

  • p Number

    The object from which to copy the x and y properties from.

Returns:

Object:

This object.

setTo

(
  • [a
  • [b
  • [c
  • [d
  • [tx
  • [ty
)

Set all matrix values

Parameters:

  • [a Number

    = 1] position 0,0 of the matrix, affects scaling and rotation.

  • [b Number

    = 0] position 0,1 of the matrix, affects scaling and rotation.

  • [c Number

    = 0] position 1,0 of the matrix, affects scaling and rotation.

  • [d Number

    = 1] position 1,1 of the matrix, affects scaling and rotation.

  • [tx Number

    = 0] position 2,0 of the matrix, affects translation on x axis.

  • [ty Number

    = 0] position 2,1 of the matrix, affects translation on y axis.

Returns:

(Object) This object.

toString

() String

Returns a string representation of this object.

Returns:

String:

a string representation of the instance.

transalte

(
  • tx
  • ty
)
Object

Translate the matrix

Parameters:

  • tx Number

    tx. The amount to translate on the x axis.

  • ty Number

    ty. The amount to translate on the y axis.

Returns:

Object:

This object.

transformPoint

() Object

Invert this matrix so that it represents the opposite of it's orginal tranformaation.

Returns:

Object:

This object.

transformPoint

(
  • pt
)
Object

Apply this matrix to a an object with x and y properties representing a point and return the transformed point.

Parameters:

  • pt Object

    The point to be translated.

Returns:

Object:

The translated point.