Class CanonicalAngle

java.lang.Object
com.thunder.lib.types.CanonicalAngle

public class CanonicalAngle extends Object
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 Details

    • CanonicalAngle

      public CanonicalAngle()
      Constructs a CanonicalAngle with a default value of 0 radians.
    • CanonicalAngle

      public CanonicalAngle(Rotation2d rotation)
      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

      public CanonicalAngle(Angle angle)
      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

      public static CanonicalAngle fromRadians(double radians)
      Constructs and returns a CanonicalAngle with the specified radian value.
      Parameters:
      radians - The value in radians.
      Returns:
      The angle object.
    • fromDegrees

      public static CanonicalAngle fromDegrees(double degrees)
      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

      public Rotation2d toRotation2d()
      Converts this CanonicalAngle to a Rotation2d.
      Returns:
      The corresponding Rotation2d.
    • toAngleMeasure

      public Angle toAngleMeasure()
      Converts this CanonicalAngle to an Angle measure.
      Returns:
      The corresponding Angle measure.
    • plus

      public CanonicalAngle plus(CanonicalAngle other)
      Adds two angles together.
      Parameters:
      other - The angles to add.
      Returns:
      The sum of the two angles.
    • minus

      public CanonicalAngle minus(CanonicalAngle other)
      Subtracts the new angle from the current angle.
      Parameters:
      other - The angle to subtract.
      Returns:
      The difference between the two angles.
    • unaryMinus

      public CanonicalAngle unaryMinus()
      Takes the inverse (negation) of the current angle.
      Returns:
      The inverse of the current angle.
    • rotateBy

      public CanonicalAngle rotateBy(CanonicalAngle other)
      Rotates the current angle by another angle.
      Parameters:
      other - The angle to rotate by.
      Returns:
      The rotated angle.
    • supplementary

      public CanonicalAngle supplementary()
      Calculates the supplementary angle.
      Returns:
      The supplementary angle.
    • isSupplementaryTo

      public boolean isSupplementaryTo(CanonicalAngle other)
      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

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object