org.apache.pdfbox.util

## Class Matrix

- java.lang.Object
- - org.apache.pdfbox.util.Matrix

All Implemented Interfaces:
  Cloneable

    public final class Matrix
    extends Object
    implements Cloneable

This class will be used for matrix manipulation.

Author:
  Ben Litchfield

### Field Summary

Fields
`static int` `SIZE`

### Constructor Summary

Constructors
Constructor and Description
`Matrix()` Constructor.
`Matrix(AffineTransform at)` Creates a matrix with the same elements as the given AffineTransform.
`Matrix(COSArray array)` Deprecated. use `createMatrix(COSBase)` instead
`Matrix(float a, float b, float c, float d, float e, float f)` Creates a transformation matrix with the given 6 elements.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
`Matrix` `clone()` Clones this object.
`void` `concatenate(Matrix matrix)` Concatenates (premultiplies) the given matrix to this matrix.
`static Matrix` `concatenate(Matrix a, Matrix b)` Produces a copy of the first matrix, with the second matrix concatenated.
`AffineTransform` `createAffineTransform()` Create an affine transform from this matrix's values.
`static Matrix` `createMatrix(COSBase base)` Convenience method to be used when creating a matrix from unverified data.
`boolean` `equals(Object obj)`
`Matrix` `extractScaling()` Deprecated. This method is due to be removed, please contact us if you make use of it.
`Matrix` `extractTranslating()` Deprecated. This method is due to be removed, please contact us if you make use of it.
`static Matrix` `getRotateInstance(double theta, float tx, float ty)` Convenience method to create a rotated instance.
`static Matrix` `getScaleInstance(float x, float y)` Convenience method to create a scaled instance.
`float` `getScaleX()` Returns the x-scaling element of this matrix.
`float` `getScaleY()` Returns the y-scaling element of this matrix.
`float` `getScalingFactorX()` Returns the x-scaling factor of this matrix.
`float` `getScalingFactorY()` Returns the y-scaling factor of this matrix.
`float` `getShearX()` Returns the x-shear element of this matrix.
`float` `getShearY()` Returns the y-shear element of this matrix.
`static Matrix` `getTranslateInstance(float x, float y)` Convenience method to create a translating instance.
`float` `getTranslateX()` Returns the x-translation element of this matrix.
`float` `getTranslateY()` Returns the y-translation element of this matrix.
`static Matrix` `getTranslatingInstance(float x, float y)` Deprecated. Use `getTranslateInstance(float, float)` instead.
`float` `getValue(int row, int column)` This will get a matrix value at some point.
`float[][]` `getValues()` Return a single dimension array of all values in the matrix.
`double[][]` `getValuesAsDouble()` Deprecated. Use `getValues()` instead.
`float` `getXPosition()` Deprecated. Use `getTranslateX()` instead
`float` `getYPosition()` Deprecated. Use `getTranslateY()` instead
`int` `hashCode()`
`Matrix` `multiply(Matrix other)` This method multiplies this Matrix with the specified other Matrix, storing the product in a new instance.
`Matrix` `multiply(Matrix other, Matrix result)` Deprecated.
`void` `reset()` Deprecated. This method will be removed.
`void` `rotate(double theta)` Rotares this matrix by the given factors.
`void` `scale(float sx, float sy)` Scales this matrix by the given factors.
`void` `setFromAffineTransform(AffineTransform af)` Deprecated. Use the `Matrix(AffineTransform)` constructor instead.
`void` `setValue(int row, int column, float value)` This will set a value at a position.
`COSArray` `toCOSArray()` Returns a COS array which represent the geometric relevant components of the matrix.
`String` `toString()`
`void` `transform(Point2D point)` Transforms the given point by this matrix.
`Vector` `transform(Vector vector)` Transforms the given vector by this matrix.
`Point2D.Float` `transformPoint(float x, float y)` Transforms the given point by this matrix.
`void` `translate(float tx, float ty)` Translates this matrix by the given amount.
`void` `translate(Vector vector)` Translates this matrix by the given vector.

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### SIZE

    public static final int SIZE

See Also:
  Constant Field Values

### Constructor Detail

#### Matrix

    public Matrix()

Constructor. This produces an identity matrix.

#### Matrix

    public Matrix(COSArray array)

Deprecated. use `createMatrix(COSBase)` instead
Creates a matrix from a 6-element (a b c d e f) COS array.

Parameters:
  `array` - source array, elements must be or extend COSNumber

#### Matrix

    public Matrix(float a,
                  float b,
                  float c,
                  float d,
                  float e,
                  float f)

