#

API Documentation for: NEXT
Show: Inherited Protected Private Deprecated

# Matrix2D Class

Defined in: `Matrix2D:41`
Module: EaselJS

Represents an affine transformation matrix, and provides tools for constructing and concatenating matrices.

This matrix can be visualized as:

    [ a  c  tx
      b  d  ty
      0  0  1  ]

Note the locations of b and c.

## Constructor

### `Matrix2D`

(

- `[a=1]`
- `[b=0]`
- `[c=0]`
- `[d=1]`
- `[tx=0]`
- `[ty=0]`

)

Defined in `Matrix2D:41`

#### Parameters:

- `[a=1]` Number optional

  Specifies the a property for the new matrix.

- `[b=0]` Number optional

  Specifies the b property for the new matrix.

- `[c=0]` Number optional

  Specifies the c property for the new matrix.

- `[d=1]` Number optional

  Specifies the d property for the new matrix.

- `[tx=0]` Number optional

  Specifies the tx property for the new matrix.

- `[ty=0]` Number optional

  Specifies the ty property for the new matrix.

- Index
- Methods
- Properties

## Item Index

### Methods

- append
- appendMatrix
- appendTransform
- clone
- copy
- decompose
- equals
- identity
- invert
- isIdentity
- prepend
- prependMatrix
- prependTransform
- rotate
- scale
- setValues
- skew
- toString
- transformPoint
- translate

### Properties

- a
- b
- c
- d
- DEG_TO_RAD static
- identity static
- tx
- ty

## Methods

### `append`

(

- `a`
- `b`
- `c`
- `d`
- `tx`
- `ty`

)
Matrix2D

Defined in `append:150`

Appends the specified matrix properties to this matrix. All parameters are required. This is the equivalent of multiplying `(this matrix) * (specified matrix)`.

#### Parameters:

- `a` Number
- `b` Number
- `c` Number
- `d` Number
- `tx` Number
- `ty` Number

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `appendMatrix`

(

- `matrix`

)
Matrix2D

Defined in `appendMatrix:205`

Appends the specified matrix to this matrix. This is the equivalent of multiplying `(this matrix) * (specified matrix)`.

#### Parameters:

- `matrix` Matrix2D

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `appendTransform`

(

- `x`
- `y`
- `scaleX`
- `scaleY`
- `rotation`
- `skewX`
- `skewY`
- `regX`
- `regY`

)
Matrix2D

Defined in `appendTransform:235`

Generates matrix properties from the specified display object transform properties, and appends them to this matrix. For example, you can use this to generate a matrix representing the transformations of a display object:

    var mtx = new createjs.Matrix2D();
    mtx.appendTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation);

#### Parameters:

- `x` Number
- `y` Number
- `scaleX` Number
- `scaleY` Number
- `rotation` Number
- `skewX` Number
- `skewY` Number
- `regX` Number

  Optional.

- `regY` Number

  Optional.

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `clone`

() Matrix2D

Defined in `clone:507`

Returns a clone of the Matrix2D instance.

#### Returns:

Matrix2D:

a clone of the Matrix2D instance.

### `copy`

(

- `matrix`

)
Matrix2D

Defined in `copy:497`

Copies all properties from the specified matrix to this matrix.

#### Parameters:

- `matrix` Matrix2D

  The matrix to copy properties from.

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `decompose`

(

- `target`

)
Object

Defined in `decompose:464`

Decomposes the matrix into transform properties (x, y, scaleX, scaleY, and rotation). Note that these values may not match the transform properties you used to generate the matrix, though they will produce the same visual results.

#### Parameters:

- `target` Object

  The object to apply the transform properties to. If null, then a new object will be returned.

#### Returns:

Object:

The target, or a new generic object with the transform properties applied.

### `equals`

(

- `matrix`

)
Boolean

Defined in `equals:439`

Returns true if this matrix is equal to the specified matrix (all property values are equal).

#### Parameters:

- `matrix` Matrix2D

  The matrix to compare.

#### Returns:

Boolean:

### `identity`

() Matrix2D

Defined in `identity:397`

Sets the properties of the matrix to those of an identity matrix (one that applies a null transformation).

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `invert`

() Matrix2D

Defined in `invert:408`

Inverts the matrix, causing it to perform the opposite transformation.

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `isIdentity`

() Boolean

Defined in `isIdentity:430`

Returns true if the matrix is an identity matrix.

#### Returns:

Boolean:

### `prepend`

(

- `a`
- `b`
- `c`
- `d`
- `tx`
- `ty`

)
Matrix2D

Defined in `prepend:178`

Prepends the specified matrix properties to this matrix. This is the equivalent of multiplying `(specified matrix) * (this matrix)`. All parameters are required.

#### Parameters:

- `a` Number
- `b` Number
- `c` Number
- `d` Number
- `tx` Number
- `ty` Number

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `prependMatrix`

(

- `matrix`

)
Matrix2D

Defined in `prependMatrix:216`

