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