Class: Matrix

graphics.geom. Matrix


new Matrix( [a] [, b] [, c] [, d] [, tx] [, ty])

The Matrix class represents a transformation matrix that determines how to map points from one coordinate space to another.

The Matrix class represents a transformation matrix that determines how to map points from one coordinate space to another.

You can perform various graphical transformations on a display object by setting the properties of a Matrix object, applying that Matrix object to the matrix property of a Transform object, and then applying that Transform object as the transform property of the display object. These transformation functions include translation (x and y repositioning), rotation, scaling, and skewing.

Parameters:
Name Type Argument Default Description
a number <optional>
1

The value that affects the positioning of pixels along the x axis when scaling or rotating an image.

b number <optional>
0

The value that affects the positioning of pixels along the y axis when rotating or skewing an image.

c number <optional>
0

The value that affects the positioning of pixels along the x axis when rotating or skewing an image.

d number <optional>
1

The value that affects the positioning of pixels along the y axis when scaling or rotating an image.

tx number <optional>
0

The distance by which to translate each point along the x axis.

ty number <optional>
0

The distance by which to translate each point along the y axis.

Example

The following example creates matrix_1 by sending no parameters to the Matrix() constructor and matrix_2 by sending parameters to it. Notice that matrix_1, which was created with no parameters, results in an identity matrix with the values a=1, b=0, c=0, d=1, tx=0, ty=0.

trace( new Matrix() ) ;  // [Matrix a:1 b:0 c:0, d:1 tx:0 ty:0]
trace(new Matrix(1, 2, 3, 4, 5, 6));  // [Matrix a:1 b:2 c:3, d:4 tx:5 ty:6]

Members


a :Number

The value that affects the positioning of pixels along the x axis when scaling or rotating an image.

Type:
  • Number
Default Value:
  • 0

b :Number

The value that affects the positioning of pixels along the y axis when rotating or skewing an image.

Type:
  • Number
Default Value:
  • 0

c :Number

The value that affects the positioning of pixels along the x axis when rotating or skewing an image.

Type:
  • Number
Default Value:
  • 0

d :Number

The value that affects the positioning of pixels along the y axis when scaling or rotating an image.

Type:
  • Number
Default Value:
  • 0

tx :Number

The distance by which to translate each point along the x axis.

Type:
  • Number
Default Value:
  • 0

ty :Number

The distance by which to translate each point along the y axis.

Type:
  • Number
Default Value:
  • 0

Methods


clone()

Create a shallow copy of the object.

Returns:

a shallow copy of the object.


concat(matrix)

Concatenates a matrix with the current matrix, effectively combining the geometric effects of the two. In mathematical terms, concatenating two matrixes is the same as combining them using matrix multiplication.

For example, if matrix m1 scales an object by a factor of four, and matrix m2 rotates an object by 1.5707963267949 radians (Math.PI/2), then m1.concat(m2) transforms m1 into a matrix that scales an object by a factor of four and rotates the object by Math.PI/2 radians.

This method replaces the source matrix with the concatenated matrix. If you want to concatenate two matrixes without altering either of the two source matrixes, first copy the source matrix by using the clone() method, as shown in the Class Examples section.

Parameters:
Name Type Description
matrix graphics.geom.Matrix | Object

The matrix to be concatenated to the source matrix.


copyFrom(matrix)

Copies all of the matrix data from the source Point object into the calling Matrix object.

Parameters:
Name Type Description
matrix graphics.geom.Matrix

The Matrix object from which to copy the data.


createBox(scaleX, scaleY [, rotation] [, tx] [, ty])

Includes parameters for scaling, rotation, and translation. When applied to a matrix it sets the matrix's values based on those parameters.

Using the createBox() method lets you obtain the same matrix as you would if you applied the identity(), rotate(), scale(), and translate() methods in succession. For example, mat.createBox(2,2,Math.PI/4, 100, 100) has the same effect as the following:

Parameters:
Name Type Argument Default Description
scaleX number

