Package com.thunder.lib.types
Class CanonicalAngle
java.lang.Object
com.thunder.lib.types.CanonicalAngle
Represents an angle in the range of (-π, π].
This class is similar to Rotation2d, but is designed to represent angles in a
more mathematically consistent way, avoiding issues with wrapping and
discontinuities.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a CanonicalAngle with a default value of 0 radians.CanonicalAngle(double radians) Constructs a CanonicalAngle with the specified radian value.CanonicalAngle(double x, double y) Constructs a CanonicalAngle with the specified x and y components.CanonicalAngle(Rotation2d rotation) Constructs a CanonicalAngle from a Rotation2d.CanonicalAngle(Angle angle) Constructs a CanonicalAngle with the specified Angle value. -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic CanonicalAnglefromDegrees(double degrees) Constructs and returns a CanonicalAngle with the specified degree value.static CanonicalAnglefromRadians(double radians) Constructs and returns a CanonicalAngle with the specified radian value.doublegetCos()Returns the cosine of the angle.doubleReturns the angle in degrees.doubleReturns the angle in radians.doublegetSin()Returns the sine of the angle.doublegetTan()Returns the tangent of the angle.inthashCode()booleanisSupplementaryTo(CanonicalAngle other) Checks if this angle is supplementary to another angle.minus(CanonicalAngle other) Subtracts the new angle from the current angle.plus(CanonicalAngle other) Adds two angles together.rotateBy(CanonicalAngle other) Rotates the current angle by another angle.Calculates the supplementary angle.Converts this CanonicalAngle to an Angle measure.Converts this CanonicalAngle to a Rotation2d.toString()Takes the inverse (negation) of the current angle.
-
Constructor Details
-
CanonicalAngle
public CanonicalAngle()Constructs a CanonicalAngle with a default value of 0 radians. -
CanonicalAngle
Constructs a CanonicalAngle from a Rotation2d.- Parameters:
rotation- The Rotation2d to convert to a CanonicalAngle.
-
CanonicalAngle
public CanonicalAngle(double radians) Constructs a CanonicalAngle with the specified radian value.- Parameters:
radians- The value in radians.
-
CanonicalAngle
Constructs a CanonicalAngle with the specified Angle value.- Parameters:
angle- The Angle value.
-
CanonicalAngle
public CanonicalAngle(double x, double y) Constructs a CanonicalAngle with the specified x and y components.- Parameters:
x- The x component or cosine of the angle.y- The y component or sine of the angle.
-
-
Method Details
-
fromRadians
Constructs and returns a CanonicalAngle with the specified radian value.- Parameters:
radians- The value in radians.- Returns:
- The angle object.
-
fromDegrees
Constructs and returns a CanonicalAngle with the specified degree value.- Parameters:
degrees- The value in degrees.- Returns:
- The angle object.
-
getCos
public double getCos()Returns the cosine of the angle.- Returns:
- Cosine of the angle.
-
getSin
public double getSin()Returns the sine of the angle.- Returns:
- Sine of the angle.
-
getTan
public double getTan()Returns the tangent of the angle.- Returns:
- Tangent of the angle.
-
getRadians
public double getRadians()Returns the angle in radians.- Returns:
- Angle in radians.
-
getDegrees
public double getDegrees()Returns the angle in degrees.- Returns:
- Angle in degrees.
-
toRotation2d
Converts this CanonicalAngle to a Rotation2d.- Returns:
- The corresponding Rotation2d.
-
toAngleMeasure
Converts this CanonicalAngle to an Angle measure.- Returns:
- The corresponding Angle measure.
-
plus
Adds two angles together.- Parameters:
other- The angles to add.- Returns:
- The sum of the two angles.
-
minus
Subtracts the new angle from the current angle.- Parameters:
other- The angle to subtract.- Returns:
- The difference between the two angles.
-
unaryMinus
Takes the inverse (negation) of the current angle.- Returns:
- The inverse of the current angle.
-
rotateBy
Rotates the current angle by another angle.- Parameters:
other- The angle to rotate by.- Returns:
- The rotated angle.
-
supplementary
Calculates the supplementary angle.- Returns:
- The supplementary angle.
-
isSupplementaryTo
Checks if this angle is supplementary to another angle.- Parameters:
other- The angle to check against.- Returns:
- True if the angles are supplementary, false otherwise.
-
toString
-
equals
-
hashCode
public int hashCode()
-