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
m1scales an object by a factor of four, and matrixm2rotates an object by 1.5707963267949 radians (Math.PI/2), thenm1.concat(m2)transformsm1into a matrix that scales an object by a factor of four and rotates the object byMath.PI/2radians.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 matrixgraphics.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 matrixgraphics.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 theidentity(),rotate(),scale(), andtranslate()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 scaleXnumber The factor by which to scale horizontally.
scaleYnumber The factor by which scale vertically.
rotationnumber <optional>
0 The amount to rotate, in radians.
txnumber <optional>
0 The number of pixels to translate (move) to the right along the x axis.
tynumber <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)// ormat.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()andlineGradientStyle()methods of the Graphics class. Width and height are scaled to ascaleX/scaleYpair and thetx/tyvalues are offset by half the width and height.Parameters:
Name Type Argument Default Description widthnumber The width of the box.
scaleYnumber The height of the box.
rotationnumber <optional>
0 The amount to rotate, in radians.
txnumber <optional>
0 The number of pixels to translate (move) to the right along the x axis.
tynumber <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, thedeltaTransformPoint()method's transformation does not consider the translation parameterstxandty.Parameters:
Name Type Description pointgraphics.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:
trueif 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 anglenumber 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 bysy.The
scale()method alters theaanddproperties of the Matrix object. In matrix notation, this is the same as concatenating the current matrix with the following matrix:
Parameters:
Name Type Description sxnumber A multiplier used to scale the object along the x axis.
synumber A multiplier used to scale the object along the y axis.
-
setTo( [a] [, b] [, c] [, d] [, tx] [, ty])
-
Sets the members of the
Matrixto the specified values.Parameters:
Name Type Argument Default Description anumber <optional>
1 The value that affects the positioning of pixels along the x axis when scaling or rotating an image.
bnumber <optional>
0 The value that affects the positioning of pixels along the y axis when rotating or skewing an image.
cnumber <optional>
0 The value that affects the positioning of pixels along the x axis when rotating or skewing an image.
dnumber <optional>
1 The value that affects the positioning of pixels along the y axis when scaling or rotating an image.
txnumber <optional>
0 The distance by which to translate each point along the x axis.
tynumber <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
dxanddyparameters.Parameters:
Name Type Argument Default Description dxnumber <optional>
0 The amount of movement along the x axis to the right, in pixels.
dynumber <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 pointgraphics.geom.Point The point for which you want to get the result of the
Matrixtransformation.Returns:
The point resulting from applying the
Matrixtransformation.