Class Angle

java.lang.Object
com.stuypulse.stuylib.math.Angle

public final class Angle extends Object
This angle class is made to remove the ambiguity of units when passing or returning angles. It stores it in radians, but returns it in any unit depending on what the user requests. All of the functions and math normalize the angle to help issues.
  • Field Details

    • kRadiant

      public static final Angle kRadiant
    • kDegree

      public static final Angle kDegree
    • kArcMinute

      public static final Angle kArcMinute
    • kArcSecond

      public static final Angle kArcSecond
    • kZero

      public static final Angle kZero
    • k30deg

      public static final Angle k30deg
    • k45deg

      public static final Angle k45deg
    • k60deg

      public static final Angle k60deg
    • k90deg

      public static final Angle k90deg
    • k120deg

      public static final Angle k120deg
    • k135deg

      public static final Angle k135deg
    • k150deg

      public static final Angle k150deg
    • k180deg

      public static final Angle k180deg
    • kNull

      public static final Angle kNull
      An angle that will return cos() = 0, sin() = 0, toRadians() = 0
  • Method Details

    • fromRadians

      public static Angle fromRadians(double radians)
      Construct a new Angle class with a double in radians
      Parameters:
      radians - the angle for the new angle class measured in radians
      Returns:
      an angle class with the specified angle
    • fromRotations

      public static Angle fromRotations(double rotations)
      Construct a new Angle class with a double in rotations
      Parameters:
      rotations - the angle for the new angle class measured in the number of rotations
      Returns:
      an angle class with the specified angle
    • fromDegrees

      public static Angle fromDegrees(double degrees)
      Construct a new Angle class with a double in degrees
      Parameters:
      degrees - the angle for the new angle class measured in degrees
      Returns:
      an angle class with the specified angle
    • fromDegrees

      public static Angle fromDegrees(int degrees)
      Return a new Angle class with an integer in degrees.

      Because the value that the angle is created from is an integer, every possible angle has been precalculated. You can use this method if you are worried about memory usage or computation time.

      Parameters:
      degrees - the angle for the new angle class in degrees
      Returns:
      an angle class with the specified angle
    • fromArcMinutes

      public static Angle fromArcMinutes(double arcminutes)
      Construct a new Angle class with a double in arcminute
      Parameters:
      arcminutes - the angle for the new angle class in arcminutes
      Returns:
      an angle class with the specified angle
    • fromArcSeconds

      public static Angle fromArcSeconds(double arcseconds)
      Construct a new Angle class with a double in arcseconds
      Parameters:
      arcseconds - the angle for the new angle class in arcseconds
      Returns:
      an angle class with the specified angle
    • fromVector

      public static Angle fromVector(double x, double y)
      Contstruct a new Angle class from x and y positions.

      You can think of this as getting the angle from rise [y] over run [x].

      Parameters:
      x - the run of the vector
      y - the rise of the vector
      Returns:
      the new angle class
    • fromVector

      public static Angle fromVector(Vector2D vector)
      Construct a new Angle class from a vector.

      This is identicle to calling fromVector(x, y) but by passing in the vectors x and y values.

      Parameters:
      vector - the vector from which to get the angle from
      Returns:
      the angle of the vector
    • fromSlope

      public static Angle fromSlope(double slope)
      Construct a new Angle from a slope.

      This will get you the angle of any slope in the form of rise / run.

      Parameters:
      slope - the slope to get the angle from
      Returns:
      the angle of the slope
    • fromRotation2d

      public static Angle fromRotation2d(edu.wpi.first.math.geometry.Rotation2d rotation)
      Constructs a new Angle from a WPILib Rotation2d
      Parameters:
      rotation - rotation2d object
      Returns:
      the same angle
    • toRadians

      public double toRadians()
      Returns:
      the value of the angle in radians centered around 0.0 (+/- pi)
    • toRadians

      public double toRadians(double center)
      Parameters:
      center - the angle in radians to be centered around (+/- pi)
      Returns:
      the angle normalized around the center in radians
    • toRotations

      public double toRotations()
      Returns:
      the value of the angle in rotations centered around 0.0 (+/- 0.5)
    • toRotations

      public double toRotations(double center)
      Parameters:
      center - the angle in rotations to be centered around (+/- 0.5)
      Returns:
      the angle normalized around the center in rotations
    • toDegrees

      public double toDegrees()
      Returns:
      the value of the angle in degrees centered around 0.0 (+/- 180)
    • toDegrees

      public double toDegrees(double center)
      Parameters:
      center - the angle in degrees to be centered around (+/- 180)
      Returns:
      the angle normalized around the center in degrees
    • getRotation2d

      public edu.wpi.first.math.geometry.Rotation2d getRotation2d()
      Return the StuyLib Angle class in the form of the WPILib Rotation2d.

      This function is here in order to make interoperability with WPILib easier so that manual conversion isn't needed as much.

      Returns:
      Rotation2d with the same value as this angle
    • add

      public Angle add(Angle other)
      Add two angles together
      Parameters:
      other - the other angle in the sum
      Returns:
      the sum of the two angles [normalized from (-pi, pi)]
    • addRadians

      public Angle addRadians(double radians)
      Add two angles together
      Parameters:
      radians - the other angle in the sum
      Returns:
      the sum of the two angles [normalized from (-pi, pi)]
    • addRotations

      public Angle addRotations(double rotations)
      Add two angles together
      Parameters:
      rotations - the other angle in the sum
      Returns:
      the sum of the two angles [normalized from (-pi, pi)]
    • addDegrees

      public Angle addDegrees(double degrees)
      Add two angles together
      Parameters:
      degrees - the other angle in the sum
      Returns:
      the sum of the two angles [normalized from (-pi, pi)]
    • sub

      public Angle sub(Angle other)
      Subtract two angles from each other
      Parameters:
      other - the other angle to subtract
      Returns:
      the second angle subtracted from the first [normalized from (-pi, pi)]
    • subRadians

      public Angle subRadians(double radians)
      Subtract two angles from each other
      Parameters:
      radians - the other angle to subtract
      Returns:
      the second angle subtracted from the first [normalized from (-pi, pi)]
    • subRotations

      public Angle subRotations(double rotations)
      Subtract two angles from each other
      Parameters:
      rotations - the other angle to subtract
      Returns:
      the second angle subtracted from the first [normalized from (-pi, pi)]
    • subDegrees

      public Angle subDegrees(double degrees)
      Subtract two angles from each other
      Parameters:
      degrees - the other angle to subtract
      Returns:
      the second angle subtracted from the first [normalized from (-pi, pi)]
    • velocityRadians

      public double velocityRadians(Angle prev, double dt)
      Get the angular velocity in radians given 2 angles and a dt
      Parameters:
      prev - the previous angle to measure velocity from
      dt - the time between measurements
      Returns:
      the calculated angular velocity in radians/s
    • velocityRotations

      public double velocityRotations(Angle prev, double dt)
      Get the angular velocity in rotations/s given 2 angles and a dt
      Parameters:
      prev - the previous angle to measure velocity from
      dt - the time between measurements
      Returns:
      the calculated angular velocity in rotations/s
    • velocityDegrees

      public double velocityDegrees(Angle prev, double dt)
      Get the angular velocity in degrees/s given 2 angles and a dt
      Parameters:
      prev - the previous angle to measure velocity from
      dt - the time between measurements
      Returns:
      the calculated angular velocity in degrees/s
    • mul

      public Angle mul(double scale)
      Multiply the angle by a scalar value
      Parameters:
      scale - the scaler value to multiply the angle by
      Returns:
      the multiplied angle [normalized from (-pi, pi)]
    • div

      public Angle div(double scale)
      Divide the angle by a scalar value
      Parameters:
      scale - the scaler value to divide the angle by
      Returns:
      the divided angle [normalized from (-pi, pi)]
    • negative

      public Angle negative()
      Returns:
      an angle with a negative value
    • opposite

      public Angle opposite()
      Returns:
      an angle rotated by 180 degrees or Pi radians
    • sin

      public double sin()
      Returns:
      the sine value of this angle
    • cos

      public double cos()
      Returns:
      the cosine value of this angle
    • tan

      public double tan()
      Returns:
      the tangent value of this angle
    • getVector

      public Vector2D getVector()
      Returns:
      the angle as a point on the unit circle
    • equals

      public boolean equals(Object other)
      Compare Angle to another object
      Overrides:
      equals in class Object
      Parameters:
      other - object to compare to
      Returns:
      both objects are Angle and they equal eachother
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      the hashCode of the double for the value in radians