1 #include "OrbitTest.hpp"
3 #include "../assert.hpp"
6 #include "world/Orbit.hpp"
8 CPPUNIT_TEST_SUITE_REGISTRATION(blobs::test::world::OrbitTest);
10 using blobs::world::Orbit;
17 void OrbitTest::setUp() {
20 void OrbitTest::tearDown() {
24 void OrbitTest::testDefaultOrbit() {
26 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
27 "wrong semi-major axis on default orbit",
28 1.0, orbit.SemiMajorAxis(), std::numeric_limits<double>::epsilon()
30 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
31 "wrong eccentricity on default orbit",
32 0.0, orbit.Eccentricity(), std::numeric_limits<double>::epsilon()
34 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
35 "wrong inclination on default orbit",
36 0.0, orbit.Inclination(), std::numeric_limits<double>::epsilon()
38 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
39 "wrong longitude of ascending node on default orbit",
40 0.0, orbit.LongitudeAscending(), std::numeric_limits<double>::epsilon()
42 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
43 "wrong argument of periapsis on default orbit",
44 0.0, orbit.ArgumentPeriapsis(), std::numeric_limits<double>::epsilon()
46 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
47 "wrong mean anomaly on default orbit",
48 0.0, orbit.MeanAnomaly(), std::numeric_limits<double>::epsilon()
51 // reference direction is +X, so at t=0, the body should be
52 // at (sma,0,0) relative to its parent
53 glm::vec4 pos(orbit.Matrix(0.0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
55 "wrong position at t=0",
56 glm::vec3(1.0f, 0.0f, 0.0f),
57 glm::vec3(pos) / pos.w
60 // at 90° position should be (0,0,sma) since the zero inclination
61 // reference plane is XZ and rotates counter-clockwise
62 pos = orbit.Matrix(PI_0p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
64 "wrong position at t=90°",
65 glm::vec3(0.0f, 0.0f, -1.0f),
66 glm::vec3(pos) / pos.w
69 // at 180° position should be (-sma,0,0)
70 pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
72 "wrong position at t=180°",
73 glm::vec3(-1.0f, 0.0f, 0.0f),
74 glm::vec3(pos) / pos.w
77 // at 270° position should be (0,0,-sma)
78 pos = orbit.Matrix(PI_1p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
80 "wrong position at t=270°",
81 glm::vec3(0.0f, 0.0f, 1.0f),
82 glm::vec3(pos) / pos.w
85 // at 360° position should be (sma,0,0), the initial position
86 pos = orbit.Matrix(PI_2p0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
88 "wrong position at t=360°",
89 glm::vec3(1.0f, 0.0f, 0.0f),
90 glm::vec3(pos) / pos.w
94 void OrbitTest::testSMA() {
96 orbit.SemiMajorAxis(2.0);
97 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
98 "wrong semi-major axis on orbit",
99 2.0, orbit.SemiMajorAxis(), std::numeric_limits<double>::epsilon()
102 // reference direction is +X, so at t=0, the body should be
103 // at (sma,0,0) relative to its parent
104 glm::vec4 pos(orbit.Matrix(0.0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
106 "wrong position at t=0",
107 glm::vec3(2.0f, 0.0f, 0.0f),
108 glm::vec3(pos) / pos.w
111 // at 90° position should be (0,0,sma) since the zero inclination
112 // reference plane is XZ and rotates counter-clockwise
113 pos = orbit.Matrix(PI_0p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
115 "wrong position at t=90°",
116 glm::vec3(0.0f, 0.0f, -2.0f),
117 glm::vec3(pos) / pos.w
120 // at 180° position should be (-sma,0,0)
121 pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
123 "wrong position at t=180°",
124 glm::vec3(-2.0f, 0.0f, 0.0f),
125 glm::vec3(pos) / pos.w
128 // at 270° position should be (0,0,-sma)
129 pos = orbit.Matrix(PI_1p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
131 "wrong position at t=270°",
132 glm::vec3(0.0f, 0.0f, 2.0f),
133 glm::vec3(pos) / pos.w
136 // at 360° position should be (sma,0,0), the initial position
137 pos = orbit.Matrix(PI_2p0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
139 "wrong position at t=360°",
140 glm::vec3(2.0f, 0.0f, 0.0f),
141 glm::vec3(pos) / pos.w
145 void OrbitTest::testEcc() {
147 orbit.Eccentricity(0.5);
148 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
149 "wrong eccentricity on orbit",
150 0.5, orbit.Eccentricity(), std::numeric_limits<double>::epsilon()
153 glm::vec4 pos(orbit.Matrix(0.0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
155 "wrong position at t=0",
156 glm::vec3(0.5f, 0.0f, 0.0f),
157 glm::vec3(pos) / pos.w
160 pos = orbit.Matrix(PI_0p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
162 "wrong position at t=90°",
163 glm::vec3(-0.935130834579468f, 0.0f, -0.779740869998932f),
164 glm::vec3(pos) / pos.w
167 pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
169 "wrong position at t=180°",
170 glm::vec3(-1.5f, 0.0f, 0.0f),
171 glm::vec3(pos) / pos.w
174 pos = orbit.Matrix(PI_1p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
176 "wrong position at t=270°",
177 glm::vec3(-0.935130834579468f, 0.0f, 0.779740869998932f),
178 glm::vec3(pos) / pos.w
181 pos = orbit.Matrix(PI_2p0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
183 "wrong position at t=360°",
184 glm::vec3(0.5f, 0.0f, 0.0f),
185 glm::vec3(pos) / pos.w
189 void OrbitTest::testInc() {
191 orbit.Inclination(PI * 0.25); // 45°
192 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
193 "wrong inclination on orbit",
194 PI * 0.25, orbit.Inclination(), std::numeric_limits<double>::epsilon()
197 // inclination rotates counter clockwise around +X, so at t=0 should be
198 // at (sma,0,0) relative to its parent
199 glm::vec4 pos(orbit.Matrix(0.0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
201 "wrong position at t=0",
202 glm::vec3(1.0f, 0.0f, 0.0f),
203 glm::vec3(pos) / pos.w
206 pos = orbit.Matrix(PI_0p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
208 "wrong position at t=90°",
209 glm::vec3(0.0f, 0.70710676908493f, -0.70710676908493f),
210 glm::vec3(pos) / pos.w
213 pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
215 "wrong position at t=180°",
216 glm::vec3(-1.0f, 0.0f, 0.0f),
217 glm::vec3(pos) / pos.w
220 pos = orbit.Matrix(PI_1p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
222 "wrong position at t=270°",
223 glm::vec3(0.0f, -0.70710676908493f, 0.70710676908493f),
224 glm::vec3(pos) / pos.w
227 pos = orbit.Matrix(PI_2p0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
229 "wrong position at t=360°",
230 glm::vec3(1.0f, 0.0f, 0.0f),
231 glm::vec3(pos) / pos.w
235 void OrbitTest::testLngAsc() {
237 orbit.LongitudeAscending(PI * 0.25); // 45°
238 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
239 "wrong longitude of ascending node on orbit",
240 PI * 0.25, orbit.LongitudeAscending(), std::numeric_limits<double>::epsilon()
242 // using an inclination of 90° as well to make the rotation more apparent
243 orbit.Inclination(PI * 0.5);
245 // inclination rotates counter clockwise around +X, while LAN rotates it
246 // around +Y, so at t=0 should be at (sma*sin(45°),0,-sma*cos(45°))
247 glm::vec4 pos(orbit.Matrix(0.0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
249 "wrong position at t=0",
250 glm::vec3(0.70710676908493f, 0.0f, -0.70710676908493f),
251 glm::vec3(pos) / pos.w
254 pos = orbit.Matrix(PI_0p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
256 "wrong position at t=90°",
257 glm::vec3(0.0f, 1.0f, 0.0f),
258 glm::vec3(pos) / pos.w
261 pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
263 "wrong position at t=180°",
264 glm::vec3(-0.70710676908493f, 0.0f, 0.70710676908493f),
265 glm::vec3(pos) / pos.w
268 pos = orbit.Matrix(PI_1p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
270 "wrong position at t=270°",
271 glm::vec3(0.0f, -1.0f, 0.0f),
272 glm::vec3(pos) / pos.w
275 pos = orbit.Matrix(PI_2p0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
277 "wrong position at t=360°",
278 glm::vec3(0.70710676908493f, 0.0f, -0.70710676908493f),
279 glm::vec3(pos) / pos.w
283 void OrbitTest::testArgPe() {
285 orbit.ArgumentPeriapsis(PI * 0.25); // 45°
286 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
287 "wrong argument of periapsis node on orbit",
288 PI * 0.25, orbit.ArgumentPeriapsis(), std::numeric_limits<double>::epsilon()
290 // using an inclination of 90° as well to make the rotation more apparent
291 orbit.Inclination(PI * 0.5);
293 // inclination rotates counter clockwise around +X, while APe rotates it
294 // around +Y in the rotated coordinate system, so at t=0 should be at
295 // (sma*sin(45°),0,sma*cos(45°))
296 glm::vec4 pos(orbit.Matrix(0.0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
298 "wrong position at t=0",
299 glm::vec3(0.70710676908493f, 0.0f, 0.70710676908493f),
300 glm::vec3(pos) / pos.w
303 pos = orbit.Matrix(PI_0p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
305 "wrong position at t=90°",
306 glm::vec3(0.0f, 1.0f, 0.0f),
307 glm::vec3(pos) / pos.w
310 pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
312 "wrong position at t=180°",
313 glm::vec3(-0.70710676908493f, 0.0f, -0.70710676908493f),
314 glm::vec3(pos) / pos.w
317 pos = orbit.Matrix(PI_1p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
319 "wrong position at t=270°",
320 glm::vec3(0.0f, -1.0f, 0.0f),
321 glm::vec3(pos) / pos.w
324 pos = orbit.Matrix(PI_2p0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
326 "wrong position at t=360°",
327 glm::vec3(0.70710676908493f, 0.0f, 0.70710676908493f),
328 glm::vec3(pos) / pos.w
332 void OrbitTest::testMnAn() {
334 orbit.MeanAnomaly(PI * 0.25); // 45°
335 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
336 "wrong mean anomaly on default orbit",
337 PI * 0.25, orbit.MeanAnomaly(), std::numeric_limits<double>::epsilon()
340 // mean anomaly just phase shifts the orbit
341 glm::vec4 pos(orbit.Matrix(0.0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
343 "wrong position at t=0",
344 glm::vec3(0.70710676908493f, 0.0f, -0.70710676908493f),
345 glm::vec3(pos) / pos.w
348 // at 90° position should be (0,0,sma) since the zero inclination
349 // reference plane is XZ and rotates counter-clockwise
350 pos = orbit.Matrix(PI_0p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
352 "wrong position at t=90°",
353 glm::vec3(-0.70710676908493f, 0.0f, -0.70710676908493f),
354 glm::vec3(pos) / pos.w
357 // at 180° position should be (-sma,0,0)
358 pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
360 "wrong position at t=180°",
361 glm::vec3(-0.70710676908493f, 0.0f, 0.70710676908493f),
362 glm::vec3(pos) / pos.w
365 // at 270° position should be (0,0,-sma)
366 pos = orbit.Matrix(PI_1p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
368 "wrong position at t=270°",
369 glm::vec3(0.70710676908493f, 0.0f, 0.70710676908493f),
370 glm::vec3(pos) / pos.w
373 // at 360° position should be (sma,0,0), the initial position
374 pos = orbit.Matrix(PI_2p0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
376 "wrong position at t=360°",
377 glm::vec3(0.70710676908493f, 0.0f, -0.70710676908493f),
378 glm::vec3(pos) / pos.w