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