Class AffineTransforms


  • public class AffineTransforms
    extends Object
    A bunch of static utility methods useful in conjunction with AffineTransforms.
    • Method Detail

      • getXAxisRotation

        public static double getXAxisRotation​(AffineTransform tx)
        Determines the rotation component of the given transformation with respect to the X-axis, i.e. the rotation of any point (excluding the origin) on the X-axis with relative to the origin.
        Parameters:
        tx - the transformation
        Returns:
        the rotation angle in radians
      • getYAxisRotation

        public static double getYAxisRotation​(AffineTransform tx)
        Determines the rotation component of the given transformation with respect to the Y-axis, i.e. the rotation of any point (excluding the origin) on the Y-axis with relative to the origin.
        Parameters:
        tx - the transformation
        Returns:
        the rotation angle in radians
      • getUnitRotation

        public static double getUnitRotation​(AffineTransform tx)
        Determines the rotation component of the given transformation with respect to the unit point (1,1) relative to the origin.
        Parameters:
        tx - the transformation
        Returns:
        the rotation angle in radians
      • getPointRotation

        public static double getPointRotation​(AffineTransform tx,
                                              Point2D p)
        Determines the rotation component of the given transformation with respect to the X-axis, i.e. the rotation of any point (excluding the origin) on the X-axis with relative to the origin.
        Parameters:
        tx - the transformation
        p - the point for which the rotation is determined.
        Returns:
        the rotation angle in radians
      • getNonTranslatingTransform

        public static AffineTransform getNonTranslatingTransform​(AffineTransform t)
        Return the non-translating part of the given transform.
        Parameters:
        t -
        Returns:
        a new AffineTransform excluding the transformation part
      • containsTranslation

        public static boolean containsTranslation​(AffineTransform t)
        Parameters:
        t - the transformation
        Returns:
        whether t contains a translative component
      • createTransformedBounds

        public static Rectangle createTransformedBounds​(AffineTransform tx,
                                                        float x,
                                                        float y,
                                                        float w,
                                                        float h)
        A short-cut method for AffineTransforms.createTransformedBounds(new Rectangle2D.Float(x,y,w,h)). This method will always return a new Rectangle instance.
        Parameters:
        tx - the transformation to apply
        Returns:
        the resulting bounds
      • createTransformedBounds2D

        public static Rectangle2D createTransformedBounds2D​(AffineTransform tx,
                                                            float x,
                                                            float y,
                                                            float w,
                                                            float h)
        A short-cut method for AffineTransforms.createTransformedBounds2D(new Rectangle2D.Float(x,y,w,h)). This method will always return a new Rectangle instance.
        Parameters:
        tx - the transformation to apply
        Returns:
        the resulting bounds
      • immutableTransform

        public static AffineTransform immutableTransform​(AffineTransform tx)
        Create an immutable incarnation of the given transform. All accesses to mutators of the returned transform will throw an UnsupportedOperationException. Changes to the source transform made after the call to this method will not be reflected in the returned transform. Please note: the immutable transform returns mutable versions of itself upon calling AffineTransform.clone(). Therefore the following code is perfectly OK: AffineTransform tx = ...; AffineTransform immutableTx = AffineTransforms.immutableTransform(tx); immutableTx.clone().scale(something, something);
        Parameters:
        tx - the input transform
        Returns:
        an immutable transform with the same characteristics as the input transform
      • getHorizontalFlip

        public static AffineTransform getHorizontalFlip​(double height)
        Creates an AffineTransform which performs a horizontal flipping with the following operations:
        • Translate by the given height
        • Horizontal flipping
        Typically, this can be used to switch from Cartesian to Screen coordinates or vice versa.
        Parameters:
        height - height of the area to be flipped
        Returns:
        an AffineTransform to perform the flipping
      • isInvertible

        public static boolean isInvertible​(AffineTransform affineTransform)
        Determine whether or not a given transformation is invertible. Non-invertible transformations will lead to exceptions when calling AffineTransform.createInverse().
        Parameters:
        affineTransform - the transformation to be considered
        Returns:
        true if the given transformation is invertible, false otherwise.
      • isNeighbor

        public static boolean isNeighbor​(AffineTransform tx1,
                                         AffineTransform tx2,
                                         double epsilon)
        Determine whether or not two given transformations are equal within a certain range epsilon. Necessary because of different rounding in double at different Java VMs.
        Parameters:
        tx1 - the first transformation to be considered
        tx2 - the second transformation to be considered
        epsilon - the maximum tolerated difference for considering the two doubles in the transform equal
        Returns:
        true if the AffineTransforms are considered equal, false otherwise.