Prepends the specified matrix to this matrix. This is the equivalent of multiplying `(specified matrix) * (this matrix)`. For example, you could calculate the combined transformation for a child object using:

    var o = myDisplayObject;
    var mtx = o.getMatrix();
    while (o = o.parent) {
        // prepend each parent's transformation in turn:
        o.prependMatrix(o.getMatrix());
    }

#### Parameters:

- `matrix` Matrix2D

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `prependTransform`

(

- `x`
- `y`
- `scaleX`
- `scaleY`
- `rotation`
- `skewX`
- `skewY`
- `regX`
- `regY`

)
Matrix2D

Defined in `prependTransform:281`

Generates matrix properties from the specified display object transform properties, and prepends them to this matrix. For example, you could calculate the combined transformation for a child object using:

    var o = myDisplayObject;
    var mtx = new createjs.Matrix2D();
    do  {
        // prepend each parent's transformation in turn:
        mtx.prependTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation, o.skewX, o.skewY, o.regX, o.regY);
    } while (o = o.parent);

    Note that the above example would not account for transformMatrix
    values. See prependMatrix for an example that does.

#### Parameters:

- `x` Number
- `y` Number
- `scaleX` Number
- `scaleY` Number
- `rotation` Number
- `skewX` Number
- `skewY` Number
- `regX` Number

  Optional.

- `regY` Number

  Optional.

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `rotate`

(

- `angle`

)
Matrix2D

Defined in `rotate:332`

Applies a clockwise rotation transformation to the matrix.

#### Parameters:

- `angle` Number

  The angle to rotate by, in degrees. To use a value in radians, multiply it by `180/Math.PI`.

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `scale`

(

- `x`
- `y`

)
Matrix2D

Defined in `scale:367`

Applies a scale transformation to the matrix.

#### Parameters:

- `x` Number

  The amount to scale horizontally. E.G. a value of 2 will double the size in the X direction, and 0.5 will halve it.

- `y` Number

  The amount to scale vertically.

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `setValues`

(

- `[a=1]`
- `[b=0]`
- `[c=0]`
- `[d=1]`
- `[tx=0]`
- `[ty=0]`

)
Matrix2D

Defined in `setValues:128`

Sets the specified values on this instance.

#### Parameters:

- `[a=1]` Number optional

  Specifies the a property for the new matrix.

- `[b=0]` Number optional

  Specifies the b property for the new matrix.

- `[c=0]` Number optional

  Specifies the c property for the new matrix.

- `[d=1]` Number optional

  Specifies the d property for the new matrix.

- `[tx=0]` Number optional

  Specifies the tx property for the new matrix.

- `[ty=0]` Number optional

  Specifies the ty property for the new matrix.

#### Returns:

Matrix2D:

This instance. Useful for chaining method calls.

### `skew`

(

- `skewX`
- `skewY`

)
Matrix2D

Defined in `skew:353`

Applies a skew transformation to the matrix.

#### Parameters:

- `skewX` Number

  The amount to skew horizontally in degrees. To use a value in radians, multiply it by `180/Math.PI`.

- `skewY` Number

  The amount to skew vertically in degrees.

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

### `toString`

() String

Defined in `toString:516`

Returns a string representation of this object.

#### Returns:

String:

a string representation of the instance.

### `transformPoint`

(

- `x`
- `y`
- `[pt]`

)
Point

Defined in `transformPoint:449`

Transforms a point according to this matrix.

#### Parameters:

- `x` Number

  The x component of the point to transform.

- `y` Number

  The y component of the point to transform.

- `[pt]` Point | Object optional

  An object to copy the result into. If omitted a generic object with x/y properties will be returned.

#### Returns:

Point:

This matrix. Useful for chaining method calls.

### `translate`

(

- `x`
- `y`

)
Matrix2D

Defined in `translate:384`

Translates the matrix on the x and y axes.

#### Parameters:

- `x` Number
- `y` Number

#### Returns:

Matrix2D:

This matrix. Useful for chaining method calls.

## Properties

### `a`

Number

Defined in `a:66`

Position (0, 0) in a 3x3 affine transformation matrix.

### `b`

Number

Defined in `b:72`

Position (0, 1) in a 3x3 affine transformation matrix.

### `c`

Number

Defined in `c:78`

Position (1, 0) in a 3x3 affine transformation matrix.

### `d`

Number

Defined in `d:84`

Position (1, 1) in a 3x3 affine transformation matrix.

### `DEG_TO_RAD`

Number final static readonly

Defined in `DEG_TO_RAD:105`

Multiplier for converting degrees to radians. Used internally by Matrix2D.

### `identity`

Matrix2D static readonly

Defined in `identity:117`

An identity matrix, representing a null transformation.

### `tx`

Number

Defined in `tx:90`

Position (2, 0) in a 3x3 affine transformation matrix.

### `ty`

Number

Defined in `ty:96`

Position (2, 1) in a 3x3 affine transformation matrix.