faa.tg.units
Class TrueBearing

java.lang.Object
  extended by faa.tg.units.AMeasure
      extended by faa.tg.units.Angle
          extended by faa.tg.units.TrueBearing
All Implemented Interfaces:
HasText, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<AMeasure>
Direct Known Subclasses:
GroundTrackHeading, TrueHeading, WindDirection

public class TrueBearing
extends Angle

 TrueBearing represents the object for measuring the direction of travel
 from one position to another, as an angle measured clockwise from true
 north.
 TrueBearing values are between 0 and 360 degrees inclusive (0 == 360).
 Bearing is expressed in units of degrees from North (North = 0.0 deg.).
 Furthermore, East = 90 deg., South = 180 deg., and West = 270 degrees.

  NOTE: Does not define add(TrueBearing) and sub(TrueBearing) because a
        TrueBearing plus a turn Angle will yield another TrueBearing.
        It doesn't really make sense to add a bearing to a bearing.
        However, this means that when you call add(Angle) or sub(Angle)
        you must cast the result back to a TrueBearing.
        And it is appropriate for a bearing minus a bearing to return a
        turn Angle, but calcTurnAngle(start, end) is provided to correctly
        normalize value.
 
See section 5.6 of the Detailed Design Document for a discussion of design issues.

See the source: TrueBearing.java

