Class Rotation2D

java.lang.Object
org.apache.commons.geometry.euclidean.twod.rotation.Rotation2D
All Implemented Interfaces:
Function<Vector2D,Vector2D>, UnaryOperator<Vector2D>, Transform<Vector2D>, EuclideanTransform<Vector2D>

public final class Rotation2D extends Object implements EuclideanTransform<Vector2D>
Class representing a rotation in 2 dimensional Euclidean space. Positive rotations are in a counter-clockwise direction.
  • Method Details

    • 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:
    • apply

      public Vector2D apply(Vector2D pt)
      Specified by:
      apply in interface Function<Vector2D,Vector2D>
    • applyVector

      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
    • toMatrix

      Return an AffineTransformMatrix2D representing the same rotation as this instance.
      Returns:
      a transform matrix representing the same rotation
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class 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

      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:
      IllegalArgumentException - if either vector cannot be normalized