Class Rotation2D
- java.lang.Object
-
- org.apache.commons.geometry.euclidean.twod.rotation.Rotation2D
-
- All Implemented Interfaces:
java.util.function.Function<Vector2D,Vector2D>,java.util.function.UnaryOperator<Vector2D>,Transform<Vector2D>,EuclideanTransform<Vector2D>
public final class Rotation2D extends java.lang.Object implements EuclideanTransform<Vector2D>
Class representing a rotation in 2 dimensional Euclidean space. Positive rotations are in a counter-clockwise direction.
-
-
Field Summary
Fields Modifier and Type Field Description private doubleangleThe angle of the rotation in radians.private doublecosAngleThe cosine of the angle of rotation, cached to avoid repeated computation.private static Rotation2DIDENTITYInstance representing a rotation of zero radians.private doublesinAngleThe sine of the angle of rotation, cached to avoid repeated computation.
-
Constructor Summary
Constructors Modifier Constructor Description privateRotation2D(double angle)Create a new instance representing the given angle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector2Dapply(Vector2D pt)Vector2DapplyVector(Vector2D vec)Apply this transform to the given vector, ignoring translations.static Rotation2DcreateVectorRotation(Vector2D u, Vector2D v)Create a rotation instance that rotates the vectoruto point in the direction of vectorv.booleanequals(java.lang.Object obj)doublegetAngle()Get the angle of rotation in radians.inthashCode()static Rotation2Didentity()Return an instance representing the identity rotation, ie a rotation of zero radians.Rotation2Dinverse()Get an instance representing the inverse transform.static Rotation2Dof(double angle)Create a new instance with the given angle of rotation.booleanpreservesOrientation()Return true if the transform preserves the orientation of the space.AffineTransformMatrix2DtoMatrix()Return anAffineTransformMatrix2Drepresenting the same rotation as this instance.java.lang.StringtoString()
-
-
-
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.
-
-
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.
-
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:
preservesOrientationin interfaceTransform<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
vrepresents the difference between pointsp1andp2, thentransform.applyVector(v)will represent the difference betweenp1andp2aftertransformis applied.This method simply calls
apply(vec)since rotations treat points and vectors similarly.- Specified by:
applyVectorin interfaceEuclideanTransform<Vector2D>- Parameters:
vec- the vector to transform- Returns:
- the new, transformed vector
-
toMatrix
public AffineTransformMatrix2D toMatrix()
Return anAffineTransformMatrix2Drepresenting the same rotation as this instance.- Returns:
- a transform matrix representing the same rotation
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.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 vectoruto point in the direction of vectorv.- Parameters:
u- input vectorv- target vector- Returns:
- a rotation instance that rotates
uto point in the direction ofv - Throws:
java.lang.IllegalArgumentException- if either vector cannot be normalized
-
-