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