| 1 | // Calculate ILS heading |
| 2 | |
| 3 | #ifdef HAVE_CONFIG_H |
| 4 | # include <config.h> |
| 5 | #endif |
| 6 | |
| 7 | #include <simgear/compiler.h> |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | |
| 12 | #include <iostream> |
| 13 | #include <string> |
| 14 | |
| 15 | #include <simgear/math/sg_geodesy.hxx> |
| 16 | |
| 17 | |
| 18 | using std::string; |
| 19 | using std::cout; |
| 20 | using std::endl; |
| 21 | |
| 22 | int main( int argc, char **argv ) { |
| 23 | |
| 24 | if ( argc != 9 ) { |
| 25 | cout << "Wrong usage" << endl; |
| 26 | } |
| 27 | |
| 28 | double loc_lat = atof( argv[1] ); |
| 29 | double loc_lon = atof( argv[2] ); |
| 30 | string dir = argv[3]; |
| 31 | double rwy_lat = atof( argv[4] ); |
| 32 | double rwy_lon = atof( argv[5] ); |
| 33 | double rwy_hdg = atof( argv[6] ); |
| 34 | double rwy_len = atof( argv[7] ) * SG_DEGREES_TO_RADIANS; |
| 35 | // double rwy_wid = atof( argv[8] ); |
| 36 | |
| 37 | if ( dir == "FOR" ) { |
| 38 | rwy_hdg += 180.0; |
| 39 | if ( rwy_hdg > 360.0 ) { |
| 40 | rwy_hdg -= 360.0; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // calculate runway threshold point |
| 45 | double thresh_lat = 0.0, thresh_lon = 0.0, return_az = 0.0; |
| 46 | geo_direct_wgs_84 ( 0.0, rwy_lat, rwy_lon, rwy_hdg, |
| 47 | rwy_len / 2.0, &thresh_lat, &thresh_lon, &return_az ); |
| 48 | cout << "Threshold = " << thresh_lat << "," << thresh_lon << endl; |
| 49 | |
| 50 | // calculate distance from threshold to localizer |
| 51 | double az1, az2, dist_m; |
| 52 | geo_inverse_wgs_84( 0.0, loc_lat, loc_lon, thresh_lat, thresh_lon, |
| 53 | &az1, &az2, &dist_m ); |
| 54 | cout << "Distance = " << dist_m << endl; |
| 55 | |
| 56 | // back project that distance along the runway center line |
| 57 | double nloc_lat = 0.0, nloc_lon = 0.0; |
| 58 | geo_direct_wgs_84 ( 0.0, thresh_lat, thresh_lon, rwy_hdg + 180.0, |
| 59 | dist_m, &nloc_lat, &nloc_lon, &return_az ); |
| 60 | printf("New localizer = %.6f %.6f\n", nloc_lat, nloc_lon ); |
| 61 | |
| 62 | return 0; |
| 63 | } |