Class Angle

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class Angle
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable

    An Angle object abstracts the angle's unit. It provides a simple interface to construct it from degrees or radians. Additionally, some useful calculations are implemented. But for sine/cosine/tangent calculations you may use the Math package.

    Every Angle object is normalized. That means, you will never encounter an Angle object beyond 360/2pi or below 0/0 (degrees/radians).

    See Also:
    Serialized Form
    • Constructor Detail

      • Angle

        public Angle()
        Constructs a new Angle object initialized with 0deg/0rad.
      • Angle

        public Angle​(double rad)
        Constructs a new Angle object with the given value in radians.
        Parameters:
        rad - the angle's value
    • Method Detail

      • fromDeg

        public static Angle fromDeg​(double degrees)
        Constructs a new Angle object representing the given value. The value is interpreted as being in degrees.
        Parameters:
        degrees - the angle in degrees
        Returns:
        an Angle object representing the passed-in angle given in degrees
      • fromRad

        public static Angle fromRad​(double radians)
        Constructs a new Angle object representing the given value. The value is interpreted as being in radians.
        Parameters:
        radians - the angle in radians
        Returns:
        an Angle object representing the passed-in angle given in radians
      • clone

        public Angle clone()
        Overridden with public visibility as proposed in Cloneable.
        Overrides:
        clone in class java.lang.Object
      • deg

        public double deg()
        Returns the value of this Angle object in degrees.
        Returns:
        this Angle's value in degrees.
      • equals

        public boolean equals​(java.lang.Object otherObj)
        Overrides:
        equals in class java.lang.Object
      • getAdded

        public Angle getAdded​(Angle other)
        Returns the sum of this and the given other Angle object as a new Angle object.
        Parameters:
        other - the Angle to add
        Returns:
        the sum of this and the given other Angle as a new Angle object
      • getCopy

        public Angle getCopy()
        Creates and returns a copy of this Angle.
        Returns:
        a copy of this Angle
      • getDeltaCCW

        public Angle getDeltaCCW​(Angle other)
        Returns the difference between this Angle and another Angle in a counter-clockwise direction
        Parameters:
        other - the other angle to compare to
        Returns:
        the difference between this Angle and another Angle in a counter-clockwise direction
      • getDeltaCW

        public Angle getDeltaCW​(Angle other)
        Returns the difference between this Angle and another Angle in a clockwise direction
        Parameters:
        other - the other angle to compare to
        Returns:
        the difference between this Angle and another Angle in a clockwise direction
      • getMultiplied

        public Angle getMultiplied​(double factor)
        Returns a new Angle object representing this Angle multiplied by the given factor.
        Parameters:
        factor - the multiplication factor
        Returns:
        a new Angle object representing this Angle multiplied by the given factor
      • getOppositeFull

        public Angle getOppositeFull()
        Returns the opposite Angle of this Angle in a full circle as a new Angle object.
        Returns:
        the opposite Angle of this Angle in a full circle as a new Angle object
      • getOppositeSemi

        public Angle getOppositeSemi()
        Returns the opposite Angle of this Angle in a semi-circle as a new Angle object.
        Returns:
        the opposite Angle of this Angle in a semi-circle as a new Angle object
      • getReverse

        public Angle getReverse()
        Returns the reverse Angle of this Angle in a full circle as a new Angle object.
        Returns:
        the reverse Angle of this Angle in a full circle as a new Angle object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • isClockwise

        public boolean isClockwise​(Angle other)
        Tests if the other Angle is within a half-circle clockwise rotation from this Angle
        Parameters:
        other - the other angle to compare to
        Returns:
        true if the a clockwise rotation to the other angle is less than 180deg
      • rad

        public double rad()
        Returns this Angle's value in radians.
        Returns:
        This Angle's value in radians.
      • setDeg

        public Angle setDeg​(double degrees)
        Sets this Angle's value to the passed-in value in degrees.
        Parameters:
        degrees - the angle's value in degrees
        Returns:
        this for convenience
      • setRad

        public Angle setRad​(double radians)
        Sets this Angle's value to the passed-in value in radians.
        Parameters:
        radians - the angle's value in radians
        Returns:
        this for convenience
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object