/** * Navigation Waypoint Class for Rob's Moving Map package * @author Robert J Morton * @version 16 December 1997 modified 06 April 2010 */ /* [new] called by loader.java 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' //array of references to all the waypoints private static waypnt[] WP = new waypnt[NWP]; private static waypnt 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 distance & bearing computation object private String Name = ""; // name of waypoint private double Lng, // waypoint's longitude Lat, // waypoint's latitude Dst = 0, // 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 RunHdg = 0, // runway heading (used only for destination 'waypoint') DL, // max allowed perpendicular drift from inbound radial Range = 150 / KPR; // waypoint's range of influence (radio range) 150km private int Hgt = 0; // waypoint's height private boolean Dest = false, // true if this waypoint is the destination Frst = false; // true if this is the first waypoint in the route // CONSTRUCT THE WAYPOINT'S DATA waypnt(double lat, double lng, int hgt, 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 Lng = lng; // set up its longitude Hgt = hgt; // set the waypoint's height WP[nwp++] = this; // Put the new waypoint's reference in the } // next element of the references array. } /* MAIN DISTANCE AND BEARING COMPUTATION BETWEEN AIRCRAFT AND WAYPOINT 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 (returned 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. */ boolean DandB() { /* Compute distance and bearings (and get error code) from latitude & longitude of aircraft, plus latitude & longitude of this waypoint. */ int ec = db.vincenty(ac.getLat(),ac.getLng(),Lat,Lng); if(ec == 0) { // provided no error occurred within dandb() /* Provided distance isn't zero, convert distance from metres to mean Earth-radians then calculate both forward and back azimuths. If distance = 0, the points must be coincident so leave the azimuths as they were last time. */ double x; if((x = db.getDist()) > 0) { Dst = x / MPR; rBrg = db.getForwardAzimuth(); tBrg = db.getBackAzimuth(); } if(Dst < 1) // Don't consider waypoints beyond 1 Earth-radian. return true; } return false; } //METHOD-PAIRS TO PUT & GET VARIOUS PARAMETERS PERTAINING TO THIS WAYPOINT void setNext(waypnt x) {nw = x;} // set reference to next waypoint waypnt getNext() {return nw;} // get reference to next waypoint in route void setPrev(waypnt x) {pw = x;} // set reference to previous waypoint waypnt getPrev() {return pw;} // get reference to prev waypoint in route void setDL(double x) {DL = x;} // set max allowed drift from Inbound Radial double getDL() {return DL;} // max allowed drift from inbound radial void setPWD(double x) {PWD = x;} // set prev waypoint's dist from this one double getPWD() {return PWD;} // get dist from prev waypoint to this one void setInRad(double x) {InRad = x;} // set bearing to previous waypoint double getInRad() {return InRad;} // get bearing to prev waypoint void setOutRad(double x) {OutRad = x;} // set bearing to next waypoint double getOutRad() {return OutRad;} // get bearing of next waypoint void setDest(boolean x) {Dest = x;} // set the 'is destination' flag boolean getDest() {return Dest;} // get the 'is destination' flag void setFrst(boolean x) {Frst = x; } // set the 'is origin' flag boolean getFrst() {return Frst;} // get the 'is origin' flag void setDST(double x) {DST = x;} // set distance from this waypoint to next double getDST() {return DST;} // get distance from this waypoint to next static void setCurrent(waypnt w) {cw = w;} // set ref of current waypoint static waypnt getCurrent() {return cw;} // get ref of current waypoint //READ-ONLY METHODS FOR GETTING VARIOUS PARAMETERS FOR CURRENT WAYPOINT String getName() {return Name;} // get waypoint's current distance double getLat() {return Lat;} // get waypoint's latitude double getLng() {return Lng;} // get waypoint's longitude double getDst() {return Dst;} // distance from aircraft to next waypoint void resetDst() {Dst = 0;} // dist from aircraft to current waypoint double getrBrg() {return rBrg;} // get bearing of waypoint from aircraft double gettBrg() {return tBrg;} // get bearing of aircraft from waypoint int getHgt() {return Hgt;} // get height of current waypoint double getRunHdg() {return RunHdg;} // get runway heading (for destination) double getRange() {return Range;} // max radio dist for waypoint DandB /* Static access to the total number of waypoints on-file and to any waypoint's reference, given its list number. */ static int getTotal() {return nwp;} static waypnt getRef(int n) {return WP[n];} /* KILL ALL WAYPOINTS: for each possible waypoint installed, set each waypoint reference to null. Then set current waypoint refer- ence to null and the number of installed waypoints to zero: */ static void killAll() { for(int i = 0; i < NWP; i++) WP[i] = null; cw = null; nwp = 0; } static void purge() {nwp = 0;} // set to 'no waypoints installed' }