Creates a transformation matrix with the given 6 elements. Transformation matrices are discussed in 8.3.3, "Common Transformations" and 8.3.4, "Transformation Matrices" of the PDF specification. For simple purposes (rotate, scale, translate) it is recommended to use the static methods below. Produces the following matrix: a b 0 c d 0 e f 1

Parameters:
  `a` - the X coordinate scaling element (m00) of the 3x3 matrix
  `b` - the Y coordinate shearing element (m10) of the 3x3 matrix
  `c` - the X coordinate shearing element (m01) of the 3x3 matrix
  `d` - the Y coordinate scaling element (m11) of the 3x3 matrix
  `e` - the X coordinate translation element (m02) of the 3x3 matrix
  `f` - the Y coordinate translation element (m12) of the 3x3 matrix
See Also:
  `getRotateInstance(double, float, float)`, `getScaleInstance(float, float)`, `getTranslateInstance(float, float)`

#### Matrix

    public Matrix(AffineTransform at)

Creates a matrix with the same elements as the given AffineTransform.

Parameters:
  `at` - matrix elements will be initialize with the values from this affine transformation, as follows: scaleX shearY 0 shearX scaleY 0 transX transY 1

### Method Detail

#### createMatrix

    public static Matrix createMatrix(COSBase base)

Convenience method to be used when creating a matrix from unverified data. If the parameter is a COSArray with at least six numbers, a Matrix object is created from the first six numbers and returned. If not, then the identity Matrix is returned.

Parameters:
  `base` - a COS object, preferably a COSArray with six numbers.
Returns:
  a Matrix object.

#### reset

    @Deprecated
    public void reset()

Deprecated. This method will be removed.
This method resets the numbers in this Matrix to the original values, which are the values that a newly constructed Matrix would have.

#### createAffineTransform

    public AffineTransform createAffineTransform()

Create an affine transform from this matrix's values.

Returns:
  An affine transform with this matrix's values.

#### setFromAffineTransform

    @Deprecated
    public void setFromAffineTransform(AffineTransform af)

Deprecated. Use the `Matrix(AffineTransform)` constructor instead.
Set the values of the matrix from the AffineTransform.

Parameters:
  `af` - The transform to get the values from.

#### getValue

    public float getValue(int row,
                          int column)

This will get a matrix value at some point.

Parameters:
  `row` - The row to get the value from.
  `column` - The column to get the value from.
Returns:
  The value at the row/column position.

#### setValue

    public void setValue(int row,
                         int column,
                         float value)

This will set a value at a position.

Parameters:
  `row` - The row to set the value at.
  `column` - the column to set the value at.
  `value` - The value to set at the position.

#### getValues

    public float[][] getValues()

Return a single dimension array of all values in the matrix.

Returns:
  The values of this matrix.

#### getValuesAsDouble

    @Deprecated
    public double[][] getValuesAsDouble()

Deprecated. Use `getValues()` instead.
Return a single dimension array of all values in the matrix.

Returns:
  The values ot this matrix.

#### concatenate

    public void concatenate(Matrix matrix)

Concatenates (premultiplies) the given matrix to this matrix.

Parameters:
  `matrix` - The matrix to concatenate.

#### translate

    public void translate(Vector vector)

Translates this matrix by the given vector.

Parameters:
  `vector` - 2D vector

#### translate

    public void translate(float tx,
                          float ty)

Translates this matrix by the given amount.

Parameters:
  `tx` - x-translation
  `ty` - y-translation

#### scale

    public void scale(float sx,
                      float sy)

Scales this matrix by the given factors.

Parameters:
  `sx` - x-scale
  `sy` - y-scale

#### rotate

    public void rotate(double theta)

Rotares this matrix by the given factors.

Parameters:
  `theta` - The angle of rotation measured in radians

#### multiply

    public Matrix multiply(Matrix other)

This method multiplies this Matrix with the specified other Matrix, storing the product in a new instance. It is allowed to have (other == this).

Parameters:
  `other` - the second operand Matrix in the multiplication; required
Returns:
  the product of the two matrices.

#### multiply

    @Deprecated
    public Matrix multiply(Matrix other,
                                       Matrix result)

Deprecated.
This method multiplies this Matrix with the specified other Matrix, storing the product in the specified result Matrix. It is allowed to have (other == this) or (result == this) or indeed (other == result). See `multiply(Matrix)` if you need a version with a single operator.

Parameters:
  `other` - the second operand Matrix in the multiplication; required
  `result` - the Matrix instance into which the result should be stored. If result is null, a new Matrix instance is created.
