Package gov.nasa.worldwind.geom
Class Angle
- java.lang.Object
-
- gov.nasa.worldwind.geom.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 ofAngleare immutable. An angle can be obtained through the factory methodsfromDegrees(double)andfromRadians(double).
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringANGLE_FORMAT_DDstatic java.lang.StringANGLE_FORMAT_DMstatic java.lang.StringANGLE_FORMAT_DMSdoubledegreesstatic AngleMINUTERepresents an angle of 1 minutestatic AngleNEG180Represents an angle of negative 180 degreesstatic AngleNEG360Represents an angle of negative 360 degreesstatic AngleNEG90Represents a right angle of negative 90 degreesstatic AnglePOS180Represents an angle of positive 180 degreesstatic AnglePOS360Represents an angle of positive 360 degreesstatic AnglePOS90Represents a right angle of positive 90 degreesdoubleradiansstatic AngleSECONDRepresents an angle of 1 secondstatic AngleZERORepresents an angle of zero degrees
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Angleacos(double cosine)Angleadd(Angle angle)Obtains the sum of these two angles.AngleaddDegrees(double degrees)AngleaddRadians(double radians)AngleangularDistanceTo(Angle angle)Computes the shortest distance between this and angle, as an angle.static doublearctanh(double radians)static Angleasin(double sine)static Angleatan(double tan)static Angleaverage(Angle a, Angle b)Obtains the average of three angles.static Angleaverage(Angle a, Angle b, Angle c)Obtains the average of three angles.static Angleclamp(Angle value, Angle min, Angle max)Limits a specified angle to be within a specified minimum and maximum.intcompareTo(Angle angle)Compares thisAnglewith another.doublecos()Obtains the cosine of this angle.doublecosHalfAngle()static booleancrossesLongitudeBoundary(Angle angleA, Angle angleB)Angledivide(double divisor)Divides this angle bydivisor.doubledivide(Angle angle)Divides this angle by another angle.booleanequals(java.lang.Object o)static AnglefromDegrees(double degrees)Obtains an angle from a specified number of degrees.static AnglefromDegreesLatitude(double degrees)static AnglefromDegreesLongitude(double degrees)static AnglefromDMdS(int degrees, double minutes)Obtain an angle from a given number of positive degrees and decimal minutes.static AnglefromDMS(int degrees, int minutes, int seconds)Obtain an angle from a given number of positive degrees, minutes and seconds.static AnglefromDMS(java.lang.String dmsString)Obtain an angle from a degrees, minute and seconds character string.static AnglefromRadians(double radians)Obtains an angle from a specified number of radians.static AnglefromRadiansLatitude(double radians)static AnglefromRadiansLongitude(double radians)static AnglefromXY(double x, double y)Obtains an angle from rectangular coordinates.doublegetDegrees()Retrieves the size of this angle in degrees.doublegetRadians()Retrieves the size of this angle in radians.longgetSizeInBytes()Obtains the amount of memory thisAngleconsumes.inthashCode()static booleanisValidLatitude(double value)static booleanisValidLongitude(double value)static Anglemax(Angle a, Angle b)static AnglemidAngle(Angle a1, Angle a2)Obtains the average of two angles.static Anglemin(Angle a, Angle b)static Anglemix(double amount, Angle value1, Angle value2)Linearly interpolates between two angles.Anglemultiply(double multiplier)Multiplies this angle bymultiplier.Anglenormalize()static AnglenormalizedAngle(Angle unnormalizedAngle)static doublenormalizedDegrees(double degrees)static doublenormalizedDegreesLatitude(double degrees)static doublenormalizedDegreesLongitude(double degrees)AnglenormalizedLatitude()static AnglenormalizedLatitude(Angle unnormalizedAngle)AnglenormalizedLongitude()static AnglenormalizedLongitude(Angle unnormalizedAngle)doublesin()Obtains the sine of this angle.doublesinHalfAngle()Anglesubtract(Angle angle)Obtains the difference of these two angles.AnglesubtractDegrees(double degrees)AnglesubtractRadians(double radians)doubletanHalfAngle()Obtains the tangent of half of this angle.java.lang.StringtoDecimalDegreesString(int digits)Forms a decimal degreesStringrepresentation of thisAngle.double[]toDMS()java.lang.StringtoDMSString()Obtains aStringrepresentation of thisAngleformatted as degrees, minutes and seconds integer values.java.lang.StringtoDMString()Obtains aStringrepresentation of thisAngleformatted as degrees and decimal minutes.java.lang.StringtoFormattedDMSString()java.lang.StringtoString()Obtains aStringrepresentation of this angle.
-
-
-
Field Detail
-
ANGLE_FORMAT_DD
public static final java.lang.String ANGLE_FORMAT_DD
- See Also:
- Constant Field Values
-
ANGLE_FORMAT_DM
public static final java.lang.String ANGLE_FORMAT_DM
- See Also:
- Constant Field Values
-
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
xandy.
-
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,minutesandseconds. - 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
degreesand decimalminutes. - 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 forjava.lang.Mathfunctions, 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, soa.add(b)andb.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 bymultiplier. 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 bydivisor. This angle remains unchanged. The result is returned as a new angle. Behaviour is undefined ifdivisorequals 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, somidAngle(m, n)andmidAngle(n, m)are equivalent.- Parameters:
a1- the first angle.a2- the second angle.- Returns:
- the average of
a1anda2throws 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,a2anda3 - Throws:
java.lang.IllegalArgumentException- ifaorbis 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,a2anda3. - Throws:
java.lang.IllegalArgumentException- ifa,borcis 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
value1andvalue2.
-
compareTo
public final int compareTo(Angle angle)
Compares thisAnglewith 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:
compareToin interfacejava.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)
-
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 aStringrepresentation of this angle.- Overrides:
toStringin classjava.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 degreesStringrepresentation of thisAngle.- 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 aStringrepresentation of thisAngleformatted 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 aStringrepresentation of thisAngleformatted 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 thisAngleconsumes.- Returns:
- the memory footprint of this angle in bytes.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-