API Docs for: 1.4.0
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 its 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=1]
  • [b=0]
  • [c=0]
  • [d=1]
  • [tx=0]
  • [ty=0]
)

Parameters:

  • [a=1] Number optional

    position 0,0 of the matrix, affects scaling and rotation.

  • [b=0] Number optional

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

  • [c=0] Number optional

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

  • [d=1] Number optional

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

  • [tx=0] Number optional

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

  • [ty=0] Number optional

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

Returns:

(Object) This object.

Methods

append

(
  • [a=1]
  • [b=0]
  • [c=0]
  • [d=1]
  • [tx=0]
  • [ty=0]
)
Kiwi.Geom.Matrix public

Append values to this matrix, parameters supplied individually.

Parameters:

  • [a=1] Number optional

    position 0,0 of the matrix, affects scaling and rotation.

  • [b=0] Number optional

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

  • [c=0] Number optional

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

  • [d=1] Number optional

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

  • [tx=0] Number optional

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

  • [ty=0] Number optional

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

Returns:

Kiwi.Geom.Matrix:

This object.

appendMatrix

(
  • m
)
Kiwi.Geom.Matrix public

Append a matrix to this matrix.

Parameters:

Returns:

Kiwi.Geom.Matrix:

This object.

clone

() Kiwi.Geom.Matrix public

Clone this matrix and returns a new Matrix object.

Returns:

copyFrom

(
  • m
)
Kiwi.Geom.Matrix public

Copy another matrix to this matrix.

Parameters:

Returns:

Kiwi.Geom.Matrix:

This object.

copyTo

(
  • m
)
Kiwi.Geom.Matrix public

Copy this matrix to another matrix.

Parameters:

Returns:

Kiwi.Geom.Matrix:

This object.

equals

(
  • matrix
)
public

Check whether this matrix equals another matrix.

Parameters:

Returns:

boolean

getPosition

() Kiwi.Geom.Point public

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

Returns:

Kiwi.Geom.Point:

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

identity

() Kiwi.Geom.Matrix public

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:

Kiwi.Geom.Matrix:

This object.

invert

() Kiwi.Geom.Matrix public

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

Returns:

Kiwi.Geom.Matrix:

This object.

objType

() String public

The type of object this is.

Returns:

String:

"Matrix"

prepend

(
  • [a=1]
  • [b=0]
  • [c=0]
  • [d=0]
  • [tx=0]
  • [ty=0]
)
Kiwi.Geom.Matrix public

Prepend values to this matrix, paramters supplied individually.

Parameters:

  • [a=1] Number optional

    position 0,0 of the matrix, affects scaling and rotation.

  • [b=0] Number optional

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

  • [c=0] Number optional

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

  • [d=0] Number optional

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

  • [tx=0] Number optional

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

  • [ty=0] Number optional

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

Returns:

Kiwi.Geom.Matrix:

This object.

prependMatrix

(
  • m
)
Kiwi.Geom.Matrix public

Prepend a matrix to this matrix.

Parameters:

Returns:

Kiwi.Geom.Matrix:

This object.

rotate

(
  • radians
)
Kiwi.Geom.Matrix public

Rotate the matrix by "radians" degrees

Parameters:

  • radians Number

    The angle (in radians) to rotate this matrix by.

Returns:

Kiwi.Geom.Matrix:

This object.

scale

(
  • scaleX
  • scaleY
)
Kiwi.Geom.Matrix public

Scales the matrix by the amount passed.

Parameters:

  • scaleX Number

    The amount to scale on the x axis.

  • scaleY Number

    The amount to scale on the y axis.

Returns:

Kiwi.Geom.Matrix:

This object.

setFromOffsetTransform

(
  • tx
  • ty
  • scaleX
  • scaleY
  • rotation
  • rotPointX
  • rotPointY
)
Kiwi.Geom.Matrix public

Defined in src\geom\Matrix.ts:159

Available since 1.0.1

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:

Kiwi.Geom.Matrix:

This object.

setFromTransform

(
  • tx
  • ty
  • scaleX
  • scaleY
  • rotation
)
Kiwi.Geom.Matrix public

Set matrix values from transform values

Parameters:

  • tx Number

    Translation on x axis.

  • ty Number

    Translation on y axis.

  • scaleX Number

    scaleX. Scale on x axis.

  • scaleY Number

    scaleY. Scale on y axis.

  • rotation Number

    rotation.

Returns:

Kiwi.Geom.Matrix:

This object.

setPosition

(
  • x
  • y
)
Kiwi.Geom.Matrix public

Set the tx and ty elements of the matrix.

Parameters:

  • x Number

    Translation on x axis.

  • y Number

    Translation on y axis.

Returns:

Kiwi.Geom.Matrix:

This object.

setPositionPoint

(
  • p
)
Kiwi.Geom.Matrix public

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:

Kiwi.Geom.Matrix:

This object.

setTo

(
  • [a=1]
  • [b=0]
  • [c=0]
  • [d=1]
  • [tx=0]
  • [ty=0]
)
Kiwi.Geom.Matrix public

Set all matrix values

Parameters:

  • [a=1] Number optional

    position 0,0 of the matrix, affects scaling and rotation.

  • [b=0] Number optional

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

  • [c=0] Number optional

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

  • [d=1] Number optional

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

  • [tx=0] Number optional

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

  • [ty=0] Number optional

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

Returns:

Kiwi.Geom.Matrix:

This object.

toString

() String public

Returns a string representation of this object.

Returns:

String:

A string representation of the instance.

transformPoint

(
  • pt
)
Kiwi.Geom.Matrix public

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:

Kiwi.Geom.Matrix:

This object.

translate

(
  • tx
  • ty
)
Kiwi.Geom.Matrix public

Translate the matrix by the amount passed.

Parameters:

  • tx Number

    The amount to translate on the x axis.

  • ty Number

    The amount to translate on the y axis.

Returns:

Kiwi.Geom.Matrix:

This object.

Properties

a

Number public

Position 0,0 of the matrix, affects scaling and rotation

Default: 1

b

Number public

Position 0,1 of the matrix, affects scaling and rotation.

Default: 0

c

Number public

Position 1,0 of the matrix, affects scaling and rotation.

Default: 0

d

Number public

Position 1,1 of the matrix, affects scaling and rotation.

Default: 1

tx

Number public

Position 2,0 of the matrix, affects translation on x axis.

Default: 0

ty

Number public

Position 2,1 of the matrix, affects translation on y axis.

Default: 0