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