Debian Codegraph @

test_suite/simgear_tests/math/test-up.cxx

raw symbols SCIP
1 // do some test relating to the concept of "up"
2
3 #include <iostream>
4
5 #include <simgear/math/sg_geodesy.hxx>
6
7 #include "testSGGeodesy.hxx"
8
9
10 using std::cout;
11 using std::endl;
12
13
14 // The test-up unit test.
15 void MathGeodesyTests::testUp()
16 {
17 // for each lat/lon given in goedetic coordinates, calculate
18 // geocentric coordinates, cartesian coordinates, the local "up"
19 // vector (based on original geodetic lat/lon), as well as the "Z"
20 // intercept (for which 0 = center of earth)
21
22
23 double lon = 0;
24 double alt = 0;
25 int i;
26 const int n = 19;
27 double lat[n] = {0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90};
28
29 // Hard coded expected results.
30 double lat_geoc_expected[n] = {
31 0,
32 4.96669608700923,
33 9.93439421027913,
34 14.9040671396528,
35 19.8766298623747,
36 24.8529125604827,
37 29.8336358098291,
38 34.8193887023496,
39 39.8106105519284,
40 44.8075767840180,
41 49.8103895262907,
42 54.8189733092144,
43 59.8330761504926,
44 64.8522761370246,
45 69.8759934364236,
46 74.9035074740039,
47 79.9339788099657,
48 84.9664750566862,
49 90
50 };
51 double cart_expected[n][3] = {
52 {6378137, 0, 0},
53 {6353866.26310279, 555891.26758132, 0},
54 {6281238.76737403, 1107551.86696002, 0},
55 {6160807.25190988, 1650783.32787306, 0},
56 {5993488.27326157, 2181451.33089075, 0},
57 {5780555.22988658, 2695517.17208404, 0},
58 {5523628.67081747, 3189068.5, 0},
59 {5224663.96230526, 3658349.09101875, 0},
60 {4885936.40630155, 4099787.43648327, 0},
61 {4510023.92403682, 4510023.92403682, 0},
62 {4099787.43648328, 4885936.40630155, 0},
63 {3658349.09101875, 5224663.96230526, 0},
64 {3189068.5, 5523628.67081747, 0},
65 {2695517.17208404, 5780555.22988658, 0},
66 {2181451.33089075, 5993488.27326157, 0},
67 {1650783.32787306, 6160807.25190988, 0},
68 {1107551.86696002, 6281238.76737403, 0},
69 {555891.26758132, 6353866.26310279, 0},
70 {3.90548253078665e-10, 6378137, 0}
71 };
72 double up_expected[n][3] = {
73 {6378137, 0, -0},
74 {6354027.82056206, 0, -552183.96002777},
75 {6281872.82960345, 0, -1100248.54773536},
76 {6162189.08803834, 0, -1640100.14019589},
77 {5995836.38389635, 0, -2167696.78782876},
78 {5784014.11472572, 0, -2679074.46295779},
79 {5528256.63929284, 0, -3170373.73538364},
80 {5230426.84020036, 0, -3637866.9093781},
81 {4892707.60007269, 0, -4077985.57220038},
82 {4517590.87884893, 0, -4487348.40886592},
83 {4107864.09120678, 0, -4862789.03770643},
84 {3666593.52237417, 0, -5201383.52320227},
85 {3197104.58692395, 0, -5500477.13393864},
86 {2702958.82600294, 0, -5757709.84149597},
87 {2187927.64927902, 0, -5971040.00711856},
88 {1655962.9523645, 0, -6138765.68235824},
89 {1111164.87081001, 0, -6259542.96102869},
90 {557747.059253584, 0, -6332400.86398617},
91 {3.91862092481447e-10, 0, -6356752.31424518}
92 };
93 double geod_intercept[n] = {
94 0,
95 552169.92020293,
96 1100137.4939038,
97 1639732.35699488,
98 2166847.86675177,
99 2677472.35586416,
100 3167719.66364641,
101 3633858.71206688,
102 4072341.90150465,
103 4479832.11012469,
104 4853228.0913901,
105 5189688.07642079,
106 5486651.40157058,
107 5741857.99662372,
108 5953365.5852939,
109 6119564.46711958,
110 6239189.76825642,
111 6311331.06793104,
112 6335439.32729282
113 };
114 double geoc_intercept[n] = {
115 0,
116 552169.92020293,
117 1100137.4939038,
118 1639732.35699488,
119 2166847.86675177,
120 2677472.35586416,
121 3167719.66364641,
122 3633858.71206688,
123 4072341.90150465,
124 4479832.11012469,
125 4853228.0913901,
126 5189688.07642079,
127 5486651.40157058,
128 5741857.99662372,
129 5953365.5852939,
130 6119564.46711958,
131 6239189.76825642,
132 6311331.06793104,
133 6378137 // Sole difference with geod, due to truncation artifacts.
134 };
135
136 for (i=0; i < n; i++) {
137 cout << "lon = " << lon << " geod lat = " << lat[i];
138
139 double sl_radius, lat_geoc;
140 sgGeodToGeoc( lat[i] * SGD_DEGREES_TO_RADIANS, alt, &sl_radius, &lat_geoc );
141 cout << " geoc lat = " << lat_geoc * SGD_RADIANS_TO_DEGREES << endl;
142 CPPUNIT_ASSERT_DOUBLES_EQUAL(lat_geoc_expected[i], lat_geoc*SGD_RADIANS_TO_DEGREES, 1e-10);
143
144 double pc[3];
145 sgGeodToCart( lon * SGD_DEGREES_TO_RADIANS, lat[i] * SGD_DEGREES_TO_RADIANS, 0.0, pc );
146 cout << " cartesian = " << SGVec3d(pc[0], pc[1], pc[2]) << endl;
147 for (int j=0; j < 3; j++)
148 CPPUNIT_ASSERT_DOUBLES_EQUAL(cart_expected[i][j], pc[j], 1e-7);
149
150 SGGeod geod_up = SGGeod::fromDeg(lon, -lat[i]);
151 SGVec3d geod_up_vect = SGVec3d::fromGeod(geod_up);
152 cout << " geod up = " << geod_up_vect << endl;
153 for (int j=0; j < 3; j++)
154 CPPUNIT_ASSERT_DOUBLES_EQUAL(up_expected[i][j], geod_up_vect[j], 1e-7);
155
156 SGGeoc geoc_up = SGGeoc::fromGeod(geod_up);
157 SGVec3d geoc_up_vect = SGVec3d::fromGeoc(geoc_up);
158 cout << " geoc up = " << geoc_up_vect << endl;
159 for (int j=0; j < 3; j++)
160 CPPUNIT_ASSERT_DOUBLES_EQUAL(up_expected[i][j], geoc_up_vect[j], 1e-7);
161
162 double slope = geod_up_vect[2] / geod_up_vect[0];
163 double intercept = pc[2] - slope * pc[0];
164 cout << " Z intercept (based on geodetic up) = " << intercept << endl;
165 CPPUNIT_ASSERT_DOUBLES_EQUAL(geod_intercept[i], intercept, 1e-7);
166
167 slope = geoc_up_vect[2] / geoc_up_vect[0];
168 intercept = pc[2] - slope * pc[0];
169 cout << " Z intercept (based on geocentric up) = " << intercept << endl;
170 CPPUNIT_ASSERT_DOUBLES_EQUAL(geoc_intercept[i], intercept, 1e-7);
171 }
172 }