001 package fr.isae.orbit;
002
003 import fr.isae.geometry.Point;
004
005 import org.junit.*;
006 import static org.junit.Assert.*;
007
008 /**
009 * Unit Test for class Orbite.
010 *
011 * Created: Tue Aug 27 16:05:42 2013
012 *
013 * @author <a href="mailto:christophe.garion@isae.fr">Christophe Garion</a>
014 * @version 1.0
015 */
016 public class OrbiteTest {
017
018 private Orbite gps;
019 private Orbite gpsf;
020 private Orbite exosat;
021 private Orbite exosatf;
022
023 private static final double EPS = 1E-6;
024 private static final double STEP = 1E-5;
025
026 /**
027 * Setup for the tests.
028 */
029 @Before public void setUp() {
030 this.gps = new Orbite(0.0, 26E6);
031 this.gpsf = new Orbite(0.0, 26E6, new Point(2E6, -5E3));
032 this.exosat = new Orbite(0.93, 100E6);
033 this.exosatf = new Orbite(0.93, 100E6, new Point(-50E6, 1E7));
034 }
035
036 /**
037 * Cleanup for the tests.
038 */
039 @After public void tearDown() {
040
041 }
042
043 /**
044 * Testing if the sum of the distances to the focus is constant
045 * for GPS.
046 */
047 @Test public void testDistanceBifocaleGPS() {
048 this.testDistanceOrbite(this.gps);
049 }
050
051 /**
052 * Testing if the sum of the distances to the focus is constant
053 * for GPS with focus not on origin.
054 */
055 @Test public void testDistanceBifocaleGPSF() {
056 this.testDistanceOrbite(this.gpsf);
057 }
058
059 /**
060 * Testing if the sum of the distances to the focus is constant
061 * for EXOSAT.
062 */
063 @Test public void testDistanceBifocaleEXOSAT() {
064 this.testDistanceOrbite(this.exosat);
065 }
066
067 /**
068 * Testing if the sum of the distances to the focus is constant
069 * for EXOSAT with focus not on origin.
070 */
071 @Test public void testDistanceBifocaleEXOSATF() {
072 this.testDistanceOrbite(this.exosatf);
073 }
074
075 private void testDistanceOrbite(Orbite o) {
076 double c = o.getC();
077
078 double distance = 2 * (o.getA() - c) + 2 * c;
079
080 Point foyer1 = o.getFoyer();
081 Point foyer2 = new Point(foyer1.getX() - 2 * c, foyer1.getY());
082
083 Point p = null;
084
085 for (double theta = 0; theta < 2 * Math.PI; theta += STEP) {
086 p = o.calculerPointSurOrbite(theta);
087 assertEquals(distance, p.distance(foyer1) + p.distance(foyer2), EPS);
088 }
089 }
090
091 /**
092 * Testing if the sum of the distances to the focus is constant
093 * for GPS with angle wrt to focus.
094 */
095 @Test public void testDistanceBifocaleFGPS() {
096 this.testDistanceOrbiteF(this.gps);
097 }
098
099 /**
100 * Testing if the sum of the distances to the focus is constant
101 * for GPS with focus not on origin and with angle wrt to focus.
102 */
103 @Test public void testDistanceBifocaleFGPSF() {
104 this.testDistanceOrbiteF(this.gpsf);
105 }
106
107 /**
108 * Testing if the sum of the distances to the focus is constant
109 * for EXOSAT with angle wrt to focus.
110 */
111 @Test public void testDistanceBifocaleFEXOSAT() {
112 this.testDistanceOrbiteF(this.exosat);
113 }
114
115 /**
116 * Testing if the sum of the distances to the focus is constant
117 * for EXOSAT with focus not on origin and with angle wrt to focus.
118 */
119 @Test public void testDistanceBifocaleFEXOSATF() {
120 this.testDistanceOrbiteF(this.exosatf);
121 }
122
123 private void testDistanceOrbiteF(Orbite o) {
124 double c = o.getC();
125
126 double distance = 2 * (o.getA() - c) + 2 * c;
127
128 Point foyer1 = o.getFoyer();
129 Point foyer2 = new Point(foyer1.getX() - 2 * c, foyer1.getY());
130
131 Point p = null;
132
133 for (double v = 0; v < 2 * Math.PI; v += STEP) {
134 p = o.calculerPointSurOrbiteFoyer(v);
135 assertEquals(distance, p.distance(foyer1) + p.distance(foyer2), EPS);
136 }
137 }
138
139 /**
140 * Test if GPS orbit is circular.
141 */
142 @Test public void testGPSCircularOrbit() {
143 assertEquals(0.0, this.gps.getA() * this.gps.getE(), EPS);
144 assertEquals(0.0, Math.abs(this.gps.getA() - this.gps.getB()), EPS);
145
146 double rayon = this.gps.getA();
147 Point centre = this.gps.getFoyer();
148
149 Point p = null;
150
151 for (double theta = 0; theta < 2 * Math.PI; theta += STEP) {
152 p = this.gps.calculerPointSurOrbite(theta);
153 assertEquals(rayon, p.distance(centre), EPS);
154 }
155 }
156
157 /**
158 * Test if GPS orbit with focus not on origin is circular.
159 */
160 @Test public void testGPSFCircularOrbit() {
161 assertEquals(0.0, this.gpsf.getA() * this.gpsf.getE(), EPS);
162 assertEquals(0.0, Math.abs(this.gpsf.getA() - this.gpsf.getB()), EPS);
163
164 double rayon = this.gpsf.getA();
165 Point centre = this.gpsf.getFoyer();
166
167 Point p = null;
168
169 for (double theta = 0; theta < 2 * Math.PI; theta += STEP) {
170 p = this.gpsf.calculerPointSurOrbite(theta);
171 assertEquals(rayon, p.distance(centre), EPS);
172 }
173 }
174
175 /**
176 * Test if GPS orbit is circular with angle wrt to focus.
177 */
178 @Test public void testGPSCircularOrbitF() {
179 assertEquals(0.0, this.gps.getA() * this.gps.getE(), EPS);
180 assertEquals(0.0, Math.abs(this.gps.getA() - this.gps.getB()), EPS);
181
182 double rayon = this.gps.getA();
183 Point centre = this.gps.getFoyer();
184
185 Point p = null;
186
187 for (double v = 0; v < 2 * Math.PI; v += STEP) {
188 p = this.gps.calculerPointSurOrbiteFoyer(v);
189 assertEquals(rayon, p.distance(centre), EPS);
190 }
191 }
192
193 /**
194 * Test if GPS orbit with focus not on origin is circular with angle
195 * wrt to focus.
196 */
197 @Test public void testGPSFCircularOrbitF() {
198 assertEquals(0.0, this.gpsf.getA() * this.gpsf.getE(), EPS);
199 assertEquals(0.0, Math.abs(this.gpsf.getA() - this.gpsf.getB()), EPS);
200
201 double rayon = this.gpsf.getA();
202 Point centre = this.gpsf.getFoyer();
203
204 Point p = null;
205
206 for (double v = 0; v < 2 * Math.PI; v += STEP) {
207 p = this.gpsf.calculerPointSurOrbiteFoyer(v);
208 assertEquals(rayon, p.distance(centre), EPS);
209 }
210 }
211
212 /**
213 * Test perigee for GPS.
214 */
215 @Test public void testPerigeeGPS() {
216 this.testPerigee(this.gps);
217 }
218
219 /**
220 * Test perigee for GPS with focus not on origin.
221 */
222 @Test public void testPerigeeGPSF() {
223 this.testPerigee(this.gpsf);
224 }
225
226 /**
227 * Test perigee for EXOSAT.
228 */
229 @Test public void testPerigeeEXOSAT() {
230 this.testPerigee(this.exosat);
231 }
232
233 /**
234 * Test perigee for EXOSAT with focus not on origin.
235 */
236 @Test public void testPerigeeEXOSATF() {
237 this.testPerigee(this.exosatf);
238 }
239
240 private void testPerigee(Orbite o) {
241 assertEquals(o.getA() - o.getA() * o.getE() + o.getFoyer().getX(),
242 o.calculerPointSurOrbite(0.0).getX(),
243 EPS);
244 assertEquals(o.getFoyer().getY(),
245 o.calculerPointSurOrbite(0.0).getY(),
246 EPS);
247 }
248
249 /**
250 * Test perigee for GPS with angle wrt focus.
251 */
252 @Test public void testPerigeeFGPS() {
253 this.testPerigeeF(this.gps);
254 }
255
256 /**
257 * Test perigee for GPS with with angle wrt focus and
258 * focus not on origin.
259 */
260 @Test public void testPerigeeFGPSF() {
261 this.testPerigeeF(this.gpsf);
262 }
263
264 /**
265 * Test perigee for EXOSAT with angle wrt focus.
266 */
267 @Test public void testPerigeeFEXOSAT() {
268 this.testPerigeeF(this.exosat);
269 }
270
271 /**
272 * Test perigee for EXOSAT with with angle wrt focus and
273 * focus not on origin.
274 */
275 @Test public void testPerigeeFEXOSATF() {
276 this.testPerigeeF(this.exosatf);
277 }
278
279 private void testPerigeeF(Orbite o) {
280 assertEquals(o.getA() - o.getA() * o.getE() + o.getFoyer().getX(),
281 o.calculerPointSurOrbiteFoyer(0.0).getX(),
282 EPS);
283 assertEquals(o.getFoyer().getY(),
284 o.calculerPointSurOrbiteFoyer(0.0).getY(),
285 EPS);
286 }
287
288 /**
289 * Test apogee for GPS.
290 */
291 @Test public void testApogeeGPS() {
292 this.testApogee(this.gps);
293 }
294
295 /**
296 * Test apogee for GPS with focus not on origin.
297 */
298 @Test public void testApogeeGPSF() {
299 this.testApogee(this.gpsf);
300 }
301
302 /**
303 * Test apogee for EXOSAT.
304 */
305 @Test public void testApogeeEXOSAT() {
306 this.testApogee(this.exosat);
307 }
308
309 /**
310 * Test apogee for EXOSAT with focus not on origin.
311 */
312 @Test public void testApogeeEXOSATF() {
313 this.testApogee(this.exosatf);
314 }
315
316 private void testApogee(Orbite o) {
317 assertEquals(-(o.getA() + o.getA() * o.getE()) + o.getFoyer().getX(),
318 o.calculerPointSurOrbite(Math.PI).getX(),
319 EPS);
320 assertEquals(o.getFoyer().getY(),
321 o.calculerPointSurOrbite(Math.PI).getY(),
322 EPS);
323 }
324
325 /**
326 * Test apogee for GPS with angle wrt focus.
327 */
328 @Test public void testApogeeFGPS() {
329 this.testApogeeF(this.gps);
330 }
331
332 /**
333 * Test apogee for GPS with with angle wrt focus and
334 * focus not on origin.
335 */
336 @Test public void testApogeeFGPSF() {
337 this.testApogeeF(this.gpsf);
338 }
339
340 /**
341 * Test apogee for EXOSAT with angle wrt focus.
342 */
343 @Test public void testApogeeFEXOSAT() {
344 this.testApogeeF(this.exosat);
345 }
346
347 /**
348 * Test apogee for EXOSAT with with angle wrt focus and
349 * focus not on origin.
350 */
351 @Test public void testApogeeFEXOSATF() {
352 this.testApogeeF(this.exosatf);
353 }
354
355 private void testApogeeF(Orbite o) {
356 assertEquals(-(o.getA() + o.getA() * o.getE()) + o.getFoyer().getX(),
357 o.calculerPointSurOrbiteFoyer(Math.PI).getX(),
358 EPS);
359 assertEquals(o.getFoyer().getY(),
360 o.calculerPointSurOrbiteFoyer(Math.PI).getY(),
361 EPS);
362 }
363
364 /**
365 * Test that tangent vector is orthogonal to point vector for
366 * GPS.
367 */
368 @Ignore public void testTangentGPS() {
369 this.testTangentCircular(this.gps);
370 }
371
372 /**
373 * Test that tangent vector is orthogonal to point vector for
374 * GPS with moved focus.
375 */
376 @Test public void testTangentGPSF() {
377 this.testTangentCircular(this.gpsf);
378 }
379
380 private void testTangentCircular(Orbite o) {
381 Point p = null;
382 Point vec = null;
383 double length = 0.0;
384 Point center = new Point(o.getFoyer().getX() - o.getC(),
385 o.getFoyer().getY());
386
387 for (double v = 0; v < 2 * Math.PI; v += 1E-5) {
388 p = o.calculerPointSurOrbiteFoyer(v);
389
390 length = p.distance(center);
391
392 p.setX((p.getX() - center.getX()) / length);
393 p.setY((p.getY() - center.getY()) / length);
394
395 vec = o.calculerVecteurTangent(v);
396
397 assertEquals(0.0, p.getX() * vec.getX() + p.getY() * vec.getY(), EPS);
398 }
399 }
400
401 /**
402 * Test visibility for GPS. Normally, satellites are always
403 * visible.
404 */
405 @Test public void testVisibilityGPS() {
406 for (double v = 0; v < 2 * Math.PI; v += STEP) {
407 assertTrue(this.gps.voitSatelliteSuivant(v));
408 }
409 }
410
411 /**
412 * Test visibility for GPS with moved focus. Normally, satellites
413 * are always visible.
414 */
415 @Test public void testVisibilityGPSF() {
416 for (double v = 0; v < 2 * Math.PI; v += STEP) {
417 assertTrue(this.gpsf.voitSatelliteSuivant(v));
418 }
419 }
420
421 /**
422 * Test visibility for EXOSAT.
423 */
424 @Test public void testVisibilityEXOSAT() {
425 this.testVisiEXOSAT(this.exosat);
426 }
427
428 /**
429 * Test visibility for EXOSAT with moved focus.
430 */
431 @Test public void testVisibilityEXOSATF() {
432 this.testVisiEXOSAT(this.exosatf);
433 }
434
435
436 private void testVisiEXOSAT(Orbite o) {
437 double v;
438
439 for (v = 0; v < 1.246; v += STEP) {
440 assertTrue(o.voitSatelliteSuivant(v));
441 }
442
443 for (v = 1.247; v < 3.169; v += STEP) {
444 assertFalse(o.voitSatelliteSuivant(v));
445 }
446
447 for (v = 3.170; v < 3.348; v += STEP) {
448 assertTrue(o.voitSatelliteSuivant(v));
449 }
450
451 for (v = 3.349; v < 4.276; v += STEP) {
452 assertFalse(o.voitSatelliteSuivant(v));
453 }
454
455 for (v = 4.277; v < 2.0 * Math.PI; v += STEP) {
456 assertTrue(o.voitSatelliteSuivant(v));
457 }
458 }
459 }
|