# Class: Matrix2D

## PDFNet. Matrix2D

#### new Matrix2D()

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

### Methods

#### <static> createIdentityMatrix()

Create identity matrix (1 0 0 1 0 0)

##### Returns:

A promise that resolves to an object of type: "matrix2d"

Type
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
PDFNet.matrix2d

#### <static> createZeroMatrix()

Create zero matrix (0 0 0 0 0 0)

##### Returns:

A promise that resolves to an object of type: "matrix2d"

Type
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.

#### copy()

Assignment operator.

##### Returns:

A promise that resolves to an object of type: "matrix2d"

Type
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` 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
boolean

#### inverse()

##### Returns:

A promise that resolves to if this matrix is invertible, the Inverse method returns its inverse matrix.

Type
PDFNet.matrix2d

#### mult(x, y)

Transform/multiply the point (x, y) using this matrix

##### Parameters:
Name Type Description
`x`

x-coordinate of point to transform

`y`

y-coordinate of point to transform

##### Returns:

A javascript object that contains an x value and y value

Type
PDFNet.Obj

#### 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:

updated this matrix

#### 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.

#### translate(h, v)

The Translate method 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.

##### Returns:

updated this matrix