Class AffineTransform

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class AffineTransform
    extends java.lang.Object
    implements java.lang.Cloneable

    The AffineTransform class provides methods to create and modify 2-dimensional affine transformations.

    It delegates to the AffineTransform functionality.

    • Constructor Detail

      • AffineTransform

        public AffineTransform()
        Creates a new AffineTransform with its transformation matrix set to the identity matrix.
      • AffineTransform

        public AffineTransform​(double m00,
                               double m10,
                               double m01,
                               double m11,
                               double m02,
                               double m12)
        Creates a new AffineTransform with its transformation matrix set to the specified values. Note that rotation is a combination of shearing and scaling.
        Parameters:
        m00 - the value of the transformation matrix in row 0 and column 0 (x coordinate scaling)
        m10 - the value of the transformation matrix in row 1 and column 0 (y coordinate shearing)
        m01 - the value of the transformation matrix in row 0 and column 1 (x coordinate shearing)
        m11 - the value of the transformation matrix in row 1 and column 1 (y coordinate scaling)
        m02 - the value of the transformation matrix in row 0 and column 2 (x coordinate translation)
        m12 - the value of the transformation matrix in row 1 and column 2 (y coordinate translation)
    • Method Detail

      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • deltaTransform

        public void deltaTransform​(double[] srcPts,
                                   int srcOff,
                                   double[] dstPts,
                                   int dstOff,
                                   int numPts)
        Transforms an array of Points specified by their coordinate values with this AffineTransform without applying the translation components of the transformation matrix of this AffineTransform.
        Parameters:
        srcPts - the array of x and y coordinates specifying the Points that are transformed
        srcOff - the index of the srcPts array where the x coordinate of the first Point to transform is found
        dstPts - the destination array of x and y coordinates for the result of the transformation
        dstOff - the index of the dstPts array where the x coordinate of the first transformed Point is stored
        numPts - the number of Points to transform
      • deltaTransform

        public Point deltaTransform​(Point pt)
        Transforms the given Point with this AffineTransform without applying the translation components of the transformation matrix of this AffineTransform.
        Parameters:
        pt - the Point to transform
        Returns:
        a new, transformed Point
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getDeterminant

        public double getDeterminant()
        Computes the determinant of the transformation matrix of this AffineTransform.
        Returns:
        the determinant of the transformation matrix of this AffineTransform
      • getM00

        public double getM00()
        Returns the matrix component in the first row and first column.
        Returns:
        The matrix component in the first row and first column.
      • getM01

        public double getM01()
        Returns the matrix component in the first row and second column.
        Returns:
        The matrix component in the first row and second column.
      • getM10

        public double getM10()
        Returns the matrix component in the second row and first column.
        Returns:
        The matrix component in the second row and first column.
      • getM11

        public double getM11()
        Returns the matrix component in the second row and second column.
        Returns:
        The matrix component in the second row and second column.
      • getMatrix

        public double[] getMatrix()
        Returns the 6 specifiable elements of the transformation matrix of this AffineTransform.
        Returns:
        the 6 specifiable elements of the transformation matrix of this AffineTransform
      • getScaleX

        public double getScaleX()
        Returns the x coordinate scaling of this AffineTransform's transformation matrix.
        Returns:
        the x coordinate scaling of this AffineTransform's transformation matrix
      • getScaleY

        public double getScaleY()
        Returns the y coordinate scaling of this AffineTransform's transformation matrix.
        Returns:
        the y coordinate scaling of this AffineTransform's transformation matrix
      • getTransformed

        public Point[] getTransformed​(Point[] points)
        Transforms the given array of Points with this AffineTransform by multiplying the transformation matrix of this AffineTransform individually with each of the given Point s.
        Parameters:
        points - array of Points to transform
        Returns:
        an array of new, transformed Points
      • getTranslateX

        public double getTranslateX()
        Returns the x coordinate translation of this AffineTransform's transformation matrix.
        Returns:
        the x coordinate translation of this AffineTransform's transformation matrix
      • getTranslateY

        public double getTranslateY()
        Returns the y coordinate translation of this AffineTransform's transformation matrix.
        Returns:
        the y coordinate translation of this AffineTransform's transformation matrix
      • getType

        public int getType()
        Returns the type of transformation represented by this AffineTransform. See the AffineTransform.getType() method for a specification of the return type of this method.
        Returns:
        the type of transformation represented by this AffineTransform
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • inverseTransform

        public void inverseTransform​(double[] srcPts,
                                     int srcOff,
                                     double[] dstPts,
                                     int dstOff,
                                     int numPts)
                              throws java.awt.geom.NoninvertibleTransformException
        Inverse transforms an array of Points specified by their coordinate values with this AffineTransform.
        Parameters:
        srcPts - the array of x and y coordinates specifying the Points that are inverse transformed
        srcOff - the index of the srcPts array where the x coordinate of the first Point to inverse transform is found
        dstPts - the destination array of x and y coordinates for the result of the inverse transformation
        dstOff - the index of the dstPts array where the x coordinate of the first inverse transformed Point is stored
        numPts - the number of Points to inverse transform
        Throws:
        java.awt.geom.NoninvertibleTransformException - when this AffineTransform is not invertible.
      • inverseTransform

        public Point inverseTransform​(Point pt)
                               throws java.awt.geom.NoninvertibleTransformException
        Inverse transforms the given Point with this AffineTransform.
        Parameters:
        pt - the Point to inverse transform
        Returns:
        a new, inverse transformed Point
        Throws:
        java.awt.geom.NoninvertibleTransformException - when this AffineTransform is not invertible.
      • invert

        public AffineTransform invert()
                               throws java.awt.geom.NoninvertibleTransformException
        Inverts this AffineTransform.
        Returns:
        this for convenience
        Throws:
        java.awt.geom.NoninvertibleTransformException - when this AffineTransform is not invertible.
      • isIdentity

        public boolean isIdentity()
        Checks if the transformation matrix of this AffineTransform equals the identity matrix.
        Returns:
        true if the transformation matrix of this AffineTransform equals the identity matrix, otherwise false
      • quadrantRotate

        public AffineTransform quadrantRotate​(int numquadrants)
        Adds a rotation by an integer multiple of 90deg to the transformation matrix of this AffineTransform. The integer multiple of 90deg is specified by the given number of quadrants.
        Parameters:
        numquadrants - the integer that defines the number of quadrants to rotate by
        Returns:
        this for convenience
      • quadrantRotate

        public AffineTransform quadrantRotate​(int numquadrants,
                                              double anchorx,
                                              double anchory)
        Adds a rotation by an integer multiple of 90deg around the Point specified by the given x and y coordinates to the transformation matrix of this AffineTransform.
        Parameters:
        numquadrants - the integer that defines the number of quadrants to rotate by
        anchorx - the x coordinate of the Point to rotate around
        anchory - the y coordinate of the Point to rotate around
        Returns:
        this for convenience
      • rotate

        public AffineTransform rotate​(double theta)
        Adds a rotation with the given angle (in radians) to the transformation matrix of this AffineTransform.
        Parameters:
        theta - the rotation angle in radians
        Returns:
        this for convenience
      • rotate

        public AffineTransform rotate​(double vecx,
                                      double vecy)
        Adds a rotation to the transformation matrix of this AffineTransform. The given coordinates specify a Vector whose Angle to the x-axis is the applied rotation Angle.
        Parameters:
        vecx - the x coordinate of the Vector specifying the rotation Angle
        vecy - the y coordinate of the Vector specifying the rotation Angle
        Returns:
        this for convenience
      • rotate

        public AffineTransform rotate​(double theta,
                                      double anchorx,
                                      double anchory)
        Adds a rotation with the given angle (in radians) around the Point specified by the given x and y coordinates to the transformation matrix of this AffineTransform.
        Parameters:
        theta - the rotation angle in radians
        anchorx - the x coordinate of the Point to rotate around
        anchory - the y coordinate of the Point to rotate around
        Returns:
        this for convenience
      • rotate

        public AffineTransform rotate​(double vecx,
                                      double vecy,
                                      double anchorx,
                                      double anchory)
        Adds a rotation around a Point to the transformation matrix of this AffineTransform. The given coordinates specify a Vector whose Angle to the x-axis is the applied rotation Angle and the anchor Point for the rotation.
        Parameters:
        vecx - the x coordinate of the Vector specifying the rotation Angle
        vecy - the y coordinate of the Vector specifying the rotation Angle
        anchorx - the x coordinate of the Point to rotate around
        anchory - the y coordinate of the Point to rotate around
        Returns:
        this for convenience
      • scale

        public AffineTransform scale​(double sx,
                                     double sy)
        Adds an x and y scaling to the transformation matrix of this AffineTransform.
        Parameters:
        sx - the x scaling factor added to the transformation matrix of this AffineTransform
        sy - the y scaling factor added to the transformation matrix of this AffineTransform
        Returns:
        this for convenience
      • setToIdentity

        public AffineTransform setToIdentity()
        Sets the transformation matrix of this AffineTransform to the identity matrix.
        Returns:
        this for convenience
      • setToQuadrantRotation

        public AffineTransform setToQuadrantRotation​(int numquadrants)
        Sets the transformation matrix of this AffineTransform to a pure rotation matrix where the rotation angle is an integer multiple of 90deg.
        Parameters:
        numquadrants - the integer that defines the number of quadrants to rotate by
        Returns:
        this for convenience
      • setToQuadrantRotation

        public AffineTransform setToQuadrantRotation​(int numquadrants,
                                                     double anchorx,
                                                     double anchory)
        Sets the transformation matrix of this AffineTransform to a pure rotation and translation matrix where the rotation angle is an integer multiple of 90deg and the rotation is around the Point specified by the given x and y coordinates.
        Parameters:
        numquadrants - the integer that defines the number of quadrants to rotate by
        anchorx - the x coordinate of the Point to rotate around
        anchory - the y coordinate of the Point to rotate around
        Returns:
        this for convenience
      • setToRotation

        public AffineTransform setToRotation​(double theta)
        Sets the transformation matrix of this AffineTransform to a pure rotation matrix by the given angle specified in radians.
        Parameters:
        theta - the rotation angle (in radians)
        Returns:
        this for convenience
      • setToRotation

        public AffineTransform setToRotation​(double vecx,
                                             double vecy)
        Sets the transformation matrix of this AffineTransform to a pure rotation matrix. The given x and y coordinates specify a Vector whose Angle to the x-axis defines the rotation Angle.
        Parameters:
        vecx - the x coordinate of the Vector whose Angle to the x-axis defines the rotation Angle
        vecy - the y coordinate of the Vector whose Angle to the x-axis defines the rotation Angle
        Returns:
        this for convenience
      • setToRotation

        public AffineTransform setToRotation​(double theta,
                                             double anchorx,
                                             double anchory)
        Sets the transformation matrix of this AffineTransform to a pure rotation and translation matrix. Thus, the resulting transformation matrix rotates Points by the given angle (in radians) around the Point specified by the given x and y coordinates.
        Parameters:
        theta - the rotation angle (in radians)
        anchorx - the x coordinate of the Point to rotate around
        anchory - the y coordinate of the Point to rotate around
        Returns:
        this for convenience
      • setToRotation

        public AffineTransform setToRotation​(double vecx,
                                             double vecy,
                                             double anchorx,
                                             double anchory)
        Sets the transformation matrix of this AffineTransform to a pure rotation and translation matrix. The firstly given x and y coordinates specify a Vector whose Angle to the x-axis defines the rotation Angle. The secondly given x and y coordinates specify the Point to rotate around.
        Parameters:
        vecx - the x coordinate of the Vector whose Angle to the x-axis defines the rotation Angle
        vecy - the y coordinate of the Vector whose Angle to the x-axis defines the rotation Angle
        anchorx - the x coordinate of the Point to rotate around
        anchory - the y coordinate of the Point to rotate around
        Returns:
        this for convenience
      • setToScale

        public AffineTransform setToScale​(double sx,
                                          double sy)
        Sets the transformation matrix of this AffineTransform to a pure scaling matrix.
        Parameters:
        sx - the x scaling factor
        sy - the y scaling factor
        Returns:
        this for convenience
      • setToShear

        public AffineTransform setToShear​(double shx,
                                          double shy)
        Sets the transformation matrix of this AffineTransform to a pure shearing matrix.
        Parameters:
        shx - the x shearing factor
        shy - the y shearing factor
        Returns:
        this for convenience
      • setToTranslation

        public AffineTransform setToTranslation​(double tx,
                                                double ty)
        Sets the transformation matrix of this AffineTransform to a pure translation matrix that translates Points by the given x and y values.
        Parameters:
        tx - the x translation value
        ty - the y translation value
        Returns:
        this for convenience
      • setTransform

        public AffineTransform setTransform​(double m00,
                                            double m10,
                                            double m01,
                                            double m11,
                                            double m02,
                                            double m12)
        Sets the respective values of the transformation matrix of this AffineTransform to the supplied ones. Note that rotation is a combination of shearing and scaling.
        Parameters:
        m00 - the value of the transformation matrix in row 0 and column 0 (x coordinate scaling)
        m10 - the value of the transformation matrix in row 1 and column 0 (y coordinate shearing)
        m01 - the value of the transformation matrix in row 0 and column 1 (x coordinate shearing)
        m11 - the value of the transformation matrix in row 1 and column 1 (y coordinate scaling)
        m02 - the value of the transformation matrix in row 0 and column 2 (x coordinate translation)
        m12 - the value of the transformation matrix in row 1 and column 2 (y coordinate translation)
        Returns:
        this for convenience
      • shear

        public AffineTransform shear​(double shx,
                                     double shy)
        Adds an x and y shearing to the transformation matrix of this AffineTransform.
        Parameters:
        shx - the x shearing factor added to the transformation matrix of this AffineTransform
        shy - the y shearing factor added to the transformation matrix of this AffineTransform
        Returns:
        this for convenience
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • translate

        public AffineTransform translate​(double tx,
                                         double ty)
        Sets the translation values of the x and y coordinates of the transformation matrix of this AffineTransform.
        Parameters:
        tx - the x coordinate translation
        ty - the y coordinate translation
        Returns:
        this for convenience