/** * Navigation Waypoint Class for Rob's Moving Map package * @author Robert J Morton * @version 16 December 1997 modified 06 April 2010 */ /* 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. */ class waypnt implements navconst { private static int NWP = 500, // maximum permitted number of waypoints nwp = 0; // current number of waypoints 'on-file' private double Lng, // waypoint's longitude Lat, // waypoint's latitude Dst, // waypoint's current distance from aircraft DST, // distance to next waypoint PWD, // distance from previous waypoint Brg, // bearing from point 'p' of point 'q' rBrg, // bearing of waypoint from aircraft tBrg, // bearing of aircraft from waypoint InRad, // bearing from this waypoint to previous waypoint OutRad, // bearing from this waypoint to next waypoint DL, //max allowed perpendicular drift from inbound radial RunHdg = 0, // runway heading (only for destination 'waypoint') Range = 150 / KPR; // waypoint's range of influence (radio range) 150km private boolean Dest = false; // indicates if this waypoint is the destination private String Name = ""; // name of waypoint private static waypnt NWP[], // array of references to all the waypoints cw; // reference of current waypoint private waypnt pw = null, // reference of previous waypoint nw = null; // reference of next waypoint private aircraft ac; // reference to current aircraft object private dandb db; /* reference to the distance and bearing computation object */ waypnt(double lat, double lng, String n, aircraft ac, dandb db) { if(nwp < NWP) { // if max number of waypoints not yet created this.ac = ac; // reference to aircraft object this.db = db; // reference to the distance and bearing object Name = n; // set up its name Lat = lat;; // set up its latitude & longitude Lng = lng; // set up its 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 // compute distance and bearings and get error code int ec = db.vincenty( ac.getLat(), // latitude of aircraft ac.getLng(), // longitude of aircraft Lat, // latitude of this waypoint Lng // longitude of this waypoint ); if(ec == 0) { // provided no error occurred within dandb() /* Provided the distance isn't zero, convert it from metres to mean Earth-radians then get both forward and back azimuths. Otherwise, the points are coincident, so leave azimuths as they were last time. */ if((Dst = db.getDist()) > 0) { Dst /= 6366197.723857773; rBrg = db.getForwardAzimuth(); tBrg = db.getBackAzimuth(); } if(Dst < 1) // don't consider waypoints beyond 1 Earth-radian return true; } return false; // an error occurred or waypoint beyond 1 Earth-radian } /* The Vincenty Method for computing distance and bearings returns distance in metres. Within this moving map navigator package, distances are handled in mean Earth-radians. The mean Earth-radian is precise on the spherical model of the Earth used in the (far less accurate) Haversine Method of computing distance and bearings (which was used previously). The mean Earth-radian is not quite so meaningful for the ellipsoidal model of the Earth used by the Vincenty Method. Nevertheless, because in this program the mean Earth-radian is arrived at by dividing the metric distance (re- turned by the Vincenty Method) by a fixed constant, it does represent a fixed and consistent measure here. The reason mean Earth-radians are used within this package is that the single conversion from metres to mean Earth-radians above avoids multiple conversions in the computations that update the aircraft's position in terms of latitude and longitude increments. */ waypnt getPrev() {return pw;} // return ref to previous waypoint in route waypnt getNext() {return nw;} // return ref to next waypoint in route 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;} // diste from this waypoint to next waypoint double getPWD() {return PWD;} // dist from previous waypoint to this one double getDL() {return DL;} // max allowed drift from inbound radial void setDL(double x) {DL = x;} // set max allowed drift from Inbound Radial String getName() {return Name;} // get the current waypoint's name double getrBrg() {return rBrg;} // get bearing of waypoint from aircraft double gettBrg() {return tBrg;} // get bearing of aircraft from waypoint void setPrev(waypnt x) {pw = x;} // set reference to previous waypoint void setNext(waypnt x) {nw = x;} // set reference to next waypoint boolean getDest() {return Dest;} // return the 'is destination' flag void setInRad(double x) {InRad = x;} // set bearing to previous waypoint void setDest(boolean x) {Dest = x;} // set the 'is destination' flag double getInRad() { return InRad; // return bearing to previous waypoint from this one } double getRange() { return Range; // max dist at which waypoint provides radio DandB } double getOutRad() { return OutRad; // return bearing of next waypoint from this one } double getRunHdg() { return RunHdg; // return the runway heading (for destination) } 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 setOutRad(double x) {OutRad = x;} //set bearing to next waypoint 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 waypoint 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' static void killAll() { // kill all waypoints for(int i = 0; i < NWP; i++) // for each possible waypoint installed WP[i] = null; // set each waypoint reference to null cw = null; // set current waypoint reference to null nwp = 0; // set number of installed waypoints to zero } }