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>
Class representing a rotation in 2 dimensional Euclidean space. Positive
rotations are in a counter-clockwise direction.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double
The angle of the rotation in radians.private final double
The cosine of the angle of rotation, cached to avoid repeated computation.private static final Rotation2D
Instance representing a rotation of zero radians.private final double
The sine of the angle of rotation, cached to avoid repeated computation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Rotation2D
(double angle) Create a new instance representing the given angle. -
Method Summary
Modifier and TypeMethodDescriptionapplyVector
(Vector2D vec) Apply this transform to the given vector, ignoring translations.static Rotation2D
Create a rotation instance that rotates the vectoru
to point in the direction of vectorv
.boolean
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.inverse()
Get an instance representing the inverse transform.static Rotation2D
of
(double angle) Create a new instance with the given angle of rotation.boolean
Return true if the transform preserves the orientation of the space.toMatrix()
Return anAffineTransformMatrix2D
representing the same rotation as this instance.toString()
-
Field Details
-
IDENTITY
Instance representing a rotation of zero radians. -
angle
private final double angleThe angle of the rotation in radians. -
cosAngle
private final double cosAngleThe cosine of the angle of rotation, cached to avoid repeated computation. -
sinAngle
private final double sinAngleThe sine of the angle of rotation, cached to avoid repeated computation.
-
-
Constructor Details
-
Rotation2D
private Rotation2D(double angle) Create a new instance representing the given angle.- Parameters:
angle
- the angle of rotation, in radians
-
-
Method Details
-
getAngle
public double getAngle()Get the angle of rotation in radians.- Returns:
- the angle of rotation in radians
-
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:
-
apply
-
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 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
Return anAffineTransformMatrix2D
representing the same rotation as this instance.- Returns:
- a transform matrix representing the same rotation
-
hashCode
public int hashCode() -
equals
-
toString
-
of
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
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 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:
IllegalArgumentException
- if either vector cannot be normalized
-