1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.frames;
18
19 import org.hipparchus.CalculusFieldElement;
20 import org.hipparchus.Field;
21 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
22 import org.hipparchus.geometry.euclidean.threed.Vector3D;
23 import org.hipparchus.util.Binary64Field;
24 import org.junit.jupiter.api.Assertions;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.orekit.Utils;
28 import org.orekit.bodies.CelestialBody;
29 import org.orekit.bodies.CelestialBodyFactory;
30 import org.orekit.time.AbsoluteDate;
31 import org.orekit.time.FieldAbsoluteDate;
32 import org.orekit.time.TimeScalesFactory;
33 import org.orekit.utils.Constants;
34 import org.orekit.utils.FieldPVCoordinates;
35
36
37
38
39
40
41 public class L2TransformProviderTest {
42
43 @Test
44 public void testTransformationOrientationForEarthMoon() {
45
46
47 final CelestialBody earth = CelestialBodyFactory.getEarth();
48 final CelestialBody moon = CelestialBodyFactory.getMoon();
49
50
51 final Frame eme2000 = FramesFactory.getEME2000();
52 final Frame l2Frame = new L2Frame(earth, moon);
53
54
55 final AbsoluteDate date = new AbsoluteDate(2000, 01, 01, 0, 0, 00.000,
56 TimeScalesFactory.getUTC());
57
58
59 Vector3D posMoon = moon.getPosition(date, eme2000);
60
61
62
63
64
65 Vector3D posL2 = l2Frame.getStaticTransformTo(eme2000,date).transformPosition(Vector3D.ZERO);
66
67
68 Assertions.assertEquals(0.0, Vector3D.angle(posMoon, posL2), 1.0e-10);
69
70
71 Assertions.assertTrue(posL2.getNorm() > posMoon.getNorm() + 6.0e7);
72
73 }
74
75 @Test
76 public void testFieldTransformationOrientationForEarthMoon() {
77 doTestFieldTransformationOrientationForEarthMoon(Binary64Field.getInstance());
78 }
79
80 private <T extends CalculusFieldElement<T>> void doTestFieldTransformationOrientationForEarthMoon(final Field<T> field) {
81
82
83 final CelestialBody earth = CelestialBodyFactory.getEarth();
84 final CelestialBody moon = CelestialBodyFactory.getMoon();
85
86
87 final Frame eme2000 = FramesFactory.getEME2000();
88 final Frame l2Frame = new L2Frame(earth, moon);
89
90
91 final FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field, 2000, 01, 01, 0, 0, 00.000,
92 TimeScalesFactory.getUTC());
93
94
95 FieldPVCoordinates<T> pvMoon = moon.getPVCoordinates(date, eme2000);
96 FieldVector3D<T> posMoon = pvMoon.getPosition();
97
98
99
100
101
102 FieldVector3D<T> posL2 = l2Frame.getTransformTo(eme2000,date).transformPosition(Vector3D.ZERO);
103
104
105 Assertions.assertEquals(0.0, FieldVector3D.angle(posMoon, posL2).getReal(), 1.0e-10);
106
107
108 Assertions.assertTrue(posL2.getNorm().getReal() > posMoon.getNorm().getReal() + 6.0e7);
109
110 }
111
112 @Test
113 public void testSunEarth() {
114
115
116 final CelestialBody sun = CelestialBodyFactory.getSun();
117 final CelestialBody earth = CelestialBodyFactory.getEarth();
118
119
120 final Frame sunFrame = sun.getInertiallyOrientedFrame();
121 final Frame l2Frame = new L2Frame(sun, earth);
122
123
124 final AbsoluteDate date = new AbsoluteDate(2000, 01, 01, 0, 0, 00.000,
125 TimeScalesFactory.getUTC());
126
127
128 Vector3D posEarth = earth.getPosition(date, sunFrame);
129
130
131
132
133
134 Vector3D posL2 = l2Frame.getStaticTransformTo(sunFrame,date).transformPosition(Vector3D.ZERO);
135
136
137 Assertions.assertEquals(0.0, Vector3D.angle(posEarth, posL2), 1.0e-10);
138
139
140 Assertions.assertTrue(posL2.getNorm() > posEarth.getNorm() + 1.0e9);
141 }
142
143 @Test
144 public void testFieldSunEarth() {
145 doTestFieldSunEarth(Binary64Field.getInstance());
146 }
147
148 private <T extends CalculusFieldElement<T>> void doTestFieldSunEarth(final Field<T> field) {
149
150
151 final CelestialBody sun = CelestialBodyFactory.getSun();
152 final CelestialBody earth = CelestialBodyFactory.getEarth();
153
154
155 final Frame sunFrame = sun.getInertiallyOrientedFrame();
156 final Frame l2Frame = new L2Frame(sun, earth);
157
158
159 final FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field, 2000, 01, 01, 0, 0, 00.000,
160 TimeScalesFactory.getUTC());
161
162
163 FieldPVCoordinates<T> pvEarth = earth.getPVCoordinates(date, sunFrame);
164 FieldVector3D<T> posEarth = pvEarth.getPosition();
165
166
167
168
169
170 FieldVector3D<T> posL2 = l2Frame.getStaticTransformTo(sunFrame,date).transformPosition(Vector3D.ZERO);
171
172
173 Assertions.assertEquals(0.0, FieldVector3D.angle(posEarth, posL2).getReal(), 1.0e-10);
174
175
176 Assertions.assertTrue(posL2.getNorm().getReal() > posEarth.getNorm().getReal() + 1.0e9);
177 }
178
179 @Test
180 public void testSunJupiter() {
181
182
183 final CelestialBody sun = CelestialBodyFactory.getSun();
184 final CelestialBody jupiter = CelestialBodyFactory.getJupiter();
185
186
187 final Frame sunFrame = sun.getInertiallyOrientedFrame();
188 final Frame l2Frame = new L2Frame(sun, jupiter);
189
190
191 final AbsoluteDate date = new AbsoluteDate(2000, 01, 01, 0, 0, 00.000,
192 TimeScalesFactory.getUTC());
193
194
195 Vector3D posJupiter = jupiter.getPosition(date, sunFrame);
196
197
198
199
200
201 Vector3D posL2 = l2Frame.getStaticTransformTo(sunFrame,date).transformPosition(Vector3D.ZERO);
202
203
204 Assertions.assertEquals(0.0, Vector3D.angle(posJupiter, posL2), 1.0e-10);
205
206
207 Assertions.assertTrue(posL2.getNorm() > posJupiter.getNorm() + 5.0e10);
208 }
209
210 @Test
211 public void testFieldSunJupiter() {
212 doTestFieldSunJupiter(Binary64Field.getInstance());
213 }
214
215 private <T extends CalculusFieldElement<T>> void doTestFieldSunJupiter(final Field<T> field) {
216
217
218 final CelestialBody sun = CelestialBodyFactory.getSun();
219 final CelestialBody jupiter = CelestialBodyFactory.getJupiter();
220
221
222 final Frame sunFrame = sun.getInertiallyOrientedFrame();
223 final Frame l2Frame = new L2Frame(sun, jupiter);
224
225
226 final FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field, 2000, 01, 01, 0, 0, 00.000,
227 TimeScalesFactory.getUTC());
228
229
230 FieldPVCoordinates<T> pvJupiter = jupiter.getPVCoordinates(date, sunFrame);
231 FieldVector3D<T> posJupiter = pvJupiter.getPosition();
232
233
234
235
236
237 FieldVector3D<T> posL2 = l2Frame.getStaticTransformTo(sunFrame,date).transformPosition(Vector3D.ZERO);
238
239
240 Assertions.assertEquals(0.0, FieldVector3D.angle(posJupiter, posL2).getReal(), 1.0e-10);
241
242
243 Assertions.assertTrue(posL2.getNorm().getReal() > posJupiter.getNorm().getReal() + 5.0e10);
244 }
245
246 @Test
247 public void testL2Orientation() {
248
249 final AbsoluteDate date0 = new AbsoluteDate(2000, 01, 1, 11, 58, 20.000,
250 TimeScalesFactory.getUTC());
251 final CelestialBody sun = CelestialBodyFactory.getSun();
252 final CelestialBody earth = CelestialBodyFactory.getEarth();
253 final Frame l2Frame = new L2Frame(sun, earth);
254 for (double dt = -Constants.JULIAN_DAY; dt <= Constants.JULIAN_DAY; dt += 3600.0) {
255 final AbsoluteDate date = date0.shiftedBy(dt);
256 final Vector3D sunPositionInL2 = sun.getPosition(date, l2Frame);
257 final Vector3D earthPositionInL2 = earth.getPosition(date, l2Frame);
258 Assertions.assertEquals(0.0, Vector3D.angle(sunPositionInL2, Vector3D.MINUS_I), 3.0e-14);
259 Assertions.assertEquals(0.0, Vector3D.angle(earthPositionInL2, Vector3D.MINUS_I), 3.0e-14);
260 }
261 }
262
263 @Test
264 public void testFieldL2Orientation() {
265 doTestFieldL2Orientation(Binary64Field.getInstance());
266 }
267
268 private <T extends CalculusFieldElement<T>> void doTestFieldL2Orientation(final Field<T> field) {
269
270 final FieldAbsoluteDate<T> date0 = new FieldAbsoluteDate<>(field, 2000, 01, 1, 11, 58, 20.000,
271 TimeScalesFactory.getUTC());
272 final CelestialBody sun = CelestialBodyFactory.getSun();
273 final CelestialBody earth = CelestialBodyFactory.getEarth();
274 final Frame l2Frame = new L2Frame(sun, earth);
275 for (double dt = -Constants.JULIAN_DAY; dt <= Constants.JULIAN_DAY; dt += 3600.0) {
276 final FieldAbsoluteDate<T> date = date0.shiftedBy(dt);
277 final FieldVector3D<T> sunPositionInL2 = sun.getPosition(date, l2Frame);
278 final FieldVector3D<T> earthPositionInL2 = earth.getPosition(date, l2Frame);
279 Assertions.assertEquals(0.0, FieldVector3D.angle(sunPositionInL2, Vector3D.MINUS_I).getReal(), 3.0e-14);
280 Assertions.assertEquals(0.0, FieldVector3D.angle(earthPositionInL2, Vector3D.MINUS_I).getReal(), 3.0e-14);
281 }
282 }
283
284 @BeforeEach
285 public void setUp() {
286 Utils.setDataRoot("regular-data");
287 }
288
289 }