Returns:
  the result.

#### transform

    public void transform(Point2D point)

Transforms the given point by this matrix.

Parameters:
  `point` - point to transform

#### transformPoint

    public Point2D.Float transformPoint(float x,
                                        float y)

Transforms the given point by this matrix.

Parameters:
  `x` - x-coordinate
  `y` - y-coordinate
Returns:
  the transformed point.

#### transform

    public Vector transform(Vector vector)

Transforms the given vector by this matrix.

Parameters:
  `vector` - 2D vector
Returns:
  the transformed vector.

#### extractScaling

    @Deprecated
    public Matrix extractScaling()

Deprecated. This method is due to be removed, please contact us if you make use of it.
Create a new matrix with just the scaling operators.

Returns:
  A new matrix with just the scaling operators.

#### getScaleInstance

    public static Matrix getScaleInstance(float x,
                                          float y)

Convenience method to create a scaled instance. Produces the following matrix: x 0 0 0 y 0 0 0 1

Parameters:
  `x` - The x-scale operator.
  `y` - The y-scale operator.
Returns:
  A new matrix with just the x/y scaling

#### extractTranslating

    @Deprecated
    public Matrix extractTranslating()

Deprecated. This method is due to be removed, please contact us if you make use of it.
Create a new matrix with just the translating operators.

Returns:
  A new matrix with just the translating operators.

#### getTranslatingInstance

    @Deprecated
    public static Matrix getTranslatingInstance(float x,
                                                            float y)

Deprecated. Use `getTranslateInstance(float, float)` instead.
Convenience method to create a translating instance. Produces the following matrix: 1 0 0 0 1 0 x y 1

Parameters:
  `x` - The x translating operator.
  `y` - The y translating operator.
Returns:
  A new matrix with just the x/y translating.

#### getTranslateInstance

    public static Matrix getTranslateInstance(float x,
                                              float y)

Convenience method to create a translating instance. Produces the following matrix: 1 0 0 0 1 0 x y 1

Parameters:
  `x` - The x translating operator.
  `y` - The y translating operator.
Returns:
  A new matrix with just the x/y translating.

#### getRotateInstance

    public static Matrix getRotateInstance(double theta,
                                           float tx,
                                           float ty)

Convenience method to create a rotated instance.

Parameters:
  `theta` - The angle of rotation measured in radians
  `tx` - The x translation.
  `ty` - The y translation.
Returns:
  A new matrix with the rotation and the x/y translating.

#### concatenate

    public static Matrix concatenate(Matrix a,
                                     Matrix b)

Produces a copy of the first matrix, with the second matrix concatenated.

Parameters:
  `a` - The matrix to copy.
  `b` - The matrix to concatenate.

#### clone

    public Matrix clone()

Clones this object.

Overrides:
  `clone` in class `Object`
Returns:
  cloned matrix as an object.

#### getScalingFactorX

    public float getScalingFactorX()

Returns the x-scaling factor of this matrix. This is calculated from the scale and shear.

Returns:
  The x-scaling factor.

#### getScalingFactorY

    public float getScalingFactorY()

Returns the y-scaling factor of this matrix. This is calculated from the scale and shear.

Returns:
  The y-scaling factor.

#### getScaleX

    public float getScaleX()

Returns the x-scaling element of this matrix.

See Also:
  `getScalingFactorX()`

#### getShearY

    public float getShearY()

Returns the y-shear element of this matrix.

#### getShearX

    public float getShearX()

Returns the x-shear element of this matrix.

#### getScaleY

    public float getScaleY()

Returns the y-scaling element of this matrix.

See Also:
  `getScalingFactorY()`

#### getTranslateX

    public float getTranslateX()

Returns the x-translation element of this matrix.

#### getTranslateY

    public float getTranslateY()

Returns the y-translation element of this matrix.

#### getXPosition

    @Deprecated
    public float getXPosition()

Deprecated. Use `getTranslateX()` instead
Get the x position in the matrix. This method is deprecated as it is incorrectly named.

Returns:
  The x-position.

#### getYPosition

    @Deprecated
    public float getYPosition()

Deprecated. Use `getTranslateY()` instead
Get the y position. This method is deprecated as it is incorrectly named.

Returns:
  The y position.

#### toCOSArray

    public COSArray toCOSArray()

Returns a COS array which represent the geometric relevant components of the matrix. The last column of the matrix is ignored, only the first two columns are returned. This is analog to the Matrix(COSArray) constructor.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### equals

    public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`