1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.frames;
18
19 import java.io.ByteArrayInputStream;
20 import java.io.ByteArrayOutputStream;
21 import java.io.IOException;
22 import java.io.ObjectInputStream;
23 import java.io.ObjectOutputStream;
24
25 import org.hamcrest.MatcherAssert;
26 import org.hamcrest.core.IsInstanceOf;
27 import org.hipparchus.geometry.euclidean.threed.Vector3D;
28 import org.junit.Assert;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.orekit.Utils;
32 import org.orekit.bodies.CelestialBody;
33 import org.orekit.bodies.CelestialBodyFactory;
34 import org.orekit.time.AbsoluteDate;
35 import org.orekit.time.TimeScale;
36 import org.orekit.time.TimeScalesFactory;
37 import org.orekit.utils.Constants;
38 import org.orekit.utils.IERSConventions;
39
40
41 public class EclipticProviderTest {
42
43
44 @BeforeClass
45 public static void setUpBefore() {
46 Utils.setDataRoot("regular-data");
47 }
48
49
50
51
52
53
54
55 @Test
56 public void testAgreementWith406Ephemerides() throws Exception {
57 TimeScale utc = TimeScalesFactory.getUTC();
58
59
60 checkAlignment(new AbsoluteDate(1969, 5, 27, utc), new AbsoluteDate(1969, 9, 20, utc));
61 checkAlignment(new AbsoluteDate(1969, 12, 5, utc), new AbsoluteDate(1970, 4, 1, utc));
62 checkAlignment(new AbsoluteDate(1970, 6, 15, utc), new AbsoluteDate(1970, 8, 1, utc));
63 checkAlignment(new AbsoluteDate(2002, 12, 16, utc), new AbsoluteDate(2004, 2, 3, utc));
64
65 checkAlignment(new AbsoluteDate(1999, 11, 22, utc), new AbsoluteDate(2000, 5, 21, utc));
66 }
67
68
69
70
71
72
73
74
75 private void checkAlignment(AbsoluteDate start, AbsoluteDate end) {
76
77 CelestialBody sun = CelestialBodyFactory.getSun();
78 CelestialBody emb = CelestialBodyFactory.getEarthMoonBarycenter();
79 Frame heliocentric = sun.getInertiallyOrientedFrame();
80
81 Frame ecliptic = FramesFactory.getEcliptic(IERSConventions.IERS_2010);
82
83
84
85
86 double preciseTol = 0.50 * Constants.ARC_SECONDS_TO_RADIANS;
87 for (AbsoluteDate date = start;
88 date.compareTo(end) < 0;
89 date = date.shiftedBy(Constants.JULIAN_YEAR / 12.0)) {
90
91 Transform heliocentricToEcliptic = heliocentric.getTransformTo(ecliptic, date);
92 Vector3D momentum = emb.getPVCoordinates(date, heliocentric).getMomentum();
93 Vector3D actual = heliocentricToEcliptic.transformVector(momentum);
94 double angle = Vector3D.angle(
95 Vector3D.PLUS_K,
96 actual
97 );
98 Assert.assertEquals("Agrees with ephemerides to within " + preciseTol, 0, angle, preciseTol);
99
100 }
101
102 }
103
104
105
106
107 @Test
108 public void testGetName() {
109 Assert.assertEquals("Ecliptic/1996",
110 FramesFactory.getEcliptic(IERSConventions.IERS_1996).getName());
111 Assert.assertEquals("Ecliptic/2003",
112 FramesFactory.getEcliptic(IERSConventions.IERS_2003).getName());
113 Assert.assertEquals("Ecliptic/2010",
114 FramesFactory.getEcliptic(IERSConventions.IERS_2010).getName());
115 }
116
117
118
119
120 @Test
121 public void testGetParent() {
122
123 Frame frame = FramesFactory.getEcliptic(IERSConventions.IERS_2003);
124
125
126 MatcherAssert.assertThat(frame.getParent().getTransformProvider(),
127 IsInstanceOf.instanceOf(MODProvider.class));
128 }
129
130 @Test
131 public void testSerialization() throws IOException, ClassNotFoundException {
132 TransformProvider provider = new EclipticProvider(IERSConventions.IERS_2010);
133
134 ByteArrayOutputStream bos = new ByteArrayOutputStream();
135 ObjectOutputStream oos = new ObjectOutputStream(bos);
136 oos.writeObject(provider);
137
138 Assert.assertTrue(bos.size() > 200);
139 Assert.assertTrue(bos.size() < 250);
140
141 ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
142 ObjectInputStream ois = new ObjectInputStream(bis);
143 TransformProvider deserialized = (TransformProvider) ois.readObject();
144 for (double dt = 0; dt < Constants.JULIAN_DAY; dt += 3600) {
145 AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt);
146 Transform expectedIdentity = new Transform(date,
147 provider.getTransform(date).getInverse(),
148 deserialized.getTransform(date));
149 Assert.assertEquals(0.0, expectedIdentity.getTranslation().getNorm(), 1.0e-15);
150 Assert.assertEquals(0.0, expectedIdentity.getRotation().getAngle(), 1.0e-15);
151 }
152
153 }
154
155 }