Package com.itextpdf.kernel.geom
Class Matrix
java.lang.Object
com.itextpdf.kernel.geom.Matrix
Keeps all the values of a 3 by 3 matrix and allows you to do some math with matrices.
Transformation matrix in PDF is a special case of a 3 by 3 matrix [a b 0]
[c d 0]
[e f 1]
In its most general form, this matrix is specified by six numbers, usually in the form of an array containing six elements [a b c d e f]
. It can represent any linear transformation from one coordinate system to another. Here the most common transformations:
- Translations shall be specified as
[1 0 0 1 Tx Ty]
, whereTx
andTy
shall be the distances to translate the origin of the coordinate system in the horizontal and vertical dimensions, respectively. - Scaling shall be 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 asSx
andSy
units, respectively, in the previous coordinate system. - Rotations shall be produced by
[Rc Rs -Rs Rc 0 0]
, whereRc = cos(q)
andRs = sin(q)
which has the effect of rotating the coordinate system axes by an angleq
counterclockwise. - Skew shall be specified by
[1 Wx Wy 1 0 0]
, whereWx = tan(a)
andWy = tan(b)
which skews the x-axis by an anglea
and the y-axis by an angleb
.
For more information see PDF Specification ISO 32000-1 section 8.3.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The row=1, col=1 position ('a') in the matrix.static final int
The row=1, col=2 position ('b') in the matrix.static final int
The row=1, col=3 position (always 0 for 2D) in the matrix.static final int
The row=2, col=1 position ('c') in the matrix.static final int
The row=2, col=2 position ('d') in the matrix.static final int
The row=2, col=3 position (always 0 for 2D) in the matrix.static final int
The row=3, col=1 ('e', or X translation) position in the matrix.static final int
The row=3, col=2 ('f', or Y translation) position in the matrix.static final int
The row=3, col=3 position (always 1 for 2D) in the matrix. -
Constructor Summary
ConstructorsConstructorDescriptionMatrix()
Constructs a new Matrix with identity.Matrix
(float tx, float ty) Constructs a matrix that represents translation.Matrix
(float a, float b, float c, float d, float e, float f) Creates a Matrix with 6 specified entries.Matrix
(float e11, float e12, float e13, float e21, float e22, float e23, float e31, float e32, float e33) Creates a Matrix with 9 specified entries. -
Method Summary
Modifier and TypeMethodDescriptionAdds a matrix from this matrix and returns the results.boolean
Checks equality of matrices.float
get
(int index) Gets a specific value inside the matrix.float
Computes the determinant of the matrix.int
hashCode()
Generates a hash code for this object.multiplies this matrix by 'b' and returns the result.Subtracts a matrix from this matrix and returns the results.toString()
Generates a String representation of the matrix.
-
Field Details
-
I11
public static final int I11The row=1, col=1 position ('a') in the matrix.- See Also:
-
I12
public static final int I12The row=1, col=2 position ('b') in the matrix.- See Also:
-
I13
public static final int I13The row=1, col=3 position (always 0 for 2D) in the matrix.- See Also:
-
I21
public static final int I21The row=2, col=1 position ('c') in the matrix.- See Also:
-
I22
public static final int I22The row=2, col=2 position ('d') in the matrix.- See Also:
-
I23
public static final int I23The row=2, col=3 position (always 0 for 2D) in the matrix.- See Also:
-
I31
public static final int I31The row=3, col=1 ('e', or X translation) position in the matrix.- See Also:
-
I32
public static final int I32The row=3, col=2 ('f', or Y translation) position in the matrix.- See Also:
-
I33
public static final int I33The row=3, col=3 position (always 1 for 2D) in the matrix.- See Also:
-
-
Constructor Details
-
Matrix
public Matrix()Constructs a new Matrix with identity. -
Matrix
public Matrix(float tx, float ty) Constructs a matrix that represents translation.- Parameters:
-
tx
- x-axis translation -
ty
- y-axis translation
-
Matrix
public Matrix(float e11, float e12, float e13, float e21, float e22, float e23, float e31, float e32, float e33) Creates a Matrix with 9 specified entries.- Parameters:
-
e11
- element at position (1,1) -
e12
- element at position (1,2) -
e13
- element at position (1,3) -
e21
- element at position (2,1) -
e22
- element at position (2,2) -
e23
- element at position (2,3) -
e31
- element at position (3,1) -
e32
- element at position (3,2) -
e33
- element at position (3,3)
-
Matrix
public Matrix(float a, float b, float c, float d, float e, float f) Creates a Matrix with 6 specified entries. The third column will always be [0 0 1] (row, column)- Parameters:
-
a
- element at (1,1) -
b
- element at (1,2) -
c
- element at (2,1) -
d
- element at (2,2) -
e
- element at (3,1) -
f
- element at (3,2)
-
-
Method Details
-
get
public float get(int index) Gets a specific value inside the matrix.For reference, the indeces are as follows:
I11 I12 I13
I21 I22 I23
I31 I32 I33- Parameters:
-
index
- an array index corresponding with a value inside the matrix - Returns:
- the value at that specific position.
-
multiply
multiplies this matrix by 'b' and returns the result. See Matrix_multiplication- Parameters:
-
by
- The matrix to multiply by - Returns:
- the resulting matrix
-
add
Adds a matrix from this matrix and returns the results.- Parameters:
-
arg
- the matrix to subtract from this matrix - Returns:
- a Matrix object
-
subtract
Subtracts a matrix from this matrix and returns the results.- Parameters:
-
arg
- the matrix to subtract from this matrix - Returns:
- a Matrix object
-
getDeterminant
public float getDeterminant()Computes the determinant of the matrix.- Returns:
- the determinant of the matrix
-
equals
Checks equality of matrices. -
hashCode
public int hashCode()Generates a hash code for this object. -
toString
Generates a String representation of the matrix.
-