This class creates an object for each waypoint and geographic feature on the applet's 'Earth'. All of these objects represent cities. In reality, all the waypoints making up an air route would normally be some form of navigational aid such as a VOR station or ILS localiser. However, to make routes look more familiar to most people, city names and positions are used. It should be borne in mind that the three routes in this applet are fictitious. Aircraft do not really fly from city-centre to city-centre like this.
Perhaps the most important method in this waypoint class computes the aircraft's distance from the waypoint upon whose reference the method DandB() is invoked. It also computes the bearing of the waypoint from the aircraft and also the bearing of the aircraft from the waypoint. Note that on the ellipsoidal surface of the Earth, one bearing is not simply the other with 180° added as it would be on a flat plane. The actual distance and bearings are obtained by calls to methods in dandb.class.
/**
* Navigation Waypoint Class for my Moving Map package
* @author Robert J Morton
* @version 16 December 1997
*/
/* Provides the essentials of a waypoint, namely its position
and its range of influence. This class can be extended for
particular kinds of waypoint, eg: mountain, city, lake,
fork in a river, gas holder, tower whose co-ordinates are
known. Mainly, however a waypoint will be a purpose-built
radio aid such as a VOR, TACAN, ILS or marker beacon.
NOTE: This sperical geometry version of waypntpg has been
renamed from WayPntSG to simply WayPnt. */
class waypnt implements navconst {
private static int NWP = 100; //maximum permitted number of waypoints
private static int nwp = 0; //current number of waypoints 'on-file'
private static waypnt[] WP = new waypnt[NWP];//array of references to all the waypoints
private static waypnt cw; //reference of current waypoint
private waypnt pw = null; //reference of previous waypoint
private waypnt nw = null; //reference of next waypoint
private aircraft ac; //reference to current aircraft object
private String Name = ""; //name of waypoint
private double Lng; //waypoint's longitude
private double Lat; //waypoint's latitude
private double Dst; //waypoint's current distance from aircraft
private double DST; //distance to next waypoint
private double PWD; //distance from previous waypoint
private double Brg; //bearing from point 'p' of point 'q'
private double rBrg; //bearing of waypoint from aircraft
private double tBrg; //bearing of aircraft from waypoint
private double InRad; //bearing from this waypoint to previous waypoint
private double OutRad; //bearing from this waypoint to next waypoint
private double RunHdg = 0; //runway heading (used only for destination 'waypoint')
private boolean Dest = false; //indicates if this waypoint is the destination
private double DL; //max allowed perpendicular drift from inbound radial
private double Range = 150; //waypoint's range of influence (eg radio range) 150km
waypnt(double lat, double lng, String n) { //CONSTRUCT THE WAYPOINT'S DATA
if(nwp < NWP) { //if max number of waypoints not yet created
Name = n; //set up its name
Lat = lat; Lng = lng; //set up it latitude & longitude
WP[nwp++] = this; //Put the new waypoint's reference in the
} // next element of the references array.
}
boolean DandB() { //COMPUTE DISTANCE AND BEARING OF WAYPOINT
ac = aircraft.getCurrent(); //get reference to current aircraft object
if(!dandb.valid( //If aircraft > 1 minute of arc from North or South pole...
ac.getLat(), //current latitude of aircraft
Lat, //latitude of current waypoint
Lng - ac.getLng() //longitudinal difference between waypoint and aircraft
)
) return false; //use old values of distance and bearings
Dst = Math.abs(dandb.getDistance()); //get distance between aircraft and waypoint in kilometres
if(Double.isNaN(Dst)) return false; //ignore waypoint if it is antipodal
if(Dst > .1) { //Only trust bearings if distance > 100 metres
rBrg = ac.RatAng( //get the
dandb.getFwrdAzimuth() //forward bearing to the waypoint
); //and re-range it 0 to 2Pi
tBrg = ac.RatAng( //get the
dandb.getBackAzimuth() //bearing from waypoint to aircraft
); //and re-range it 0 to 2Pi
}
return true; //say results OK
}
waypnt getPrev() {return pw;} //return reference to previous waypoint in route
waypnt getNext() {return nw;} //return reference to next waypoint in route
String getName() {return Name;} //access to the waypoint's current distance
double getLat() {return Lat;} //access to the waypoint latitude
double getLng() {return Lng;} //access to the waypoint longitude
double getDst() {return Dst;} //distance from aircraft to next waypoint
double getDST() {return DST;} //distance from this waypoint to next waypoint
double getPWD() {return PWD;} //distance from previous waypoint to this one
double getrBrg() {return rBrg;} //return bearing of waypoint from aircraft
double gettBrg() {return tBrg;} //return bearing of aircraft from waypoint
double getInRad() {return InRad;} //return bearing to previous waypoint from this one
double getOutRad() {return OutRad;} //return bearing of next waypoint from this one
boolean getDest() {return Dest;} //return the 'is destination' flag
double getRunHdg() {return RunHdg;} //return the runway heading (for destination)
double getDL() {return DL;} //max allowed drift from inbound radial
double getRange() {return Range;} //max dist at which waypoint provides radio DandB
void setPrev(waypnt x) {pw = x;} //set reference to previous waypoint
void setNext(waypnt x) {nw = x;} //set reference to next waypoint
void setDST(double x) {DST = x;} //set next waypoint's distance from this waypoint
void setPWD(double x) {PWD = x;} //set previous waypoint's distance from this waypoint
void setInRad(double x) {InRad = x;} //set bearing to previous waypoint
void setOutRad(double x) {OutRad = x;} //set bearing to next waypoint
void setDest(boolean x) {Dest = x;} //set the 'is destination' flag
void setDL(double x) {DL = x;} //set max allowed drift from Inbound Radial
static waypnt getCurrent() {return cw;} //access to the reference of the current waypoint
static void setCurrent(waypnt w) {cw = w;} //set reference of the current waypoint
static int getTotal() {return nwp;} //return the total number of waypoints on-file
static waypnt getRef(int n) {return WP[n];} //return reference to waypoint given its number
static void purge() {nwp = 0;} //set to 'no waypoints installed'
}
/* Robert J Morton, the author of this program,
is a poor but Right Honourable Member of the
Ancient and Noble Order of the Long-term Unemployed.
Offers of work please to: robmorton@clara.net */