Class Rotation2D

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double angle
      The angle of the rotation in radians.
      private double cosAngle
      The cosine of the angle of rotation, cached to avoid repeated computation.
      private static Rotation2D IDENTITY
      Instance representing a rotation of zero radians.
      private double sinAngle
      The sine of the angle of rotation, cached to avoid repeated computation.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Rotation2D​(double angle)
      Create a new instance representing the given angle.
    • Field Detail

      • IDENTITY

        private static final Rotation2D IDENTITY
        Instance representing a rotation of zero radians.
      • angle

        private final double angle
        The angle of the rotation in radians.
      • cosAngle

        private final double cosAngle
        The cosine of the angle of rotation, cached to avoid repeated computation.
      • sinAngle

        private final double sinAngle
        The sine of the angle of rotation, cached to avoid repeated computation.
    • Constructor Detail

      • Rotation2D

        private Rotation2D​(double angle)
        Create a new instance representing the given angle.
        Parameters:
        angle - the angle of rotation, in radians
    • Method Detail

      • getAngle

        public double getAngle()
        Get the angle of rotation in radians.
        Returns:
        the angle of rotation in radians
      • inverse

        public Rotation2D inverse()
        Get an instance representing the inverse transform.
        Specified by:
        inverse in interface Transform<Vector2D>
        Returns:
        an instance representing the inverse transform
      • preservesOrientation

        public boolean preservesOrientation()
        Return true if the transform preserves the orientation of the space. For example, in Euclidean 2D space, this will be true for translations, rotations, and scalings but will be false for reflections.

        This method simply returns true since rotations always preserve the orientation of the space.

        Specified by:
        preservesOrientation in interface Transform<Vector2D>
        Returns:
        true if the transform preserves the orientation of the space
        See Also:
        Orientation
      • applyVector

        public Vector2D applyVector​(Vector2D vec)
        Apply this transform to the given vector, ignoring translations.

        This method can be used to transform vector instances representing displacements between points. For example, if v represents the difference between points p1 and p2, then transform.applyVector(v) will represent the difference between p1 and p2 after transform is applied.

        This method simply calls apply(vec) since rotations treat points and vectors similarly.

        Specified by:
        applyVector in interface EuclideanTransform<Vector2D>
        Parameters:
        vec - the vector to transform
        Returns:
        the new, transformed vector
      • hashCode

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

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

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

        public static Rotation2D of​(double angle)
        Create a new instance with the given angle of rotation.
        Parameters:
        angle - the angle of rotation in radians
        Returns:
        a new instance with the given angle of rotation
      • identity

        public static Rotation2D identity()
        Return an instance representing the identity rotation, ie a rotation of zero radians.
        Returns:
        an instance representing a rotation of zero radians
      • createVectorRotation

        public static Rotation2D createVectorRotation​(Vector2D u,
                                                      Vector2D v)
        Create a rotation instance that rotates the vector u to point in the direction of vector v.
        Parameters:
        u - input vector
        v - target vector
        Returns:
        a rotation instance that rotates u to point in the direction of v
        Throws:
        java.lang.IllegalArgumentException - if either vector cannot be normalized