Version:
$Id: TrueBearing.java,v 3.8 2009/01/09 22:02:57 danaw Exp $
Author:
Tim Kimmet (modeled after Robert G. Oliver's Units Classes)
See Also:
Units.radians, AUnits, AMeasure, TrueHeading, GroundTrackHeading, MagneticHeading, Serialized Form

Field Summary
static java.lang.String CVS_VERSION_ID
          The CVS Version ID
static TrueBearing DEG_180
           
static TrueBearing DEG_270
           
static TrueBearing DEG_30
           
static TrueBearing DEG_360
           
static TrueBearing DEG_5
           
static TrueBearing DEG_60
           
static TrueBearing DEG_90
           
(package private) static long serialVersionUID
           
 
Fields inherited from class faa.tg.units.Angle
D180_DIV_PI, DEG_1, DEG_330, DEG_NEG180, DEG_NEG270, DEG_NEG30, DEG_NEG5, DEG_NEG90, DEG_PER_RAD, NEG_NINETY_DEG, NEG_ONEEIGHTY_DEG, NINETY_DEG, ONEEIGHTY_DEG, PI, PI_DIV_180, PI_DIV_2, PI_DIV_4, PI_MUL_2, PI_MUL_4, RAD_PER_DEG, THIRTY_DEG, THREETHIRTY_DEG, TWOSEVENTY_DEG, ZERO
 
Fields inherited from class faa.tg.units.AMeasure
DEC0, DEC0_, DEC00, DEC000, DEC1, DEC1_, DEC12, DEC12_, DEC1L, DEC1L_, DEC2, DEC2_, DEC3, DEC3_, DEC4, DEC4_, DEC5, DEC5_, DEC6, DEC6_, DEC7, DEC7_, DEC9, DEC9_, itsValue, TIME_FRACTION
 
Constructor Summary
TrueBearing(Angle angle)
          Constructs a TrueBearing with a bearing equivalent to the given angle.
TrueBearing(double theValue, AngleUnits theUnits)
          Constructor for the TrueBearing class.
TrueBearing(java.lang.String dmsStr)
          Constructor for TrueBearing that parses a parameter string to determine its value.
 
Method Summary
static Angle calcTurnAngle(TrueBearing start, TrueBearing end)
          This subtraction method returns the turn Angle created by subtracting the start TrueBearing from the end TrueBearing.
 boolean eq(TrueBearing theMeasure)
          This method provides a test for equality: for TrueBearings, a normalized value of 0 is equal to a normalized value of 360.
 boolean ge(TrueBearing theMeasure)
          This method provides a test for greater than / equal to.
 java.lang.String getFuzzyString()
          Returns a string of N, NE, E, SE, S, SW, W, or NW depending on the value.
 boolean gt(TrueBearing theMeasure)
          This method provides a test for greater than.
 boolean le(TrueBearing theMeasure)
          This method provides a test for less than / equal to.
 boolean lt(TrueBearing theMeasure)
          This method provides a test for less than.
static void main(java.lang.String[] args)
           
protected static double normalizeRange(double value, AUnits units)
          Normalizes the TrueBearing value to be >= 0 and <= 360.
 double ratio(TrueBearing val)
          This division method produces a dimensionless ratio of like measures.
 TrueBearing reciprocal()
          Constructs a value that has a bearing equivalent to the reciprocal of this bearing.
 TrueBearing sub(TrueBearing subtrahend)
          This subtraction method subtracts a value with like units.
 java.lang.String toString()
          Returns the String representation of this object in its original form.
static TrueBearing toTrueBearing(org.w3c.dom.Element hdgElem)
          Creates a TrueBearing from an XML element containing AttributeNodes for a bearing's units and value; if a type is also specified a type of "T" or "True" will return a TrueHeading for that value, or a type of "G" or "Ground" will return a GroundTrackHeading.
 
Methods inherited from class faa.tg.units.Angle
abs, add, aeq, as, average, cos, diff, eq, ge, gt, isBetween, le, lt, parseDmsString, ratio, reciprocalAngle, removeDelimiters, sin, sub, tan, toDmsString, toRadialString, toText
 
Methods inherited from class faa.tg.units.AMeasure
absoluteValue, add, as, as, clone, compareTo, debug, div, eq, equals, ge, getAUnit, getCanonicalUnit, getCanonicalValue, getInitialUnit, getUnitClass, gt, hashCode, isBetween, le, lt, mul, ratio, sub, toAMeasure, toString, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

CVS_VERSION_ID

public static final java.lang.String CVS_VERSION_ID
The CVS Version ID

See Also:
Constant Field Values

DEG_5

public static final TrueBearing DEG_5

DEG_30

public static final TrueBearing DEG_30

DEG_60

public static final TrueBearing DEG_60

DEG_90

public static final TrueBearing DEG_90

DEG_180

public static final TrueBearing DEG_180

DEG_270

public static final TrueBearing DEG_270

DEG_360

public static final TrueBearing DEG_360
Constructor Detail

TrueBearing

public TrueBearing(double theValue,
                   AngleUnits theUnits)
Constructor for the TrueBearing class.

Parameters:
theValue - the magnitude of TrueBearing as a double
theUnits - the units of the value that will be stored (ex: rad)

TrueBearing

public TrueBearing(Angle angle)
Constructs a TrueBearing with a bearing equivalent to the given angle.

Parameters:
angle - The angle that will be used to create the true bearing.

TrueBearing

public TrueBearing(java.lang.String dmsStr)
            throws java.lang.NumberFormatException
Constructor for TrueBearing that parses a parameter string to determine its value. The String may be in one of the following formats:
   ddd-mm-ss.sss     ddd-mm-ss     ddd-mm.mmm     ddd-mm     ddd.ddd
   dd-mm-ss.sss      dd-mm-ss      dd-mm.mmm      dd-mm      dd.ddd

   ddd:mm:ss.sss     ddd:mm:ss     ddd:mm.mmm     ddd:mm     ddd
   dd:mm:ss.sss      dd:mm:ss      dd:mm.mmm      dd:mm      dd

   dddmmss.sss       dddmmss       dddmm.mmm      dddmm
   ddmmss.sss        ddmmss        ddmm.mmm       ddmm
 
In addition, the string may start or end with one of the following hemisphere designation characters:
     N      S      E      W      +      -
 
Note: the degrees field must have either 2 or 3 digits; minutes and seconds fields (not including decimal fraction) must be 2 digits.

Parameters:
dmsStr - A String in degrees:minutes:seconds format. If in [D]DD:MM:SS, the string should start or end with a N-S, E-W or +/- direction designator.
Throws:
java.lang.NumberFormatException - If the string could not be parsed.
See Also:
Angle.parseDmsString(String)
Method Detail

calcTurnAngle

public static Angle calcTurnAngle(TrueBearing start,
                                  TrueBearing end)
This subtraction method returns the turn Angle created by subtracting the start TrueBearing from the end TrueBearing. The result will be a positive Angle if the turn was a right turn and a negative Angle if the turn is a left turn.

The turn measured from the heading differences must be less than 180 degrees, so that turns that cross the 360 degree direction boundary can be detected (since the direction of turn is not specified).

Parameters:
start - The starting direction.
end - The ending direction.
Returns:
An Angle equal to this value minus the parameter value.

normalizeRange

protected static double normalizeRange(double value,
                                       AUnits units)
Normalizes the TrueBearing value to be >= 0 and <= 360. An eq() test for 0 degrees and 360 degrees will result in true<\b>.


toTrueBearing

public static TrueBearing toTrueBearing(org.w3c.dom.Element hdgElem)
                                 throws java.lang.IllegalArgumentException,
                                        org.w3c.dom.DOMException
Creates a TrueBearing from an XML element containing AttributeNodes for a bearing's units and value; if a type is also specified a type of "T" or "True" will return a TrueHeading for that value, or a type of "G" or "Ground" will return a GroundTrackHeading. If node has no value text, returns null.

Parameters:
hdgElem - Bearing Element with attributes for units and value (and possibly type).
Returns:
Value described by element or null if element is empty.
Throws:
org.w3c.dom.DOMException - XML construction error.
java.lang.IllegalArgumentException - XML did not correctly specify bearing.
java.lang.NullPointerException - TrueBearing element was null.

reciprocal

public TrueBearing reciprocal()
Constructs a value that has a bearing equivalent to the reciprocal of this bearing. If a subclass of TrueBearing is used the value returned is of the type of that subclass.


sub

public TrueBearing sub(TrueBearing subtrahend)
This subtraction method subtracts a value with like units. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Parameters:
subtrahend - The unit of measure to subtract from this measure.
Returns:
A new TrueBearing equal to this value minus the parameter value.

ratio

public double ratio(TrueBearing val)
This division method produces a dimensionless ratio of like measures.

Returns:
the ratio of the two measures

eq

public boolean eq(TrueBearing theMeasure)
This method provides a test for equality: for TrueBearings, a normalized value of 0 is equal to a normalized value of 360.

It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns boolean indicating whether values are equal.

lt

public boolean lt(TrueBearing theMeasure)
This method provides a test for less than. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns whether this value is less than the given value.

gt

public boolean gt(TrueBearing theMeasure)
This method provides a test for greater than. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns whether this value is greater than the given value.

ge

public boolean ge(TrueBearing theMeasure)
This method provides a test for greater than / equal to. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns result of test for greater than or equal to.

le

public boolean le(TrueBearing theMeasure)
This method provides a test for less than / equal to. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns result of test for less than or equal to.

toString

public java.lang.String toString()
Returns the String representation of this object in its original form.

Overrides:
toString in class Angle
Returns:
Returns a string containing the canonical value of the bearing.
See Also:
Units

getFuzzyString

public java.lang.String getFuzzyString()
Returns a string of N, NE, E, SE, S, SW, W, or NW depending on the value.


main

public static void main(java.lang.String[] args)