Class WrappedAngle


  • public class WrappedAngle
    extends java.lang.Object
    Represents an angle which is constrained to [-180, 180) degrees. Does the math to find the best direction to get from one angle to another.
    • Constructor Summary

      Constructors 
      Constructor Description
      WrappedAngle​(double angle)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double asDouble()
      Gets the angle that this represents, in the range [-180, 180).
      double getSmallestDifferenceWith​(WrappedAngle that)
      Gets the smallest difference (by magnitude) between this angle and the given angle, either going clockwise or counter-clockwise.
      org.javatuples.Pair<java.lang.Double,​java.lang.Boolean> getSmallestDifferenceWithHalfAngle​(WrappedAngle that, double biasTo360)
      Gets the smallest difference (by magnitude) between this angle and either the given angle or the given angle + 180, going etiher clockwise or counter-clockwise.
      WrappedAngle plus​(double addend)
      Returns the sum of this angle and the given angle
      WrappedAngle plus​(WrappedAngle addend)
      Return the sum of this angle and the given angle
      static double wrapAngle​(double angle)
      Wraps the angle to be in the range [-180, 180).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WrappedAngle

        public WrappedAngle​(double angle)
        Constructor.
        Parameters:
        angle - The angle that this will represent, in degrees. Not bound to any range.
    • Method Detail

      • asDouble

        public double asDouble()
        Gets the angle that this represents, in the range [-180, 180).
        Returns:
        The angle in degrees
      • plus

        public WrappedAngle plus​(double addend)
        Returns the sum of this angle and the given angle
        Parameters:
        addend - The angle to add, in degrees
        Returns:
        The sum
      • plus

        public WrappedAngle plus​(WrappedAngle addend)
        Return the sum of this angle and the given angle
        Parameters:
        addend - The angle to add
        Returns:
        The sum
      • getSmallestDifferenceWith

        public double getSmallestDifferenceWith​(WrappedAngle that)
        Gets the smallest difference (by magnitude) between this angle and the given angle, either going clockwise or counter-clockwise.
        Parameters:
        that - The angle to get the difference from
        Returns:
        The difference, in degrees. When added to this angle, the sum will be the given angle.
      • getSmallestDifferenceWithHalfAngle

        public org.javatuples.Pair<java.lang.Double,​java.lang.Boolean> getSmallestDifferenceWithHalfAngle​(WrappedAngle that,
                                                                                                                double biasTo360)
        Gets the smallest difference (by magnitude) between this angle and either the given angle or the given angle + 180, going etiher clockwise or counter-clockwise.
        Parameters:
        that - The angle to get the difference from
        biasTo360 - The maximum distance from the given angle where the distance returned will be from it and not it + 180. Range is [0, 180], where 90 means indifference to where the given angle or the given angle + 180 is used, 180 means never use the given angle + 180, and anything less than 0.01 means always use the given angle + 180
        Returns:
        A javatuples pair containing (1) The difference, in degrees. When added to this angle, the sum will be the given angle or the given angle + 180. (2) True adding the difference will result in the given angle + 180, false if it will result in the given angle
      • wrapAngle

        public static double wrapAngle​(double angle)
        Wraps the angle to be in the range [-180, 180).
        Parameters:
        angle - The angle to wrap, in degrees
        Returns:
        The wrapped angle, in degrees