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 ofAngle
are immutable. An angle can be obtained through the factory methodsfromDegrees(double)
andfromRadians(double)
.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ANGLE_FORMAT_DD
static java.lang.String
ANGLE_FORMAT_DM
static java.lang.String
ANGLE_FORMAT_DMS
double
degrees
static Angle
MINUTE
Represents an angle of 1 minutestatic Angle
NEG180
Represents an angle of negative 180 degreesstatic Angle
NEG360
Represents an angle of negative 360 degreesstatic Angle
NEG90
Represents a right angle of negative 90 degreesstatic Angle
POS180
Represents an angle of positive 180 degreesstatic Angle
POS360
Represents an angle of positive 360 degreesstatic Angle
POS90
Represents a right angle of positive 90 degreesdouble
radians
static Angle
SECOND
Represents an angle of 1 secondstatic Angle
ZERO
Represents an angle of zero degrees
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Angle
acos(double cosine)
Angle
add(Angle angle)
Obtains the sum of these two angles.Angle
addDegrees(double degrees)
Angle
addRadians(double radians)
Angle
angularDistanceTo(Angle angle)
Computes the shortest distance between this and angle, as an angle.static double
arctanh(double radians)
static Angle
asin(double sine)
static Angle
atan(double tan)
static Angle
average(Angle a, Angle b)
Obtains the average of three angles.static Angle
average(Angle a, Angle b, Angle c)
Obtains the average of three angles.static Angle
clamp(Angle value, Angle min, Angle max)
Limits a specified angle to be within a specified minimum and maximum.int
compareTo(Angle angle)
Compares thisAngle
with another.double
cos()
Obtains the cosine of this angle.double
cosHalfAngle()
static boolean
crossesLongitudeBoundary(Angle angleA, Angle angleB)
Angle
divide(double divisor)
Divides this angle bydivisor
.double
divide(Angle angle)
Divides this angle by another angle.boolean
equals(java.lang.Object o)
static Angle
fromDegrees(double degrees)
Obtains an angle from a specified number of degrees.static Angle
fromDegreesLatitude(double degrees)
static Angle
fromDegreesLongitude(double degrees)
static Angle
fromDMdS(int degrees, double minutes)
Obtain an angle from a given number of positive degrees and decimal minutes.static Angle
fromDMS(int degrees, int minutes, int seconds)
Obtain an angle from a given number of positive degrees, minutes and seconds.static Angle
fromDMS(java.lang.String dmsString)
Obtain an angle from a degrees, minute and seconds character string.static Angle
fromRadians(double radians)
Obtains an angle from a specified number of radians.static Angle
fromRadiansLatitude(double radians)
static Angle
fromRadiansLongitude(double radians)
static Angle
fromXY(double x, double y)
Obtains an angle from rectangular coordinates.double
getDegrees()
Retrieves the size of this angle in degrees.double
getRadians()
Retrieves the size of this angle in radians.long
getSizeInBytes()
Obtains the amount of memory thisAngle
consumes.int
hashCode()
static boolean
isValidLatitude(double value)
static boolean
isValidLongitude(double value)
static Angle
max(Angle a, Angle b)
static Angle
midAngle(Angle a1, Angle a2)
Obtains the average of two angles.static Angle
min(Angle a, Angle b)
static Angle
mix(double amount, Angle value1, Angle value2)
Linearly interpolates between two angles.Angle
multiply(double multiplier)
Multiplies this angle bymultiplier
.Angle
normalize()
static Angle
normalizedAngle(Angle unnormalizedAngle)
static double
normalizedDegrees(double degrees)
static double
normalizedDegreesLatitude(double degrees)
static double
normalizedDegreesLongitude(double degrees)
Angle
normalizedLatitude()
static Angle
normalizedLatitude(Angle unnormalizedAngle)
Angle
normalizedLongitude()
static Angle
normalizedLongitude(Angle unnormalizedAngle)
double
sin()
Obtains the sine of this angle.double
sinHalfAngle()
Angle
subtract(Angle angle)
Obtains the difference of these two angles.Angle
subtractDegrees(double degrees)
Angle
subtractRadians(double radians)
double
tanHalfAngle()
Obtains the tangent of half of this angle.java.lang.String
toDecimalDegreesString(int digits)
Forms a decimal degreesString
representation of thisAngle
.double[]
toDMS()
java.lang.String
toDMSString()
Obtains aString
representation of thisAngle
formatted as degrees, minutes and seconds integer values.java.lang.String
toDMString()
Obtains aString
representation of thisAngle
formatted as degrees and decimal minutes.java.lang.String
toFormattedDMSString()
java.lang.String
toString()
Obtains aString
representation 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
x
andy
.
-
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
andseconds
. - 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 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.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, 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 ifdivisor
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, somidAngle(m, n)
andmidAngle(n, m)
are equivalent.- Parameters:
a1
- the first angle.a2
- the second angle.- Returns:
- the average of
a1
anda2
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
anda3
- Throws:
java.lang.IllegalArgumentException
- ifa
orb
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
anda3
. - Throws:
java.lang.IllegalArgumentException
- ifa
,b
orc
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
andvalue2
.
-
compareTo
public final int compareTo(Angle angle)
Compares thisAngle
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 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 aString
representation of this angle.- Overrides:
toString
in 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 degreesString
representation 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 aString
representation of thisAngle
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 aString
representation of thisAngle
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 thisAngle
consumes.- Returns:
- the memory footprint of this angle in bytes.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-