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 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector2D
apply(Vector2D pt)
Vector2D
applyVector(Vector2D vec)
Apply this transform to the given vector, ignoring translations.static Rotation2D
createVectorRotation(Vector2D u, Vector2D v)
Create a rotation instance that rotates the vectoru
to point in the direction of vectorv
.boolean
equals(java.lang.Object obj)
double
getAngle()
Get the angle of rotation in radians.int
hashCode()
static Rotation2D
identity()
Return an instance representing the identity rotation, ie a rotation of zero radians.Rotation2D
inverse()
Get an instance representing the inverse transform.static Rotation2D
of(double angle)
Create a new instance with the given angle of rotation.boolean
preservesOrientation()
Return true if the transform preserves the orientation of the space.AffineTransformMatrix2D
toMatrix()
Return anAffineTransformMatrix2D
representing the same rotation as this instance.java.lang.String
toString()
-
-
-
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:
preservesOrientation
in 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
v
represents the difference between pointsp1
andp2
, thentransform.applyVector(v)
will represent the difference betweenp1
andp2
aftertransform
is applied.This method simply calls
apply(vec)
since rotations treat points and vectors similarly.- Specified by:
applyVector
in interfaceEuclideanTransform<Vector2D>
- Parameters:
vec
- the vector to transform- Returns:
- the new, transformed vector
-
toMatrix
public AffineTransformMatrix2D toMatrix()
Return anAffineTransformMatrix2D
representing the same rotation as this instance.- Returns:
- a transform matrix representing the same rotation
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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 vectoru
to point in the direction of vectorv
.- Parameters:
u
- input vectorv
- target vector- Returns:
- a rotation instance that rotates
u
to point in the direction ofv
- Throws:
java.lang.IllegalArgumentException
- if either vector cannot be normalized
-
-