Class TransformUtils



  • public class TransformUtils
    extends Object
    This is a collection of methods that deal with AffineTransforms. Note the PerspectiveTransform class already has static methods that perform similar functions.
    • Constructor Detail

      • TransformUtils

        public TransformUtils()
    • Method Detail

      • getRotationAngle

        public static double getRotationAngle(AffineTransform transform)
        Compute the rotation angle of an affine transformation. Counter-clockwise rotation is considered positive.
        Parameters:
        transform - the AffineTransform to analyze.
        Returns:
        rotation angle in radians (beween -pi and pi), or NaN if the transformation is bogus.
      • createAffineTransform

        public static AffineTransform createAffineTransform(Point2D initialP1,
                                                            Point2D initialP2,
                                                            Point2D initialP3,
                                                            Point2D finalP1,
                                                            Point2D finalP2,
                                                            Point2D finalP3)
        Given 3 points, this will return the AffineTransform that links each initial to final point.

        This uses the solve(matrix,true) method.

        Parameters:
        initialP1 - the point that transforms into finalP1
        initialP2 - the point that transforms into finalP2
        initialP3 - the point that transforms into finalP3
        finalP1 - the point that originated at initialP1
        finalP2 - the point that originated at initialP2
        finalP3 - the point that originated at initialP3
        Returns:
        an AffineTransform that maps from the initial points to the final points.
      • createAffineTransform

        public static AffineTransform createAffineTransform(Rectangle2D r1,
                                                            Rectangle2D r2)
        This will return the AffineTransform that maps one rectangle onto another.

        This uses the solve(matrix,true) method.

        Parameters:
        r1 - the rectangle that transforms into r2
        r2 - the rectangle that originated at r1
        Returns:
        an AffineTransform that maps from the initial rectangle to the final rectangle.
      • createAffineTransform

        public static AffineTransform createAffineTransform(double oldX1,
                                                            double oldY1,
                                                            double oldX2,
                                                            double oldY2,
                                                            double oldX3,
                                                            double oldY3,
                                                            double newX1,
                                                            double newY1,
                                                            double newX2,
                                                            double newY2,
                                                            double newX3,
                                                            double newY3)
        Given 3 points, this will return the AffineTransform that links each initial to final point.

        This uses the solve(matrix,true) method.

        Parameters:
        oldX1 - the x-coordinate of the untransformed first point
        oldY1 - the y-coordinate of the untransformed first point
        oldX2 - the x-coordinate of the untransformed second point
        oldY2 - the y-coordinate of the untransformed second point
        oldX3 - the x-coordinate of the untransformed third point
        oldY3 - the y-coordinate of the untransformed third point
        newX1 - the x-coordinate of the transformed first point
        newY1 - the y-coordinate of the transformed first point
        newX2 - the x-coordinate of the transformed second point
        newY2 - the y-coordinate of the transformed second point
        newX3 - the x-coordinate of the transformed third point
        newY3 - the y-coordinate of the transformed third point
        Returns:
        an AffineTransform that maps from the initial points to the final points.
      • tween

        public static AffineTransform tween(AffineTransform a,
                                            AffineTransform b,
                                            float progress,
                                            boolean createNewObject)
        Transitions from one AffineTransform to another.
        Parameters:
        a - the initial AffineTransform
        b - the final AffineTransform
        progress - a float between zero and one, where zero represents a and one represents b. Values outside this range will not throw an exception, but they will make some funky results.
        createNewObject - indicates whether a new AffineTransform should be constructed, or if one of the arguments can be used to store the results
        Returns:
        a transform that is somehow between a and b.