Module org.dyn4j

Class Transform

    • Field Detail

      • IDENTITY

        @Deprecated
        public static final Transform IDENTITY
        Deprecated.
        create your own instances of Transform instead; since 3.4.0
        NOTE: as of being deprecated this instance is no longer immutable.
    • Constructor Detail

      • Transform

        public Transform()
        Default public constructor
      • Transform

        public Transform​(Transform transform)
        Public copy constructor constructor
        Parameters:
        transform - the transform to copy
        Since:
        3.4.0
    • Method Detail

      • rotate

        public void rotate​(double theta)
        Description copied from interface: Rotatable
        Rotates the object about the origin.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        theta - the angle of rotation in radians
      • rotate

        public void rotate​(Rotation rotation)
        Description copied from interface: Rotatable
        Rotates the object about the origin.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        rotation - the Rotation representing the rotation amount
      • rotate

        public void rotate​(double theta,
                           double x,
                           double y)
        Description copied from interface: Rotatable
        Rotates the object about the given coordinates.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        theta - the angle of rotation in radians
        x - the x coordinate to rotate about
        y - the y coordinate to rotate about
      • rotate

        public void rotate​(Rotation rotation,
                           double x,
                           double y)
        Description copied from interface: Rotatable
        Rotates the object about the given point.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        rotation - the Rotation representing the rotation amount
        x - the x coordinate to rotate about
        y - the y coordinate to rotate about
      • rotate

        public void rotate​(double theta,
                           Vector2 point)
        Description copied from interface: Rotatable
        Rotates the object about the given point.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        theta - the angle of rotation in radians
        point - the point to rotate about
      • rotate

        public void rotate​(Rotation rotation,
                           Vector2 point)
        Description copied from interface: Rotatable
        Rotates the object about the given point.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        rotation - the Rotation representing the rotation amount
        point - the point to rotate about
      • translate

        public void translate​(double x,
                              double y)
        Description copied from interface: Translatable
        Translates the object the given amounts in the respective directions.
        Specified by:
        translate in interface Translatable
        Parameters:
        x - the translation in the x direction
        y - the translation in the y direction
      • translate

        public void translate​(Vector2 vector)
        Description copied from interface: Translatable
        Translates the object along the given vector.
        Specified by:
        translate in interface Translatable
        Parameters:
        vector - the translation along a vector
      • set

        public void set​(Transform transform)
        Sets this transform to the given transform.
        Parameters:
        transform - the transform to copy
        Since:
        1.1.0
      • identity

        public void identity()
        Sets this Transform to the identity.
      • isIdentity

        public boolean isIdentity()
        Returns true if this Transform is an identity transform.
        Returns:
        boolean
        Since:
        4.0.0
      • getTransformedX

        public double getTransformedX​(Vector2 vector)
        Transforms only the x coordinate of the given Vector2 and returns the result.
        Parameters:
        vector - the Vector2 to transform
        Returns:
        the transformed x coordinate
        Since:
        3.4.0
      • getTransformedY

        public double getTransformedY​(Vector2 vector)
        Transforms only the y coordinate of the given Vector2 and returns the result.
        Parameters:
        vector - the Vector2 to transform
        Returns:
        the transformed y coordinate
        Since:
        3.4.0
      • transformX

        public void transformX​(Vector2 vector)
        Transforms only the x coordinate of the given Vector2 and places the result in the x field of the given Vector2.
        Parameters:
        vector - the Vector2 to transform
        Since:
        3.4.0
      • transformY

        public void transformY​(Vector2 vector)
        Transforms only the y coordinate of the given Vector2 and places the result in the y field of the given Vector2.
        Parameters:
        vector - the Vector2 to transform
        Since:
        3.4.0
      • getTransformed

        public void getTransformed​(Vector2 vector,
                                   Vector2 destination)
        Transforms the given Vector2 and returns the result in dest.
        Parameters:
        vector - the Vector2 to transform
        destination - the Vector2 containing the result
      • transform

        public void transform​(Vector2 vector)
        Transforms the given Vector2 and places the result in the given Vector2.
        Parameters:
        vector - the Vector2 to transform
      • getInverseTransformed

        public Vector2 getInverseTransformed​(Vector2 vector)
        Inverse transforms the given Vector2 and returns a new Vector2 containing the result.
        Parameters:
        vector - the Vector2 to transform
        Returns:
        Vector2
      • getInverseTransformed

        public void getInverseTransformed​(Vector2 vector,
                                          Vector2 destination)
        Inverse transforms the given Vector2 and returns the result in the destination Vector2.
        Parameters:
        vector - the Vector2 to transform
        destination - the Vector2 containing the result
      • inverseTransform

        public void inverseTransform​(Vector2 vector)
        Inverse transforms the given Vector2 and places the result in the given Vector2.
        Parameters:
        vector - the Vector2 to transform
      • getTransformedR

        public Vector2 getTransformedR​(Vector2 vector)
        Transforms the given Vector2 only by the rotation and returns a new Vector2 containing the result.
        Parameters:
        vector - the Vector2 to transform
        Returns:
        Vector2
      • getTransformedR

        public void getTransformedR​(Vector2 vector,
                                    Vector2 destination)
        Transforms the given Vector2 only by the rotation and returns the result in the destination Vector2.
        Parameters:
        vector - the Vector2 to transform
        destination - the Vector2 containing the result
        Since:
        3.1.5
      • transformR

        public void transformR​(Vector2 vector)
        Transforms the given Vector2 only by the rotation and returns the result in the given Vector2.
        Parameters:
        vector - the Vector2 to transform
      • getInverseTransformedR

        public Vector2 getInverseTransformedR​(Vector2 vector)
        Inverse transforms the given Vector2 only by the rotation and returns a new Vector2 containing the result.
        Parameters:
        vector - the Vector2 to transform
        Returns:
        Vector2
      • getInverseTransformedR

        public void getInverseTransformedR​(Vector2 vector,
                                           Vector2 destination)
        Transforms the given Vector2 only by the rotation and returns the result in the destination Vector2.
        Parameters:
        vector - the Vector2 to transform
        destination - the Vector2 containing the result
        Since:
        3.1.5
      • inverseTransformR

        public void inverseTransformR​(Vector2 vector)
        Transforms the given Vector2 only by the rotation and returns the result in the given Vector2.
        Parameters:
        vector - the Vector2 to transform
      • getTranslationX

        public double getTranslationX()
        Returns the x translation.
        Returns:
        double
      • setTranslationX

        public void setTranslationX​(double x)
        Sets the translation along the x axis.
        Parameters:
        x - the translation along the x axis
        Since:
        1.2.0
      • getTranslationY

        public double getTranslationY()
        Returns the x translation.
        Returns:
        double
      • setTranslationY

        public void setTranslationY​(double y)
        Sets the translation along the y axis.
        Parameters:
        y - the translation along the y axis
        Since:
        1.2.0
      • setTranslation

        public void setTranslation​(double x,
                                   double y)
        Sets the translation.
        Parameters:
        x - the translation along the x axis
        y - the translation along the y axis
        Since:
        1.2.0
      • setTranslation

        public void setTranslation​(Vector2 translation)
        Sets the translation.
        Parameters:
        translation - the translation along both axes
        Since:
        1.2.0
      • getRotationAngle

        public double getRotationAngle()
        Returns the rotation.
        Returns:
        double angle in the range [-π, π]
      • getRotation

        public Rotation getRotation()
        Returns:
        the Rotation object representing the rotation of this Transform
        Since:
        3.4.0
      • setRotation

        public double setRotation​(double theta)
        Sets the rotation and returns the previous rotation.
        Parameters:
        theta - the angle in radians
        Returns:
        double the old rotation in radians in the range [-π, π]
        Since:
        3.1.0
      • setRotation

        public Rotation setRotation​(Rotation rotation)
        Sets the rotation and returns the previous rotation.
        Parameters:
        rotation - the Rotation
        Returns:
        A new Rotation object representing the old rotation of this Transform
        Since:
        3.4.0
      • getValues

        public double[] getValues()
        Returns the values stored in this transform.

        The values are in the order of 00, 01, x, 10, 11, y.

        Returns:
        double[]
        Since:
        3.0.1
      • lerp

        public void lerp​(Transform end,
                         double alpha)
        Interpolates this transform linearly by alpha towards the given end transform.

        Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.

        Parameters:
        end - the end transform
        alpha - the amount to interpolate
        Since:
        1.2.0
      • lerp

        public void lerp​(Transform end,
                         double alpha,
                         Transform result)
        Interpolates linearly by alpha towards the given end transform placing the result in the given transform.

        Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.

        Parameters:
        end - the end transform
        alpha - the amount to interpolate
        result - the transform to place the result
        Since:
        1.2.0
      • lerp

        public void lerp​(Vector2 dp,
                         double da,
                         double alpha,
                         Transform result)
        Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and places it into result.
        Parameters:
        dp - the change in position
        da - the change in angle
        alpha - the amount to interpolate
        result - the transform to place the result
        Since:
        3.1.5
      • lerp

        public void lerp​(Vector2 dp,
                         double da,
                         double alpha)
        Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa).
        Parameters:
        dp - the change in position
        da - the change in angle
        alpha - the amount to interpolate
        Since:
        3.1.5
      • lerped

        public Transform lerped​(Vector2 dp,
                                double da,
                                double alpha)
        Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and returns the result.
        Parameters:
        dp - the change in position
        da - the change in angle
        alpha - the amount to interpolate
        Returns:
        Transform
        Since:
        3.1.5
      • lerped

        public Transform lerped​(Transform end,
                                double alpha)
        Interpolates linearly by alpha towards the given end transform returning a new transform containing the result.

        Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.

        Parameters:
        end - the end transform
        alpha - the amount to interpolate
        Returns:
        Transform the resulting transform
        Since:
        1.2.0