Class Angle

  • All Implemented Interfaces:
    java.lang.Comparable<Angle>

    public class Angle
    extends java.lang.Object
    implements java.lang.Comparable<Angle>
    Represents a geometric angle. Instances of Angle are immutable. An angle can be obtained through the factory methods fromDegrees(double) and fromRadians(double).
    • Field Detail

      • ANGLE_FORMAT_DMS

        public static final java.lang.String ANGLE_FORMAT_DMS
        See Also:
        Constant Field Values
      • ZERO

        public static final Angle ZERO
        Represents an angle of zero degrees
      • POS90

        public static final Angle POS90
        Represents a right angle of positive 90 degrees
      • NEG90

        public static final Angle NEG90
        Represents a right angle of negative 90 degrees
      • POS180

        public static final Angle POS180
        Represents an angle of positive 180 degrees
      • NEG180

        public static final Angle NEG180
        Represents an angle of negative 180 degrees
      • POS360

        public static final Angle POS360
        Represents an angle of positive 360 degrees
      • NEG360

        public static final Angle NEG360
        Represents an angle of negative 360 degrees
      • MINUTE

        public static final Angle MINUTE
        Represents an angle of 1 minute
      • SECOND

        public static final Angle SECOND
        Represents an angle of 1 second
      • degrees

        public final double degrees
      • radians

        public final double radians
    • Constructor Detail

      • Angle

        public Angle​(Angle angle)
    • Method Detail

      • fromDegrees

        public static Angle fromDegrees​(double degrees)
        Obtains an angle from a specified number of degrees.
        Parameters:
        degrees - the size in degrees of the angle to be obtained
        Returns:
        a new angle, whose size in degrees is given by degrees
      • fromRadians

        public static Angle fromRadians​(double radians)
        Obtains an angle from a specified number of radians.
        Parameters:
        radians - the size in radians of the angle to be obtained.
        Returns:
        a new angle, whose size in radians is given by radians.
      • fromDegreesLatitude

        public static Angle fromDegreesLatitude​(double degrees)
      • fromRadiansLatitude

        public static Angle fromRadiansLatitude​(double radians)
      • fromDegreesLongitude

        public static Angle fromDegreesLongitude​(double degrees)
      • fromRadiansLongitude

        public static Angle fromRadiansLongitude​(double radians)
      • fromXY

        public static Angle fromXY​(double x,
                                   double y)
        Obtains an angle from rectangular coordinates.
        Parameters:
        x - the abscissa coordinate.
        y - the ordinate coordinate.
        Returns:
        a new angle, whose size is determined from x and y.
      • fromDMS

        public static Angle fromDMS​(int degrees,
                                    int minutes,
                                    int seconds)
        Obtain an angle from a given number of positive degrees, minutes and seconds.
        Parameters:
        degrees - integer number of degrees, positive.
        minutes - integer number of minutes, positive only between 0 and 60.
        seconds - integer number of seconds, positive only between 0 and 60.
        Returns:
        a new angle whose size in degrees is given by degrees, minutes and seconds.
        Throws:
        java.lang.IllegalArgumentException - if minutes or seconds are outside the 0-60 range or the degrees is negative.
      • fromDMdS

        public static Angle fromDMdS​(int degrees,
                                     double minutes)
        Obtain an angle from a given number of positive degrees and decimal minutes.
        Parameters:
        degrees - integer number of degrees, positive.
        minutes - double representing the decimal representation of minutes and seconds.
        Returns:
        a new angle whose size in degrees is given by degrees and decimal minutes.
        Throws:
        java.lang.IllegalArgumentException - if minutes or seconds are outside the 0-60 range or the degrees is negative.
      • fromDMS

        public static Angle fromDMS​(java.lang.String dmsString)
        Obtain an angle from a degrees, minute and seconds character string.

        eg:

         123 34 42
         -123* 34' 42" (where * stands for the degree symbol)
         +45* 12' 30" (where * stands for the degree symbol)
         45 12 30 S
         45 12 30 N
         
        For a string containing both a sign and compass direction, the compass direction will take precedence.
        Parameters:
        dmsString - the degrees, minute and second character string.
        Returns:
        the corresponding angle.
        Throws:
        java.lang.IllegalArgumentException - if dmsString is null or not properly formated.
      • getDegrees

        public final double getDegrees()
        Retrieves the size of this angle in degrees. This method may be faster than first obtaining the radians and then converting to degrees.
        Returns:
        the size of this angle in degrees.
      • getRadians

        public final double getRadians()
        Retrieves the size of this angle in radians. This may be useful for java.lang.Math functions, which generally take radians as trigonometric arguments. This method may be faster that first obtaining the degrees and then converting to radians.
        Returns:
        the size of this angle in radians.
      • add

        public final Angle add​(Angle angle)
        Obtains the sum of these two angles. Does not accept a null argument. This method is commutative, so a.add(b) and b.add(a) are equivalent. Neither this angle nor angle is changed, instead the result is returned as a new angle.
        Parameters:
        angle - the angle to add to this one.
        Returns:
        an angle whose size is the total of this angles and angles size.
        Throws:
        java.lang.IllegalArgumentException - if angle is null.
      • subtract

        public final Angle subtract​(Angle angle)
        Obtains the difference of these two angles. Does not accept a null argument. This method is not commutative. Neither this angle nor angle is changed, instead the result is returned as a new angle.
        Parameters:
        angle - the angle to subtract from this angle.
        Returns:
        a new angle corresponding to this angle's size minus angle's size.
        Throws:
        java.lang.IllegalArgumentException - if angle is null.
      • multiply

        public final Angle multiply​(double multiplier)
        Multiplies this angle by multiplier. This angle remains unchanged. The result is returned as a new angle.
        Parameters:
        multiplier - a scalar by which this angle is multiplied.
        Returns:
        a new angle whose size equals this angle's size multiplied by multiplier.
      • divide

        public final double divide​(Angle angle)
        Divides this angle by another angle. This angle remains unchanged, instead the resulting value in degrees is returned.
        Parameters:
        angle - the angle by which to divide.
        Returns:
        this angle's degrees divided by angle's degrees.
        Throws:
        java.lang.IllegalArgumentException - if angle is null.
      • addDegrees

        public final Angle addDegrees​(double degrees)
      • subtractDegrees

        public final Angle subtractDegrees​(double degrees)
      • divide

        public final Angle divide​(double divisor)
        Divides this angle by divisor. This angle remains unchanged. The result is returned as a new angle. Behaviour is undefined if divisor equals zero.
        Parameters:
        divisor - the number to be divided by.
        Returns:
        a new angle equivalent to this angle divided by divisor.
      • addRadians

        public final Angle addRadians​(double radians)
      • subtractRadians

        public final Angle subtractRadians​(double radians)
      • angularDistanceTo

        public Angle angularDistanceTo​(Angle angle)
        Computes the shortest distance between this and angle, as an angle.
        Parameters:
        angle - the angle to measure angular distance to.
        Returns:
        the angular distance between this and value.
      • sin

        public final double sin()
        Obtains the sine of this angle.
        Returns:
        the trigonometric sine of this angle.
      • sinHalfAngle

        public final double sinHalfAngle()
      • asin

        public static Angle asin​(double sine)
      • arctanh

        public static double arctanh​(double radians)
      • cos

        public final double cos()
        Obtains the cosine of this angle.
        Returns:
        the trigonometric cosine of this angle.
      • cosHalfAngle

        public final double cosHalfAngle()
      • acos

        public static Angle acos​(double cosine)
      • tanHalfAngle

        public final double tanHalfAngle()
        Obtains the tangent of half of this angle.
        Returns:
        the trigonometric tangent of half of this angle.
      • atan

        public static Angle atan​(double tan)
      • midAngle

        public static Angle midAngle​(Angle a1,
                                     Angle a2)
        Obtains the average of two angles. This method is commutative, so midAngle(m, n) and midAngle(n, m) are equivalent.
        Parameters:
        a1 - the first angle.
        a2 - the second angle.
        Returns:
        the average of a1 and a2 throws IllegalArgumentException if either angle is null.
      • average

        public static Angle average​(Angle a,
                                    Angle b)
        Obtains the average of three angles. The order of parameters does not matter.
        Parameters:
        a - the first angle.
        b - the second angle.
        Returns:
        the average of a1, a2 and a3
        Throws:
        java.lang.IllegalArgumentException - if a or b is null
      • average

        public static Angle average​(Angle a,
                                    Angle b,
                                    Angle c)
        Obtains the average of three angles. The order of parameters does not matter.
        Parameters:
        a - the first angle.
        b - the second angle.
        c - the third angle.
        Returns:
        the average of a1, a2 and a3.
        Throws:
        java.lang.IllegalArgumentException - if a, b or c is null.
      • clamp

        public static Angle clamp​(Angle value,
                                  Angle min,
                                  Angle max)
        Limits a specified angle to be within a specified minimum and maximum.

        The returned angle is undefined if min > max. Otherwise, this method's return value is equivalent to the following:

        • min - If value < min
        • max - If value > max
        • value - If min <= value >= max
        Parameters:
        value - The angle to clamp.
        min - The minimum angle to clamp to.
        max - The maximum angle to clamp to.
        Returns:
        The clamped angle.
        Throws:
        java.lang.IllegalArgumentException - if any argument is null.
      • mix

        public static Angle mix​(double amount,
                                Angle value1,
                                Angle value2)
        Linearly interpolates between two angles.
        Parameters:
        amount - the interpolant.
        value1 - the first angle.
        value2 - the second angle.
        Returns:
        a new angle between value1 and value2.
      • compareTo

        public final int compareTo​(Angle angle)
        Compares this Angle with another. Returns a negative integer if this is the smaller angle, a positive integer if this is the larger, and zero if both angles are equal.
        Specified by:
        compareTo in interface java.lang.Comparable<Angle>
        Parameters:
        angle - the angle to compare against.
        Returns:
        -1 if this angle is smaller, 0 if both are equal and +1 if this angle is larger.
        Throws:
        java.lang.IllegalArgumentException - if angle is null.
      • normalizedDegrees

        public static double normalizedDegrees​(double degrees)
      • normalizedDegreesLatitude

        public static double normalizedDegreesLatitude​(double degrees)
      • normalizedDegreesLongitude

        public static double normalizedDegreesLongitude​(double degrees)
      • normalizedAngle

        public static Angle normalizedAngle​(Angle unnormalizedAngle)
      • normalizedLatitude

        public static Angle normalizedLatitude​(Angle unnormalizedAngle)
      • normalizedLongitude

        public static Angle normalizedLongitude​(Angle unnormalizedAngle)
      • normalize

        public Angle normalize()
      • normalizedLatitude

        public Angle normalizedLatitude()
      • normalizedLongitude

        public Angle normalizedLongitude()
      • crossesLongitudeBoundary

        public static boolean crossesLongitudeBoundary​(Angle angleA,
                                                       Angle angleB)
      • isValidLatitude

        public static boolean isValidLatitude​(double value)
      • isValidLongitude

        public static boolean isValidLongitude​(double value)
      • toString

        public final java.lang.String toString()
        Obtains a String representation of this angle.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the value of this angle in degrees and as a String.
      • toDecimalDegreesString

        public final java.lang.String toDecimalDegreesString​(int digits)
        Forms a decimal degrees String representation of this Angle.
        Parameters:
        digits - the number of digits past the decimal point to include in the string.
        Returns:
        the value of this angle in decimal degrees as a string with the specified number of digits beyond the decimal point. The string is padded with trailing zeros to fill the number of post-decimal point positions requested.
      • toDMSString

        public final java.lang.String toDMSString()
        Obtains a String representation of this Angle formatted as degrees, minutes and seconds integer values.
        Returns:
        the value of this angle in degrees, minutes, seconds as a string.
      • toDMString

        public final java.lang.String toDMString()
        Obtains a String representation of this Angle formatted as degrees and decimal minutes.
        Returns:
        the value of this angle in degrees and decimal minutes as a string.
      • toFormattedDMSString

        public final java.lang.String toFormattedDMSString()
      • toDMS

        public final double[] toDMS()
      • getSizeInBytes

        public long getSizeInBytes()
        Obtains the amount of memory this Angle consumes.
        Returns:
        the memory footprint of this angle in bytes.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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