/** * Navigation Waypoint Class for Rob's Moving Map package * @author Robert J Morton YE572246C * @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 coord- inates 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 aircraft ac; // reference to current aircraft object private dandb db; // reference to dandb computation object // indicates if this waypoint is the destination private boolean Dest = false; private waypnt pw = null, // reference of previous waypoint nw = null; // reference of next waypoint private String Name = ""; // name of waypoint 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' InRad, // bearing from this waypoint to previous waypoint OutRad, // bearing from this waypoint to next waypoint rBrg, // bearing of waypoint from aircraft tBrg, // bearing of aircraft from waypoint DL, // max allowed perpendicular drift from inbound radial RunHdg = 0, // runway heading (used only for destination 'waypoint') // waypoint's range of influence (eg radio range) 150km Range = 150 / KPR; // CONSTRUCT THE WAYPOINT'S DATA 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; 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 the distance and bearings from the latitude & longitude of the aircraft and the latitude & longitude of this waypoint. Get any returned error code. */ int ec = db.vincenty(ac.getLat(),ac.getLng(),Lat,Lng); if(ec != 0) return false; // exit if error returned by dandb() /* Provided the distance is not zero, convert distance from metres to mean Earth-radians and get the forward & back azimuths. */ if((Dst = db.getDist()) > 0) { Dst /= 6366197.723857773; rBrg = db.getForwardAzimuth(); tBrg = db.getBackAzimuth(); } if(Dst > 1) return false; // ignore waypoints beyond 1 Earth-radian return true; } /* 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 comp- uting 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 consis- tent measure here. The reason mean Earth-radians are used within this pack- age 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. */ // Return the reference to the next/previous waypoint in the route waypnt getNext() {return nw;} waypnt getPrev() {return pw;} // Return the waypoint's current name/lattitude/longitude String getName() {return Name;} double getLat() {return Lat;} double getLng() {return Lng;} // Return the distance from the aircraft to the next waypoint double getDst() {return Dst;} // Return distance from this to next and from previous to this waypoint double getDST() {return DST;} double getPWD() {return PWD;} // Return bearing of waypoint from aircraft and aircraft from waypoint double getrBrg() {return rBrg;} double gettBrg() {return tBrg;} // Return bearings of previous and next waypoints from this waypoint double getInRad() {return InRad;} double getOutRad() {return OutRad;} // Get/set the state of the 'is destination' flag boolean getDest() {return Dest;} void setDest(boolean x) {Dest = x;} // Return the runway heading of the destination double getRunHdg() {return RunHdg;} // Get/set the maximum allowed drift from the inbound radial double getDL() {return DL;} void setDL(double x) {DL = x;} // Return the maximum distance at which the waypoint provides radio DandB double getRange() {return Range;} // Set reference to next/previous waypoint void setNext(waypnt x) {nw = x;} void setPrev(waypnt x) {pw = x;} // Set next/previous waypoint's distance from this waypoint void setDST(double x) {DST = x;} void setPWD(double x) {PWD = x;} //set bearing to next/previous waypoint void setOutRad(double x) {OutRad = x;} void setInRad(double x) {InRad = x;} // Get/set the reference of the current waypoint static waypnt getCurrent() {return cw;} static void setCurrent(waypnt w) {cw = w;} // Return the total number of waypoint on-file static int getTotal() {return nwp;} // Return a waypoint's reference given its number static waypnt getRef(int n) {return WP[n];} // Set to 'no waypoints installed' static void purge() {nwp = 0;} // Clear all waypoints static void killAll() { // for each possible waypoint installed set its reference to null for(int i = 0; i < NWP; i++) WP[i] = null; cw = null; // set current waypoint reference to null nwp = 0; // set number of installed waypoints to zero } }