The factor by which to scale horizontally.

scaleY number

The factor by which scale vertically.

rotation number <optional>
0

The amount to rotate, in radians.

tx number <optional>
0

The number of pixels to translate (move) to the right along the x axis.

ty number <optional>
0

The number of pixels to translate (move) down along the y axis.

Example
var mat = new Matrix();
mat.createBox(2,2,Math.PI/4, 100, 100)
// or
mat.identity();
mat.rotate(Math.PI/4);
mat.scale(2,2);
mat.translate(10,20);

createGradientBox(width, scaleY [, rotation] [, tx] [, ty])

Creates the specific style of matrix expected by the beginGradientFill() and lineGradientStyle() methods of the Graphics class. Width and height are scaled to a scaleX/scaleY pair and the tx/ty values are offset by half the width and height.

Parameters:
Name Type Argument Default Description
width number

The width of the box.

scaleY number

The height of the box.

rotation number <optional>
0

The amount to rotate, in radians.

tx number <optional>
0

The number of pixels to translate (move) to the right along the x axis.

ty number <optional>
0

The number of pixels to translate (move) down along the y axis.


deltaTransformPoint(point)

Given a point in the pretransform coordinate space, returns the coordinates of that point after the transformation occurs.

Unlike the standard transformation applied using the transformPoint() method, the deltaTransformPoint() method's transformation does not consider the translation parameters tx and ty.

Parameters:
Name Type Description
point graphics.geom.Point | Object

The point for which you want to get the result of the matrix transformation.

Returns:

The point resulting from applying the matrix transformation.


equals()

Compares the passed-in object with this object for equality.

Returns:

true if the the specified object is equal with this object.


identity()

Sets each matrix property to a value that causes a null transformation.

An object transformed by applying an identity matrix will be identical to the original.


invert()

Performs the opposite transformation of the original matrix. You can apply an inverted matrix to an object to undo the transformation performed when applying the original matrix.


rotate(angle)

Applies a rotation transformation to the Matrix object.

Parameters:
Name Type Description
angle number

The rotation angle in radians.


scale(sx, sy)

Applies a scaling transformation to the matrix.

The x axis is multiplied by sx, and the y axis it is multiplied by sy.

The scale() method alters the a and d properties of the Matrix object. In matrix notation, this is the same as concatenating the current matrix with the following matrix:

Parameters:
Name Type Description
sx number

A multiplier used to scale the object along the x axis.

sy number

A multiplier used to scale the object along the y axis.


setTo( [a] [, b] [, c] [, d] [, tx] [, ty])

Sets the members of the Matrix to the specified values.

Parameters:
Name Type Argument Default Description
a number <optional>
1

The value that affects the positioning of pixels along the x axis when scaling or rotating an image.

b number <optional>
0

The value that affects the positioning of pixels along the y axis when rotating or skewing an image.

c number <optional>
0

The value that affects the positioning of pixels along the x axis when rotating or skewing an image.

d number <optional>
1

The value that affects the positioning of pixels along the y axis when scaling or rotating an image.

tx number <optional>
0

The distance by which to translate each point along the x axis.

ty number <optional>
0

The distance by which to translate each point along the y axis.


toObject()

Returns the Object representation of this object.

Returns:

the Object representation of this object.


toString( [dx] [, dy])

Translates the matrix along the x and y axes, as specified by the dx and dy parameters.

Parameters:
Name Type Argument Default Description
dx number <optional>
0

The amount of movement along the x axis to the right, in pixels.

dy number <optional>
0

The amount of movement down along the y axis, in pixels.


toString()

Returns a text value listing the properties of the Matrix object.

Returns:

The text value listing the properties of the Matrix object.


toString(point)

Returns the result of applying the geometric transformation represented by the Matrix object to the specified point.

Parameters:
Name Type Description
point graphics.geom.Point

The point for which you want to get the result of the Matrix transformation.

Returns:

The point resulting from applying the Matrix transformation.