new Matrix2D( [m_a] [, m_b] [, m_c] [, m_d] [, m_h] [, m_v])
2D Matrix
A Matrix2D object represents a 3x3 matrix that, in turn, represents an affine transformation.
A Matrix2D object stores only six of the nine numbers in a 3x3 matrix because all 3x3
matrices that represent affine transformations have the same third column (0, 0, 1).
Affine transformations include rotating, scaling, reflecting, shearing, and translating.
In PDFNet, the Matrix2D class provides the foundation for performing affine transformations
on vector drawings, images, and text.
A transformation matrix specifies the relationship between two coordinate spaces.
By modifying a transformation matrix, objects can be scaled, rotated, translated,
or transformed in other ways.
A transformation matrix in PDF is specified by six numbers, usually in the form
of an array containing six elements. In its most general form, this array is denoted
[a b c d h v]; The following table lists the arrays that specify the most common
transformations:
- Translations are specified as [1 0 0 1 tx ty], where tx and ty are the distances
to translate the origin of the coordinate system in the horizontal and vertical
dimensions, respectively.
- Scaling is obtained by [sx 0 0 sy 0 0]. This scales the coordinates so that 1
unit in the horizontal and vertical dimensions of the new coordinate system is
the same size as sx and sy units, respectively, in the previous coordinate system.
- Rotations are produced by [cos(A) sin(A) -sin(A) cos(A) 0 0], which has the effect
of rotating the coordinate system axes by an angle 'A' counterclockwise.
- Skew is specified by [1 tan(A) tan(B) 1 0 0], which skews the x axis by an angle
A and the y axis by an angle B.
Matrix2D elements are positioned as follows :
| m_a m_b 0 |
| m_c m_d 0 |
| m_h m_v 1 |
A single Matrix2D object can store a single transformation or a sequence of transformations.
The latter is called a composite transformation. The matrix of a composite transformation is
obtained by multiplying (concatenating) the matrices of the individual transformations.
Because matrix multiplication is not commutative-the order in which matrices are multiplied
is significant. For example, if you first rotate, then scale, then translate, you get a
different result than if you first translate, then rotate, then scale.
--------------------
Since Matrix2D is a struct, it can be created manually by calling "new PDFNet.Matrix2D(m_a, m_b, m_c, m_d, m_h, m_v)"
eg. var myfoo = new PDFNet.Matrix2D(1,0,0,1,0,0);
Default values for a Matrix2D struct are:
m_a = 0
m_b = 0
m_c = 0
m_d = 0
m_h = 0
m_v = 0
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
m_a |
number |
<optional> |
|
m_b |
number |
<optional> |
|
m_c |
number |
<optional> |
|
m_d |
number |
<optional> |
|
m_h |
number |
<optional> |
|
m_v |
number |
<optional> |
Properties:
Name | Type | Description |
---|---|---|
m_a |
number | |
m_b |
number | |
m_c |
number | |
m_d |
number | |
m_h |
number | |
m_v |
number |
Methods
-
<static> create( [a] [, b] [, c] [, d] [, h] [, v])
-
Creates and initializes a Matrix object based on six numbers that define an affine transformation.
Parameters:
Name Type Argument Default Description a
number <optional>
0 the matrix element in the first row, first column. b
number <optional>
0 the matrix element in the first row, second column. c
number <optional>
0 the matrix element in the second row, first column. d
number <optional>
0 the matrix element in the second row, second column. h
number <optional>
0 the matrix element in the third row, first column. v
number <optional>
0 the matrix element in the third row, second column. Returns:
A promise that resolves to an object of type: "Matrix2D".- Type
- Promise.<Core.PDFNet.Matrix2D>
-
<static> createIdentityMatrix()
-
Create identity matrix (1 0 0 1 0 0)
Returns:
A promise that resolves to an object of type: "PDFNet.Matrix2D"- Type
- Promise.<Core.PDFNet.Matrix2D>
-
<static> createRotationMatrix(angle)
-
Parameters:
Name Type Description angle
number the angle of rotation in radians. Positive values specify clockwise rotation. Returns:
A promise that resolves to a rotation matrix for a given angle.- Type
- Promise.<Core.PDFNet.Matrix2D>
-
<static> createZeroMatrix()
-
Create zero matrix (0 0 0 0 0 0)
Returns:
A promise that resolves to an object of type: "PDFNet.Matrix2D"- Type
- Promise.<Core.PDFNet.Matrix2D>
-
concat(a, b, c, d, h, v)
-
The Concat method updates this matrix with the product of itself and another matrix specified through an argument list.
Parameters:
Name Type Description a
number the matrix element in the first row, first column. b
number the matrix element in the first row, second column. c
number the matrix element in the second row, first column. d
number the matrix element in the second row, second column. h
number the matrix element in the third row, first column. v
number the matrix element in the third row, second column. Returns:
- Type
- Promise.<void>
-
copy()
-
Copy Constructor
Returns:
A promise that resolves to an object of type: "PDFNet.Matrix2D"- Type
- Promise.<Core.PDFNet.Matrix2D>
-
equals(m2)
-
The equality operator determines whether the elements of this matrix are equal to the elements of another matrix.
Parameters:
Name Type Description m2
Core.PDFNet.Matrix2D A Matrix object that is compared with this Matrix object. Returns:
A promise that resolves to a boolean regarding whether two matrices are the same.- Type
- Promise.<boolean>
-
inverse()
-
Returns:
A promise that resolves to if this matrix is invertible, the Inverse method returns its inverse matrix.- Type
- Promise.<Core.PDFNet.Matrix2D>
-
mult(x, y)
-
Transform/multiply the point (x, y) using this matrix
Parameters:
Name Type Description x
number x-coordinate of point to transform y
number y-coordinate of point to transform Returns:
A promise that resolves to a javascript object that contains an x value and y value- Type
- Promise.<Core.PDFNet.Obj>
-
multiply(m)
-
Parameters:
Name Type Description m
Core.PDFNet.Matrix2D Returns:
- Type
- Promise.<void>
-
postTranslate(h, v)
-
Updates this matrix by concatenating a translation matrix. M' = M * T(h, v). It is equivalent to this.Concat(1,0,0,1,h,v).
Parameters:
Name Type Description h
number the horizontal component of the translation. v
number the vertical component of the translation. Returns:
- Type
- Promise.<void>
-
preTranslate(h, v)
-
Updates this matrix to the concatenation of a translation matrix and the original matrix. M' = T(h, v) * M. It is equivalent to this.m_h += h; this.m_v += v.
Parameters:
Name Type Description h
number the horizontal component of the translation. v
number the vertical component of the translation. Returns:
- Type
- Promise.<void>
-
scale(h, v)
-
The Scale method updates this matrix with the product of itself and a scaling matrix.
Parameters:
Name Type Description h
number the horizontal scale factor. v
number the vertical scale factor Returns:
- Type
- Promise.<void>
-
set(a, b, c, d, h, v)
-
The Set method sets the elements of this matrix.
Parameters:
Name Type Description a
number the matrix element in the first row, first column. b
number the matrix element in the first row, second column. c
number the matrix element in the second row, first column. d
number the matrix element in the second row, second column. h
number the matrix element in the third row, first column. v
number the matrix element in the third row, second column. Returns:
- Type
- Promise.<void>
-
translate(h, v)
-
Updates this matrix with the product of itself and a translation matrix (i.e. it is equivalent to this.m_h += h; this.m_v += v).
Parameters:
Name Type Description h
number the horizontal component of the translation. v
number the vertical component of the translation. Note: This method is deprecated. Please use PreTranslate or PostTranslate instead. The behavior of this method is identical to PreTranslate, but PostTranslate will be more suitable for some use cases. Returns:
- Type
- Promise.<void>