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 FalseOrbite.
010 *
011 * Created: Tue 17 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 FalseOrbiteTest {
017
018 private FalseOrbite fgps;
019 private FalseOrbite fexosat;
020 private Orbite gps;
021 private Orbite exosat;
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.fgps = new FalseOrbite(0.0, 26E6);
031 this.fexosat = new FalseOrbite(0.93, 100E6);
032 this.gps = new Orbite(0.0, 26E6);
033 this.exosat = new Orbite(0.93, 100E6);
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.testDistanceFalseOrbite(this.fgps);
049 }
050
051 /**
052 * Testing if the sum of the distances to the focus is constant
053 * for EXOSAT.
054 */
055 @Test public void testDistanceBifocaleEXOSAT() {
056 this.testDistanceFalseOrbite(this.fexosat);
057 }
058
059 private void testDistanceFalseOrbite(FalseOrbite o) {
060 double c = o.getC();
061
062 double distance = 2 * (o.getA() - c) + 2 * c;
063
064 Point foyer1 = o.getFoyer();
065 Point foyer2 = new Point(foyer1.getX() - 2 * c, foyer1.getY());
066
067 Point p = null;
068
069 for (double theta = 0; theta < 2 * Math.PI; theta += STEP) {
070 p = o.calculerPointSurOrbite(theta);
071 assertEquals(distance, p.distance(foyer1) + p.distance(foyer2), EPS);
072 }
073 }
074
075 /**
076 * Test method for getA for EXOSAT.
077 */
078 @Test public void testGetAEXOSAT() {
079 assertEquals(this.exosat.getA(), this.fexosat.getA(), EPS);
080 }
081
082 /**
083 * Test method for getB for EXOSAT.
084 */
085 @Test public void testGetBEXOSAT() {
086 assertEquals(this.exosat.getB(), this.fexosat.getB(), EPS);
087 }
088
089 /**
090 * Test method for getB for EXOSAT with correction.
091 */
092 @Test public void testGetBEXOSATCorrect() {
093 this.fexosat.setB(this.exosat.getB());
094 assertEquals(this.exosat.getB(),
095 this.fexosat.getB(), EPS);
096 }
097
098 /**
099 * Testing if the sum of the distances to the focus is constant
100 * for EXOSAT with correction.
101 */
102 @Test public void testDistanceBifocaleEXOSATCorrect() {
103 this.fexosat.setB(this.exosat.getB());
104 this.testDistanceFalseOrbite(this.fexosat);
105 }
106
107 /**
108 * Test perigee for GPS.
109 */
110 @Test public void testPerigeeGPS() {
111 this.testPerigee(this.fgps, this.gps);
112 }
113
114 /**
115 * Test perigee for EXOSAT.
116 */
117 @Test public void testPerigeeEXOSAT() {
118 this.testPerigee(this.fexosat, this.exosat);
119 }
120
121 private void testPerigee(FalseOrbite fo, Orbite o) {
122 assertEquals(o.calculerPointSurOrbite(0.0).getX(),
123 fo.calculerPointSurOrbite(0.0).getX(),
124 EPS);
125 assertEquals(o.calculerPointSurOrbite(0.0).getY(),
126 fo.calculerPointSurOrbite(0.0).getY(),
127 EPS);
128 }
129
130 /**
131 * Test perigee for GPS with angle wrt focus.
132 */
133 @Test public void testPerigeeFGPS() {
134 this.testPerigeeF(this.fgps, this.gps);
135 }
136
137 /**
138 * Test perigee for EXOSAT with angle wrt focus.
139 */
140 @Test public void testPerigeeFEXOSAT() {
141 this.testPerigeeF(this.fexosat, this.exosat);
142 }
143
144 private void testPerigeeF(FalseOrbite fo, Orbite o) {
145 assertEquals(o.calculerPointSurOrbiteFoyer(0.0).getX(),
146 fo.calculerPointSurOrbiteFoyer(0.0).getX(),
147 EPS);
148 assertEquals(o.calculerPointSurOrbiteFoyer(0.0).getY(),
149 fo.calculerPointSurOrbiteFoyer(0.0).getY(),
150 EPS);
151 }
152
153 /**
154 * Test apogee for GPS.
155 */
156 @Test public void testApogeeGPS() {
157 this.testApogee(this.fgps, this.gps);
158 }
159
160 /**
161 * Test apogee for EXOSAT.
162 */
163 @Test public void testApogeeEXOSAT() {
164 this.testApogee(this.fexosat, this.exosat);
165 }
166
167 private void testApogee(FalseOrbite fo, Orbite o) {
168 assertEquals(o.calculerPointSurOrbite(Math.PI).getX(),
169 fo.calculerPointSurOrbite(Math.PI).getX(),
170 EPS);
171 assertEquals(o.calculerPointSurOrbite(Math.PI).getY(),
172 fo.calculerPointSurOrbite(Math.PI).getY(),
173 EPS);
174 }
175
176 /**
177 * Test apogee for GPS with angle wrt focus.
178 */
179 @Test public void testApogeeFGPS() {
180 this.testApogeeF(this.fgps, this.gps);
181 }
182
183 /**
184 * Test apogee for EXOSAT with angle wrt focus.
185 */
186 @Test public void testApogeeFEXOSAT() {
187 this.testApogeeF(this.fexosat, this.exosat);
188 }
189
190 private void testApogeeF(FalseOrbite fo, Orbite o) {
191 assertEquals(o.calculerPointSurOrbiteFoyer(Math.PI).getX(),
192 fo.calculerPointSurOrbiteFoyer(Math.PI).getX(),
193 EPS);
194 assertEquals(o.calculerPointSurOrbiteFoyer(Math.PI).getY(),
195 fo.calculerPointSurOrbiteFoyer(Math.PI).getY(),
196 EPS);
197 }
198
199 /**
200 * Test that tangent vector is orthogonal to point vector for
201 * GPS.
202 */
203 @Test public void testTangentGPS() {
204 this.testTangentCircular(this.fgps);
205 }
206
207 private void testTangentCircular(FalseOrbite o) {
208 Point p = null;
209 Point vec = null;
210 double length = 0.0;
211 Point center = new Point(o.getFoyer().getX() - o.getC(),
212 o.getFoyer().getY());
213
214 for (double v = 0; v < 2 * Math.PI; v += 1E-5) {
215 p = o.calculerPointSurOrbiteFoyer(v);
216
217 length = p.distance(center);
218
219 p.setX((p.getX() - center.getX()) / length);
220 p.setY((p.getY() - center.getY()) / length);
221
222 vec = o.calculerVecteurTangent(v);
223
224 assertEquals(0.0, p.getX() * vec.getX() + p.getY() * vec.getY(), EPS);
225 }
226 }
227
228 /**
229 * Test if tangent vector a PI/2 and -PI/2 is in the right
230 * direction.
231 */
232 @Test public void testTangentVector() {
233 Point veca = this.fgps.calculerVecteurTangent(Math.PI / 2.0);
234 Point vecb = this.fgps.calculerVecteurTangent(-Math.PI / 2.0);
235
236 assertEquals(-1.0, veca.getX(), EPS);
237 assertEquals(0.0, veca.getY(), EPS);
238 assertEquals(1.0, vecb.getX(), EPS);
239 assertEquals(0.0, vecb.getY(), EPS);
240 }
241
242 /**
243 * We know that when v = PI/2, y is the latus rectum and is
244 * b^2/a.
245 */
246 @Test public void testLatusRectumEXOSAT() {
247 Point lr = this.fexosat.calculerPointSurOrbiteFoyer(Math.PI / 2.0);
248
249 assertEquals(2.0 * Math.pow(this.fexosat.getB(), 2) / this.fexosat.getA(),
250 lr.getY() - this.fexosat.getFoyer().getY(), EPS);
251 }
252 }
|