Class AffineTransform

java.lang.Object
com.itextpdf.kernel.geom.AffineTransform
All Implemented Interfaces:
Cloneable

public class AffineTransform extends Object implements Cloneable
The AffineTransform class represents an affine transformation, which is a combination of linear transformations such as translation, scaling, rotation, and shearing which allows preservation of the straightness of lines.
  • Field Details

  • Constructor Details

    • AffineTransform

      public AffineTransform()
      Create an empty AffineTransform instance. The default type is for the transformation is TYPE_IDENTITY
    • AffineTransform

      public AffineTransform (AffineTransform t)
      Will create a new AffineTransform instance with the values provided from the original AffineTransform instance.
      Parameters:
      t - The AffineTransform class to be used.
    • AffineTransform

      public AffineTransform (double m00, double m10, double m01, double m11, double m02, double m12)
      Create an AffineTransform instance with the values provided. The default type is for the transformation is TYPE_UNKNOWN
      Parameters:
      m00 - The value of the first row and first column of the matrix.
      m10 - The value of the second row and first column of the matrix.
      m01 - The value of the first row and second column of the matrix.
      m11 - The value of the second row and second column of the matrix.
      m02 - The value of the first row and third column of the matrix.
      m12 - The value of the second row and third column of the matrix.
    • AffineTransform

      public AffineTransform (float[] matrix)
      Create an AffineTransform instance with the values provided. The default type is for the transformation is TYPE_UNKNOWN
      Parameters:
      matrix - The array of values to be used for the transformation matrix.
    • AffineTransform

      public AffineTransform (double[] matrix)
      Create an AffineTransform instance with the values provided. The default type is for the transformation is TYPE_UNKNOWN
      Parameters:
      matrix - The array of values to be used for the transformation matrix.
  • Method Details

    • getType

      public int getType()
      Method returns type of affine transformation.

      Transform matrix is m00 m01 m02 m10 m11 m12

      According analytic geometry new basis vectors are (m00, m01) and (m10, m11), translation vector is (m02, m12). Original basis vectors are (1, 0) and (0, 1). Type transformations classification:

      Returns:
      the type of this AffineTransform
    • getScaleX

      public double getScaleX()
      Gets the scale factor of the x-axis.
      Returns:
      the scale factor of the x-axis.
    • getScaleY

      public double getScaleY()
      Gets the scale factor of the y-axis.
      Returns:
      the scale factor of the y-axis.
    • getShearX

      public double getShearX()
      Gets the shear factor of the x-axis.
      Returns:
      the shear factor of the x-axis.
    • getShearY

      public double getShearY()
      Gets the shear factor of the y-axis.
      Returns:
      the shear factor of the y-axis.
    • getTranslateX

      public double getTranslateX()
      Gets translation factor of the x-axis.
      Returns:
      the translation factor of the x-axis.
    • getTranslateY

      public double getTranslateY()
      Gets translation factor of the y-axis.
      Returns:
      the translation factor of the y-axis.
    • isIdentity

      public boolean isIdentity()
      Gets whether this AffineTransform is an identity transformation.
      Returns:
      true if this AffineTransform is an identity transformation, false otherwise.
    • getMatrix

      public void getMatrix (float[] matrix)
      Fills the matrix parameter with the values of this AffineTransform instance.
      Parameters:
      matrix - the array to be filled with the values of this AffineTransform instance.
    • getMatrix

      public void getMatrix (double[] matrix)
      Fills the matrix parameter with the values of this AffineTransform instance.
      Parameters:
      matrix - the array to be filled with the values of this AffineTransform instance.
    • getDeterminant

      public double getDeterminant()
      Gets the determinant of the matrix representation of this AffineTransform.
      Returns:
      the determinant of the matrix representation of this AffineTransform.
    • setTransform

      public void setTransform (float m00, float m10, float m01, float m11, float m02, float m12)
      Sets the values of this AffineTransform instance to the values provided. The type of the transformation is set to TYPE_UNKNOWN.
      Parameters:
      m00 - The value of the first row and first column of the matrix.
      m10 - The value of the second row and first column of the matrix.
      m01 - The value of the first row and second column of the matrix.
      m11 - The value of the second row and second column of the matrix.
      m02 - The value of the first row and third column of the matrix.
      m12 - The value of the second row and third column of the matrix.
    • setTransform

      public void setTransform (double m00, double m10, double m01, double m11, double m02, double m12)
      Sets the values of this AffineTransform instance to the values provided. The type of the transformation is set to TYPE_UNKNOWN.
      Parameters:
      m00 - The value of the first row and first column of the matrix.
      m10 - The value of the second row and first column of the matrix.
      m01 - The value of the first row and second column of the matrix.
      m11 - The value of the second row and second column of the matrix.
      m02 - The value of the first row and third column of the matrix.
      m12 - The value of the second row and third column of the matrix.
    • setTransform

      public void setTransform (AffineTransform t)
      Sets the values of this AffineTransform instance to the values provided.
      Parameters:
      t - The AffineTransform instance to be used.
    • setToIdentity

      public void setToIdentity()
      Sets this AffineTransform to the identity transformation.
    • setToTranslation

      public void setToTranslation (double mx, double my)
      Sets this AffineTransform to represent a translation transformation.
      Parameters:
      mx - The value of the translation on the x-axis.
      my - The value of the translation on the y-axis.
    • setToScale

      public void setToScale (double scx, double scy)
      Sets this AffineTransform to represent a scale transformation.
      Parameters:
      scx - The value of the scale factor on the x-axis.
      scy - The value of the scale factor on the y-axis.
    • setToShear

      public void setToShear (double shx, double shy)
      Sets this AffineTransform to represent a shear transformation.
      Parameters:
      shx - The value of the shear factor on the x-axis.
      shy - The value of the shear factor on the y-axis.
    • setToRotation

      public void setToRotation (double angle)
      Set this affine transformation to represent a rotation over the passed angle
      Parameters:
      angle - angle to rotate over in radians
    • setToRotation

      public void setToRotation (double angle, double px, double py)
      Set this affine transformation to represent a rotation over the passed angle, using the passed point as the center of rotation
      Parameters:
      angle - angle to rotate over in radians
      px - x-coordinate of center of rotation
      py - y-coordinate of center of rotation
    • getTranslateInstance

      public static AffineTransform getTranslateInstance (double mx, double my)
      Get a new AffineTransform instance representing a translation over the passed values
      Parameters:
      mx - x-coordinate of translation
      my - y-coordinate of translation
      Returns:
      AffineTransform representing the translation
    • getScaleInstance

      public static AffineTransform getScaleInstance (double scx, double scY)
      Get a new AffineTransform instance representing a scale over the passed values
      Parameters:
      scx - scale factor on the x-axis
      scY - scale factor on the y-axis
      Returns:
      AffineTransform representing the scale
    • getShearInstance

      public static AffineTransform getShearInstance (double shx, double shy)
      Get a new AffineTransform instance representing a shear over the passed values
      Parameters:
      shx - shear factor on the x-axis
      shy - shear factor on the y-axis
      Returns:
      AffineTransform representing the shear
    • getRotateInstance

      public static AffineTransform getRotateInstance (double angle)
      Get an affine transformation representing a counter-clockwise rotation over the passed angle
      Parameters:
      angle - angle in radians to rotate over
      Returns:
      AffineTransform representing the rotation
    • getRotateInstance

      public static AffineTransform getRotateInstance (double angle, double x, double y)
      Get an affine transformation representing a counter-clockwise rotation over the passed angle, using the passed point as the center of rotation
      Parameters:
      angle - angle in radians to rotate over
      x - x-coordinate of center of rotation
      y - y-coordinate of center of rotation
      Returns:
      AffineTransform representing the rotation
    • translate

      public void translate (double mx, double my)
    • scale

      public void scale (double scx, double scy)
    • shear

      public void shear (double shx, double shy)
    • rotate

      public void rotate (double angle)
      Add a counter-clockwise rotation to this transformation
      Parameters:
      angle - angle in radians to rotate over
    • rotate

      public void rotate (double angle, double px, double py)
      Add a counter-clockwise rotation to this transformation, using the passed point as the center of rotation
      Parameters:
      angle - angle in radians to rotate over
      px - x-coordinate of center of rotation
      py - y-coordinate of center of rotation
    • concatenate

      public void concatenate (AffineTransform t)
      Multiply matrix of two AffineTransform objects
      Parameters:
      t - - the AffineTransform object is a multiplier.
    • preConcatenate

      public void preConcatenate (AffineTransform t)
      Multiply matrix of two AffineTransform objects
      Parameters:
      t - - the AffineTransform object is a multiplicand.
    • createInverse

      public AffineTransform createInverse() throws NoninvertibleTransformException
      Creates a new AffineTransform object that is invert of this AffineTransform object.
      Returns:
      a new AffineTransform object that is invert of this AffineTransform object.
      Throws:
      NoninvertibleTransformException - if this AffineTransform object cannot be inverted.
    • transform

      public Point transform (Point src, Point dst)
      Transform the point according to the values of this AffineTransform object.
      Parameters:
      src - The point to be transformed.
      dst - The point that will hold the result of the transformation.
      Returns:
      The point that holds the result of the transformation.
    • transform

      public void transform (Point[] src, int srcOff, Point[] dst, int dstOff, int length)
      Transform the array of points according to the values of this AffineTransform object.
      Parameters:
      src - The array of points to be transformed.
      srcOff - The offset of the first point in the array.
      dst - The array of points that will hold the result of the transformation.
      dstOff - The offset of the first point in the destination array.
      length - The number of points to be transformed.
    • transform

      public void transform (double[] src, int srcOff, double[] dst, int dstOff, int length)
      Transform the array of points according to the values of this AffineTransform object.
      Parameters:
      src - The array of points to be transformed.
      srcOff - The offset of the first point in the array.
      dst - The array of points that will hold the result of the transformation.
      dstOff - The offset of the first point in the destination array.
      length - The number of points to be transformed.
    • transform

      public void transform (float[] src, int srcOff, float[] dst, int dstOff, int length)
      Transform the array of points according to the values of this AffineTransform object.
      Parameters:
      src - The array of points to be transformed.
      srcOff - The offset of the first point in the array.
      dst - The array of points that will hold the result of the transformation.
      dstOff - The offset of the first point in the destination array.
      length - The number of points to be transformed.
    • transform

      public void transform (float[] src, int srcOff, double[] dst, int dstOff, int length)
      Transform the array of points according to the values of this AffineTransform object.
      Parameters:
      src - The array of points to be transformed.
      srcOff - The offset of the first point in the array.
      dst - The array of points that will hold the result of the transformation.
      dstOff - The offset of the first point in the destination array.
      length - The number of points to be transformed.
    • transform

      public void transform (double[] src, int srcOff, float[] dst, int dstOff, int length)
      Transform the array of points according to the values of this AffineTransform object.
      Parameters:
      src - The array of points to be transformed.
      srcOff - The offset of the first point in the array.
      dst - The array of points that will hold the result of the transformation.
      dstOff - The offset of the first point in the destination array.
      length - The number of points to be transformed.
    • deltaTransform

      public Point deltaTransform (Point src, Point dst)
      Performs the transformation on the source point and stores the result in the destination point.
      Parameters:
      src - The source point to be transformed.
      dst - The destination point that will hold the result of the transformation.
      Returns:
      The modified destination point.
    • deltaTransform

      public void deltaTransform (double[] src, int srcOff, double[] dst, int dstOff, int length)
      Performs the delta transformation on the source array of points and stores the result in the destination array of points.
      Parameters:
      src - The source array of data to be transformed.
      srcOff - The offset of the first point in the source array.
      dst - The destination array of data that will hold the result of the transformation.
      dstOff - The offset of the first point in the destination array.
      length - The number of points to be transformed.
    • inverseTransform

      public Point inverseTransform (Point src, Point dst) throws NoninvertibleTransformException
      Performs the inverse transformation on the source point and stores the result in the destination point.
      Parameters:
      src - The source point to be transformed.
      dst - The destination point that will hold the result of the transformation.
      Returns:
      The modified destination point.
      Throws:
      NoninvertibleTransformException - if the matrix cannot be inverted.
    • inverseTransform

      public void inverseTransform (double[] src, int srcOff, double[] dst, int dstOff, int length) throws NoninvertibleTransformException
      Performs the inverse transformation on the source array of points and stores the result in the destination array of points.
      Parameters:
      src - The source array of data to be transformed.
      srcOff - The offset of the first point in the source array.
      dst - The destination array of data that will hold the result of the transformation.
      dstOff - The offset of the first point in the destination array.
      length - The number of points to be transformed.
      Throws:
      NoninvertibleTransformException - if the matrix cannot be inverted.
    • inverseTransform

      public void inverseTransform (float[] src, int srcOff, float[] dst, int dstOff, int length) throws NoninvertibleTransformException
      Performs the inverse transformation on the source array of points and stores the result in the destination array of points.
      Parameters:
      src - The source array of data to be transformed.
      srcOff - The offset of the first point in the source array.
      dst - The destination array of data that will hold the result of the transformation.
      dstOff - The offset of the first point in the destination array.
      length - The number of points to be transformed.
      Throws:
      NoninvertibleTransformException - if the matrix cannot be inverted.
    • clone

      Creates a "deep copy" of this AffineTransform, meaning the object returned by this method will be independent of the object being cloned.
      Overrides:
      clone in class Object
      Returns:
      the copied AffineTransform.
      Throws:
      CloneNotSupportedException
    • equals

      public boolean equals (Object o)
      Compares this AffineTransform with the specified Object. If the object is the same as this AffineTransform, this method returns true. Otherwise, this method checks if the Object is an instance of AffineTransform and if the values of the two AffineTransforms are equal.
      Overrides:
      equals in class Object
      Parameters:
      o - The object to compare this AffineTransform with.
      Returns:
      true if the object is the same as this AffineTransform, false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for the object.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object.