]> git.mxchange.org Git - flightgear.git/blob - tests/test-up.cxx
Add elevator trim tab position logging.
[flightgear.git] / tests / test-up.cxx
1 // do some test relating to the concept of "up"
2
3 #include <simgear/compiler.h>
4
5 #include STL_IOSTREAM
6
7 #include <plib/sg.h>
8
9 #include <simgear/constants.h>
10 #include <simgear/math/sg_geodesy.hxx>
11
12 SG_USING_STD(cout);
13 SG_USING_STD(endl);
14
15 int main() {
16     // for each lat/lon given in goedetic coordinates, calculate
17     // geocentric coordinates, cartesian coordinates, the local "up"
18     // vector (based on original geodetic lat/lon), as well as the "Z"
19     // intercept (for which 0 = center of earth)
20
21
22     double lon = 0;
23     double alt = 0;
24
25     for ( double lat = 0; lat <= 90; lat += 5.0 ) {
26         cout << "lon = " << lon << "  geod lat = " << lat;
27
28         double sl_radius, lat_geoc;
29         sgGeodToGeoc( lat * SGD_DEGREES_TO_RADIANS, alt, &sl_radius, &lat_geoc );
30         cout << "  geoc lat = " << lat_geoc * SGD_RADIANS_TO_DEGREES << endl;
31
32         Point3D pgd( lon * SGD_DEGREES_TO_RADIANS, lat * SGD_DEGREES_TO_RADIANS, 0.0 );
33         Point3D pc = sgGeodToCart( pgd );
34         cout << "  cartesian = " << pc << endl;
35
36         sgdMat4 GEOD_UP;
37         sgdVec3 geod_up;
38         sgdMakeRotMat4( GEOD_UP, lon, 0.0, -lat );
39         sgdSetVec3( geod_up, GEOD_UP[0][0], GEOD_UP[0][1], GEOD_UP[0][2] );
40         cout << "  geod up = " << geod_up[0] << ", " << geod_up[1] << ", "
41              << geod_up[2] << endl;
42
43         sgdMat4 GEOC_UP;
44         sgdVec3 geoc_up;
45         sgdMakeRotMat4( GEOC_UP, lon, 0.0, -lat_geoc * SGD_RADIANS_TO_DEGREES );
46         sgdSetVec3( geoc_up, GEOC_UP[0][0], GEOC_UP[0][1], GEOC_UP[0][2] );
47         cout << "  geoc up = " << geoc_up[0] << ", " << geoc_up[1] << ", "
48              << geoc_up[2] << endl;
49
50         double slope = geod_up[2] / geod_up[0];
51         double intercept = pc.z() - slope * pc.x();
52         cout << "  Z intercept (based on geodetic up) = " << intercept << endl;
53
54         slope = geoc_up[2] / geoc_up[0];
55         intercept = pc.z() - slope * pc.x();
56         cout << "  Z intercept (based on geocentric up) = " << intercept << endl;
57
58    }
59
60     return 0;
61 }