Class Rotation2D

java.lang.Object
com.irurueta.geometry.Rotation2D
All Implemented Interfaces:
Serializable

public class Rotation2D extends Object implements Serializable
This class defines the amount of rotation for 2D points or lines.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Default threshold to determine if two instances are equal.
    static final double
    Constant defining threshold to determine whether a matrix is orthogonal or not and has determinant equal to 1.
    static final double
    Constant defining minimum allowed comparison threshold.
    static final double
    Constant defining minimum allowed threshold.
    static final int
    Constant defining the number of columns on a 2D rotation matrix expressed in homogeneous coordinates.
    static final int
    Constant defining the number of rows on a 2D rotation matrix expressed in homogeneous coordinates.
    static final int
    Constant defining the number of columns on a 2D rotation matrix expressed in inhomogeneous coordinates.
    static final int
    Constant defining the number of rows on a 2D rotation matrix expressed in inhomogeneous coordinates.
    private double
    Private member containing amount of rotation expressed in radians.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty Constructor.
    Rotation2D(double theta)
    Constructor.
    Rotation2D(com.irurueta.algebra.Matrix m)
    Constructor.
    Rotation2D(com.irurueta.algebra.Matrix m, double threshold)
    Constructor.
    Copy constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.irurueta.algebra.Matrix
    Returns this 2D rotation instance expressed as a 3x3 homogeneous matrix.
    void
    asHomogeneousMatrix(com.irurueta.algebra.Matrix result)
    Sets into provided Matrix instance this 2D rotation expressed as a 3x3 homogeneous matrix.
    com.irurueta.algebra.Matrix
    Returns this 2D rotation instance expressed as a 2x2 inhomogeneous matrix.
    void
    asInhomogeneousMatrix(com.irurueta.algebra.Matrix result)
    Sets into provided Matrix instance this 2D rotation expressed as a 2x2 inhomogeneous matrix.
    void
    combine(Rotation2D rotation)
    Combines provided rotation into this rotation resulting in the sum of both rotations.
    static void
    combine(Rotation2D rot1, Rotation2D rot2, Rotation2D result)
    Combines the rotation of instances rot1 and rot1 into provided result instance.
    Combines provided rotation with this rotation and returns the result as a new Rotation2D instance.
    boolean
    Determines if two Rotation2D instances are equal or not (i.e. have the same rotation).
    boolean
    equals(Rotation2D other, double threshold)
    Determines if two Rotation2D instances are equal up to provided threshold or not (i.e. have the same rotation).
    boolean
    Determines if two Rotation2D instances are equal or not (i.e. have the same rotation).
    void
    fromHomogeneousMatrix(com.irurueta.algebra.Matrix m)
    Sets amount of rotation from provided homogeneous rotation matrix.
    void
    fromHomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold)
    Sets amount of rotation from provided homogeneous rotation matrix.
    void
    fromInhomogeneousMatrix(com.irurueta.algebra.Matrix m)
    Sets amount of rotation from provided inhomogeneous rotation matrix.
    void
    fromInhomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold)
    Sets amount of rotation from provided inhomogeneous rotation matrix.
    final void
    fromMatrix(com.irurueta.algebra.Matrix m)
    Sets amount of rotation from provided rotation matrix.
    final void
    fromMatrix(com.irurueta.algebra.Matrix m, double threshold)
    Sets amount of rotation from provided rotation matrix.
    double
    Returns rotation amount expressed in radians.
    int
    Hash code to compare instances.
    Returns a 2D rotation which is inverse to this instance.
    void
    Sets into provided Rotation2D instance a rotation inverse to this instance.
    static boolean
    isValidRotationMatrix(com.irurueta.algebra.Matrix m)
    Returns boolean indicating whether provided matrix is a valid matrix for a rotation.
    static boolean
    isValidRotationMatrix(com.irurueta.algebra.Matrix m, double threshold)
    Returns boolean indicating whether provided matrix is a valid matrix for a rotation.
    rotate(Line2D line)
    Returns a line containing a rotated version of provided line.
    void
    rotate(Line2D inputLine, Line2D resultLine)
    Rotates a line using the origin of coordinates as the axis of rotation.
    rotate(Point2D point)
    Returns a 2D point containing a rotated version of provided point.
    void
    rotate(Point2D inputPoint, Point2D resultPoint)
    Rotates a 2D point using the origin of coordinates as the axis of rotation.
    void
    setTheta(double theta)
    Sets rotation amount expressed in radians.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ROTATION2D_INHOM_MATRIX_ROWS

      public static final int ROTATION2D_INHOM_MATRIX_ROWS
      Constant defining the number of rows on a 2D rotation matrix expressed in inhomogeneous coordinates.
      See Also:
    • ROTATION2D_INHOM_MATRIX_COLS

      public static final int ROTATION2D_INHOM_MATRIX_COLS
      Constant defining the number of columns on a 2D rotation matrix expressed in inhomogeneous coordinates.
      See Also:
    • ROTATION2D_HOM_MATRIX_ROWS

      public static final int ROTATION2D_HOM_MATRIX_ROWS
      Constant defining the number of rows on a 2D rotation matrix expressed in homogeneous coordinates.
      See Also:
    • ROTATION2D_HOM_MATRIX_COLS

      public static final int ROTATION2D_HOM_MATRIX_COLS
      Constant defining the number of columns on a 2D rotation matrix expressed in homogeneous coordinates.
      See Also:
    • MATRIX_VALID_THRESHOLD

      public static final double MATRIX_VALID_THRESHOLD
      Constant defining threshold to determine whether a matrix is orthogonal or not and has determinant equal to 1. Rotation matrices must fulfill those requirements.
      See Also:
    • MIN_THRESHOLD

      public static final double MIN_THRESHOLD
      Constant defining minimum allowed threshold.
      See Also:
    • DEFAULT_COMPARISON_THRESHOLD

      public static final double DEFAULT_COMPARISON_THRESHOLD
      Default threshold to determine if two instances are equal.
      See Also:
    • MIN_COMPARISON_THRESHOLD

      public static final double MIN_COMPARISON_THRESHOLD
      Constant defining minimum allowed comparison threshold.
      See Also:
    • theta

      private double theta
      Private member containing amount of rotation expressed in radians.
  • Constructor Details

    • Rotation2D

      public Rotation2D()
      Empty Constructor. Initializes rotation to zero radians.
    • Rotation2D

      public Rotation2D(Rotation2D rotation)
      Copy constructor. Copies provided rotation into this instance.
      Parameters:
      rotation - Instance to be copied.
    • Rotation2D

      public Rotation2D(com.irurueta.algebra.Matrix m) throws InvalidRotationMatrixException
      Constructor. Creates a 2D rotation using provided matrix. Provided matrix can be expressed in either homogeneous or inhomogeneous coordinates, and it must also be orthogonal and having determinant equal to 1. The threshold to determine whether provided matrix is orthonormal will be MATRIX_VALID_THRESHOLD.
      Parameters:
      m - Matrix to create rotation from.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (its size is wrong, or it is not orthonormal).
      See Also:
    • Rotation2D

      public Rotation2D(com.irurueta.algebra.Matrix m, double threshold) throws InvalidRotationMatrixException
      Constructor. Creates a 2D rotation using provided matrix. Provided matrix can be expressed in either homogeneous or inhomogeneous coordinates, and it must also be orthogonal up to provided threshold, and must have determinant equal to 1.
      Parameters:
      m - Matrix to create rotation from.
      threshold - Threshold to determine whether matrix is orthonormal.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (its size is wrong, or it is not orthonormal).
      IllegalArgumentException - Raised if provided threshold is negative
      See Also:
    • Rotation2D

      public Rotation2D(double theta)
      Constructor. Creates a 2D rotation using provided rotation value expressed in radians
      Parameters:
      theta - Rotation amount expressed in radians.
  • Method Details

    • getTheta

      public double getTheta()
      Returns rotation amount expressed in radians.
      Returns:
      Rotation amount expressed in radians.
    • setTheta

      public void setTheta(double theta)
      Sets rotation amount expressed in radians.
      Parameters:
      theta - rotation angle.
    • inverseRotation

      public Rotation2D inverseRotation()
      Returns a 2D rotation which is inverse to this instance. In other words, the combination of this rotation with its inverse produces no change.
      Returns:
      Inverse 2D rotation.
    • inverseRotation

      public void inverseRotation(Rotation2D result)
      Sets into provided Rotation2D instance a rotation inverse to this instance. The combination of this rotation with its inverse produces no change.
      Parameters:
      result - Instance where inverse rotation will be set.
    • asInhomogeneousMatrix

      public com.irurueta.algebra.Matrix asInhomogeneousMatrix()
      Returns this 2D rotation instance expressed as a 2x2 inhomogeneous matrix.
      Returns:
      Rotation matrix expressed in inhomogeneous coordinates.
    • asInhomogeneousMatrix

      public void asInhomogeneousMatrix(com.irurueta.algebra.Matrix result)
      Sets into provided Matrix instance this 2D rotation expressed as a 2x2 inhomogeneous matrix.
      Parameters:
      result - Matrix where rotation will be set.
      Throws:
      IllegalArgumentException - Raised if provided instance does not have size 2x2.
    • asHomogeneousMatrix

      public com.irurueta.algebra.Matrix asHomogeneousMatrix()
      Returns this 2D rotation instance expressed as a 3x3 homogeneous matrix.
      Returns:
      Rotation matrix expressed in homogeneous coordinates.
    • asHomogeneousMatrix

      public void asHomogeneousMatrix(com.irurueta.algebra.Matrix result)
      Sets into provided Matrix instance this 2D rotation expressed as a 3x3 homogeneous matrix.
      Parameters:
      result - Matrix where rotation will be set.
      Throws:
      IllegalArgumentException - Raised if provided instance does not have size 3x3.
    • fromMatrix

      public final void fromMatrix(com.irurueta.algebra.Matrix m, double threshold) throws InvalidRotationMatrixException
      Sets amount of rotation from provided rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix can be expressed in either inhomogeneous (2x2) or homogeneous (3x3) coordinates.
      Parameters:
      m - Provided rotation matrix.
      threshold - Threshold to determine whether matrix is orthonormal.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (has wrong size, or it is not orthonormal).
      IllegalArgumentException - Raised if provided threshold is negative
      See Also:
    • fromMatrix

      public final void fromMatrix(com.irurueta.algebra.Matrix m) throws InvalidRotationMatrixException
      Sets amount of rotation from provided rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix can be expressed in either inhomogeneous (2x2) or homogeneous (3x3) coordinates. Because threshold is not provided it is used MATRIX_VALID_THRESHOLD instead.
      Parameters:
      m - Provided rotation matrix.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (has wrong size, or it is not orthonormal).
      See Also:
    • fromInhomogeneousMatrix

      public void fromInhomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold) throws InvalidRotationMatrixException
      Sets amount of rotation from provided inhomogeneous rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix must also have size 2x2.
      Parameters:
      m - Provided rotation matrix.
      threshold - Threshold to determine whether matrix is orthonormal.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (has wrong size, or it is not orthonormal).
      IllegalArgumentException - Raised if provided threshold is negative.
      See Also:
    • fromInhomogeneousMatrix

      public void fromInhomogeneousMatrix(com.irurueta.algebra.Matrix m) throws InvalidRotationMatrixException
      Sets amount of rotation from provided inhomogeneous rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix must also have size 2x2. Because threshold is not provided it is used MATRIX_VALID_THRESHOLD instead.
      Parameters:
      m - Provided rotation matrix.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (has wrong size, or it is not orthonormal).
      See Also:
    • fromHomogeneousMatrix

      public void fromHomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold) throws InvalidRotationMatrixException
      Sets amount of rotation from provided homogeneous rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix must also have size 3x3, and its last row and column must be zero, except for element in last row and column which must be 1.
      Parameters:
      m - Provided rotation matrix.
      threshold - Threshold to determine whether matrix is orthonormal.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (has wrong size, or it is not orthonormal).
      IllegalArgumentException - Raised if provided threshold is negative.
      See Also:
    • fromHomogeneousMatrix

      public void fromHomogeneousMatrix(com.irurueta.algebra.Matrix m) throws InvalidRotationMatrixException
      Sets amount of rotation from provided homogeneous rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular), its transpose must be its inverse and must have determinant equal to 1. Provided matrix must also have size 3x3, and its last row and column must be zero, except for element in last row and column which must be 1 Because threshold is not provided it is used MATRIX_VALID_THRESHOLD instead.
      Parameters:
      m - Provided rotation matrix.
      Throws:
      InvalidRotationMatrixException - Raised if provided matrix is not valid (has wrong size, or it is not orthonormal).
      See Also:
    • rotate

      public void rotate(Point2D inputPoint, Point2D resultPoint)
      Rotates a 2D point using the origin of coordinates as the axis of rotation. Point will be rotated by the amount of rotation contained in this instance.
      Parameters:
      inputPoint - Input point to be rotated.
      resultPoint - Rotated point.
    • rotate

      public Point2D rotate(Point2D point)
      Returns a 2D point containing a rotated version of provided point. Point will be rotated using the origin of the coordinates as the axis of rotation. Point will be rotated by the amount of rotation contained in this instance.
      Parameters:
      point - Point to be rotated.
      Returns:
      Rotated point.
    • rotate

      public void rotate(Line2D inputLine, Line2D resultLine)
      Rotates a line using the origin of coordinates as the axis of rotation. Line2D will be rotated by the amount of rotation contained in this instance.
      Parameters:
      inputLine - Input line to be rotated.
      resultLine - Rotated line.
    • rotate

      public Line2D rotate(Line2D line)
      Returns a line containing a rotated version of provided line. Line2D will be rotated using the origin of the coordinates as the axis of rotation. Line2D will be rotated by the amount of rotation contained in this instance.
      Parameters:
      line - Line2D to be rotated.
      Returns:
      Rotated line.
    • isValidRotationMatrix

      public static boolean isValidRotationMatrix(com.irurueta.algebra.Matrix m, double threshold)
      Returns boolean indicating whether provided matrix is a valid matrix for a rotation. Rotation matrices must be orthogonal and must have determinant equal to 1.
      Parameters:
      m - Input matrix to be checked.
      threshold - Threshold to determine whether matrix is orthogonal and whether determinant is one.
      Returns:
      True if matrix is valid, false otherwise.
      Throws:
      IllegalArgumentException - Raised if provided threshold is negative.
    • isValidRotationMatrix

      public static boolean isValidRotationMatrix(com.irurueta.algebra.Matrix m)
      Returns boolean indicating whether provided matrix is a valid matrix for a rotation. Rotation matrices must be orthogonal and must have determinant equal to 1 Because threshold is not provided, it is used MATRIX_VALID_THRESHOLD instead.
      Parameters:
      m - Input matrix to be checked.
      Returns:
      True if matrix is valid, false otherwise.
      Throws:
      IllegalArgumentException - Raised if provided threshold is negative.
    • combineAndReturnNew

      public Rotation2D combineAndReturnNew(Rotation2D rotation)
      Combines provided rotation with this rotation and returns the result as a new Rotation2D instance.
      Parameters:
      rotation - Input rotation to be combined.
      Returns:
      Combined rotation, which is equal to the sum of provided rotation with this rotation.
    • combine

      public void combine(Rotation2D rotation)
      Combines provided rotation into this rotation resulting in the sum of both rotations.
      Parameters:
      rotation - Input rotation to be combined.
    • combine

      public static void combine(Rotation2D rot1, Rotation2D rot2, Rotation2D result)
      Combines the rotation of instances rot1 and rot1 into provided result instance.
      Parameters:
      rot1 - 1st input rotation.
      rot2 - 2nd input rotation.
      result - Combined rotation, which is equal to the sum of provided input rotations.
    • equals

      public boolean equals(Rotation2D other, double threshold)
      Determines if two Rotation2D instances are equal up to provided threshold or not (i.e. have the same rotation).
      Parameters:
      other - other rotation to compare.
      threshold - threshold to determine if they are equal.
      Returns:
      true if they are equal, false otherwise.
      Throws:
      IllegalArgumentException - if threshold is negative.
    • equals

      public boolean equals(Rotation2D other)
      Determines if two Rotation2D instances are equal or not (i.e. have the same rotation).
      Parameters:
      other - other object to compare.
      Returns:
      true if they are equal, false otherwise.
    • equals

      public boolean equals(Object obj)
      Determines if two Rotation2D instances are equal or not (i.e. have the same rotation).
      Overrides:
      equals in class Object
      Parameters:
      obj - other object to compare.
      Returns:
      true if they are equal, false otherwise.
    • hashCode

      public int hashCode()
      Hash code to compare instances.
      Overrides:
      hashCode in class Object
      Returns:
      hash code to compare instances.