|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.measure.Angle
public class Angle
An angle, or measure of arc.
Positive angles are measured in a counter-clockwise direction; negative angles in a clockwise direction.
Note About Accuracy
This class originally used java's primitive double type
for storage and calculation. Certain transformations, though,
led to results that where not accurate enough for many purposes.
Because of that, the internal references to double
have been replaced with references to BigDecimal
.
Version Info:
$Revision: 1816 $ |
$Date: 2008-12-23 10:21:00 -0700 (Tue, 23 Dec 2008) $ |
$Author: dharland $ |
Constructor Summary | |
---|---|
Angle()
Creates a new angle of zero degrees. |
|
Angle(BigDecimal degrees)
Creates a new angle of degrees degrees. |
|
Angle(BigDecimal magnitude,
ArcUnits units)
Creates a new angle with the given magnitude and units. |
|
Angle(String degrees)
Creates a new angle of degrees degrees. |
|
Angle(String magnitude,
ArcUnits units)
Creates a new angle with the given magnitude and units. |
Method Summary | |
---|---|
Angle |
add(Angle other)
Adds the other angle to this one. |
Angle |
add(BigDecimal amount)
Adds the amount , of the same units as this angle, to this angle. |
Angle |
add(String amount)
Adds the amount , of the same units as this angle, to this angle. |
static Angle |
arcCosine(double cosine)
Returns a new angle whose cosine is cosine. |
static Angle |
arcSine(double sine)
Returns a new angle whose sine is sine. |
static Angle |
arcTangent(double tangent)
Returns a new angle whose tangent is tangent. |
Angle |
clone()
Returns an angle that is equal to this one. |
int |
compareTo(Angle otherAngle)
Compares this angle with the otherAngle for order. |
Angle |
convertTo(ArcUnits newUnits)
Converts this angle to the new units. |
Angle |
convertToMinAbsValueNormal()
Converts this angle to the normalized value that has the smaller absolute value. |
Angle |
convertToNegativeNormal()
Converts this angle to a negative normalized angle. |
Angle |
convertToPositiveNormal()
Converts this angle to a positive normalized angle. |
double |
cosecant()
Returns the cosecant of this angle. |
double |
cosine()
Returns the cosine of this angle. |
double |
cotangent()
Returns the cotangent of this angle. |
Angle |
divideBy(BigDecimal divisor)
Divides this angle by divisor . |
Angle |
divideBy(String divisor)
Divides this angle by divisor . |
boolean |
equals(Object o)
Returns true if o is equal to this angle. |
int |
getFullCircles()
Returns the number of full circles made by this angle. |
ArcUnits |
getUnits()
Returns the units of this angle. |
BigDecimal |
getValue()
Returns the magnitude of this angle. |
int |
hashCode()
Returns a hash code value for this angle. |
boolean |
isClockwise()
Returns true if this angle is traversed in a clockwise direction. |
boolean |
isInDefaultState()
Returns true if this angle is in its default state, no matter how it got there. |
boolean |
isInfinite()
Returns true if the magnitude of this angle approaches infinity. |
boolean |
isNegative()
Returns true if the value of this angle is less than zero. |
boolean |
isPositive()
Returns true if the value of this angle is greater than zero. |
Angle |
multiplyBy(BigDecimal multiplier)
Multiplies this angle by multiplier . |
Angle |
multiplyBy(String multiplier)
Multiplies this angle by multiplier . |
Angle |
negate()
Negates the value of this angle. |
Angle |
normalize()
Normalizes this angle so that its absolute value is less than that of a full circle. |
static Angle |
parse(String angleString)
Returns a new angle based on angleString . |
void |
reset()
Resets this angle so that it is equal to a angle created via the no-argument constructor. |
Angle |
reverseDirection()
Reverses the direction of this angle. |
double |
secant()
Returns the secant of this angle. |
void |
set(BigDecimal value,
ArcUnits units)
Sets the magnitude and units of this angle. |
void |
set(String angleString)
Sets the value and units of this angle based on angleString . |
void |
set(String value,
ArcUnits units)
Sets the magnitude and units of this angle. |
void |
setUnits(ArcUnits newUnits)
Sets the units of this angle to newUnits . |
void |
setValue(BigDecimal newValue)
Sets the magnitude of this angle to newValue . |
void |
setValue(String newValue)
Sets the magnitude of this angle to newValue . |
double |
sine()
Returns the sine of this angle. |
Angle |
subtract(Angle other)
Subtracts the other angle from this one. |
Angle |
subtract(BigDecimal amount)
Subtracts the amount , of the same units as this angle, from this
angle. |
Angle |
subtract(String amount)
Subtracts the amount , of the same units as this angle, from this
angle. |
double |
tangent()
Returns the tangent of this angle. |
Number[] |
toDms()
Returns a representation of this angle in degrees, minutes, and seconds. |
Number[] |
toHms()
Returns a representation of this angle in hours, minutes, and seconds. |
String |
toString()
Returns a text representation of this angle in its native units. |
String |
toString(int minFracDigits,
int maxFracDigits)
Returns a text representation of this angle in its native units. |
String |
toStringDms()
Returns a text representation of this angle in degrees, arc-minutes, and arc-seconds. |
String |
toStringDms(int minFracDigits,
int maxFracDigits)
Returns a text representation of this angle in degrees, arc-minutes, and arc-seconds. |
String |
toStringDmsHtml(int minFracDigits,
int maxFracDigits)
Returns a text representation of this angle in degrees, arc-minutes, and arc-seconds, with HTML-friendly symbols. |
String |
toStringHms()
Returns a text representation of this angle in hours, minutes, and seconds. |
String |
toStringHms(int minFracDigits,
int maxFracDigits)
Returns a text representation of this angle in hours, minutes, and seconds. |
String |
toStringHtml(int minFracDigits,
int maxFracDigits)
Returns a text representation of this angle in its native units, using an HTML-friendly symbol. |
BigDecimal |
toUnits(ArcUnits otherUnits)
Returns the magnitude of this angle in otherUnits . |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Angle()
public Angle(BigDecimal degrees)
degrees
degrees.
public Angle(String degrees)
degrees
degrees.
public Angle(BigDecimal magnitude, ArcUnits units)
public Angle(String magnitude, ArcUnits units)
Method Detail |
---|
public void reset()
public BigDecimal getValue()
public ArcUnits getUnits()
public final void set(BigDecimal value, ArcUnits units)
value
- the new magnitude for this angle.units
- the new units for this angle.public final void set(String value, ArcUnits units)
value
- the new magnitude for this angle.units
- the new units for this angle.public final void setValue(BigDecimal newValue)
newValue
.
Note that the units of this angle are unaffected by this method.
newValue
- the new magnitude for this angle.
NumberFormatException
- if newValue
is null.public final void setValue(String newValue)
newValue
.
Note that the units of this angle are unaffected by this method.
newValue
- the new magnitude for this angle.
NumberFormatException
- if newValue
is null.public final void setUnits(ArcUnits newUnits)
newUnits
.
Note that the value of this angle is unaffected by
this method. Contrast this with convertTo(ArcUnits)
.
newUnits
- the new units for this angle. If newUnits
is null
it will be treated as ArcUnits.getDefault()
.public void set(String angleString)
angleString
.
See parse(String)
for the expected format of
angleString
.
If the parsing fails, this angle will be kept in its current state.
angleString
- a string that will be converted into
an angle.
IllegalArgumentException
- if angleString
is not in
the expected form.public int getFullCircles()
For example, an angle of +60.0° has made zero full circles, an angle of -400.0° one full circle, and an angle of +900.0° two full circles.
public boolean isNegative()
public boolean isPositive()
public boolean isClockwise()
public boolean isInDefaultState()
An angle is in its default state if both its value and
its units are the same as those of an angle newly created via
the no-argument constructor
.
An angle whose most recent update came via the
reset
method is also in its default state.
public boolean isInfinite()
public Angle negate()
For example, if this angle is currently -45.0°,
it will be +45.0° after this call. The negation
here is a simple sign flip.
Contrast this with reverseDirection()
.
public Angle reverseDirection()
For example, if this angle is currently -45.0°,
it will be +315.0° after this call.
Contrast this with negate()
.
public Angle normalize()
For example, if this angle is currently 765.0°, it will be 45.0° after this call. Likewise, if this angle is currently -765.0°, it will be -45.0° after this call.
public Angle convertToPositiveNormal()
normalize()
)
and then by creating a positive angle, not by a
simple sign flip, but instead by reversing direction
to complete the circle.
For example, if this angle is currently -765.0°, it is first normalized to -45.0°. The result is then converted to a positive number by traveling the circle in the opposite direction, for a final result of +315°.
public Angle convertToNegativeNormal()
normalize()
)
and then by creating a negative angle not by a
simple sign flip, but instead by reversing direction
to complete the circle.
For example, if this angle is currently +765.0°, it is first normalized to +45.0°. The result is then converted to a negative number by traveling the circle in the opposite direction, for a final result of -315°.
public Angle convertToMinAbsValueNormal()
For example, if this angle is currently +920.0°, it is first normalized to +200.0°. By reversing direction, we wind up with an angle of -160.0°, which has a smaller absolute value than +200.0°, so that is our end result. For the special situations where the normalized value is either +180.0° or -180.0°, the original direction is preserved.
public Angle convertTo(ArcUnits newUnits)
After this method is complete this angle will have units of
units
and its value will have been converted
accordingly.
newUnits
- the new units for this angle.
If newUnits
is null an
IllegalArgumentException
will be thrown.
BigDecimal radians =
myAngle.convertTo(ArcUnits.RADIAN).getValue();
public BigDecimal toUnits(ArcUnits otherUnits)
otherUnits
.
Note that this method does not alter the state of this angle.
Contrast this with convertTo(ArcUnits)
.
otherUnits
- the units in which to express this angle's magnitude.
otherUnits
.public Number[] toDms()
public Number[] toHms()
public Angle add(Angle other)
other
angle to this one.
other
- an angle to be added to this one.
public Angle subtract(Angle other)
other
angle from this one.
other
- an angle to be subtracted from this one.
public Angle add(BigDecimal amount)
amount
, of the same units as this angle, to this angle.
amount
- the amount to add to this angle.
public Angle add(String amount)
amount
, of the same units as this angle, to this angle.
amount
- the amount to add to this angle.
public Angle subtract(BigDecimal amount)
amount
, of the same units as this angle, from this
angle.
amount
- the amount to subtract from this angle.
public Angle subtract(String amount)
amount
, of the same units as this angle, from this
angle.
amount
- the amount to subtract from this angle.
public Angle multiplyBy(BigDecimal multiplier)
multiplier
.
multiplier
- the number by which this angle should be multiplied.
public Angle multiplyBy(String multiplier)
multiplier
.
multiplier
- the number by which this angle should be multiplied.
public Angle divideBy(BigDecimal divisor)
divisor
.
divisor
- the number by which this angle should be divided.
public Angle divideBy(String divisor)
divisor
.
divisor
- the number by which this angle should be divided.
public double cosine()
public double sine()
public double tangent()
public double secant()
public double cosecant()
public double cotangent()
public static Angle arcCosine(double cosine)
cosine
- the value whose arc cosine is to be returned.
public static Angle arcSine(double sine)
sine
- the value whose arc sine is to be returned.
public static Angle arcTangent(double tangent)
tangent
- the value whose arc tangent is to be returned.
public static Angle parse(String angleString)
angleString
.
Valid Formats
Let I be the text representation of an integer.
Let R be the text representation of a real number.
Let w represent zero or more whitespace characters.
Let S be a valid units
symbol.
Format One: wRw. The given number will be defined to be
in units of degrees
. Examples:
hours
or degrees
.
The second S must be the symbol for either
minutes
or arc minutes
.
The final S must be the symbol for either
seconds
or arc seconds
.
Special Cases
An angleString
of null or "" (the empty
string) will not result in an IllegalArgumentException
,
but will instead return an angle of zero degrees.
angleString
- a string that will be converted into
an angle.
IllegalArgumentException
- if angleString
is not in
the expected form.public String toString()
toString
in class Object
public String toString(int minFracDigits, int maxFracDigits)
public String toStringHtml(int minFracDigits, int maxFracDigits)
public String toStringHms()
public String toStringHms(int minFracDigits, int maxFracDigits)
minFracDigits
- the minimum number of places after the decimal point
for the seconds field.maxFracDigits
- the maximum number of places after the decimal point
for the seconds field. If this value is less than zero,
no rounding or truncating will be performed.public String toStringDms()
public String toStringDms(int minFracDigits, int maxFracDigits)
minFracDigits
- the minimum number of places after the decimal point
for the seconds field.maxFracDigits
- the maximum number of places after the decimal point
for the seconds field. If this value is less than zero,
no rounding or truncating will be performed.public String toStringDmsHtml(int minFracDigits, int maxFracDigits)
minFracDigits
- the minimum number of places after the decimal point
for the seconds field.maxFracDigits
- the maximum number of places after the decimal point
for the seconds field. If this value is less than zero,
no rounding or truncating will be performed.public Angle clone()
clone
in class Object
public boolean equals(Object o)
o
is equal to this angle.
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(Angle otherAngle)
otherAngle
for order.
compareTo
in interface Comparable<Angle>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |