1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.frames;
18  
19  
20  import org.hipparchus.geometry.euclidean.threed.Rotation;
21  import org.hipparchus.geometry.euclidean.threed.RotationConvention;
22  import org.hipparchus.geometry.euclidean.threed.Vector3D;
23  import org.hipparchus.util.FastMath;
24  import org.junit.Assert;
25  import org.junit.Before;
26  import org.junit.Test;
27  import org.orekit.Utils;
28  import org.orekit.time.AbsoluteDate;
29  import org.orekit.time.DateComponents;
30  import org.orekit.time.TimeComponents;
31  import org.orekit.time.TimeScalesFactory;
32  import org.orekit.utils.IERSConventions;
33  import org.orekit.utils.PVCoordinates;
34  
35  
36  public class ITRFProviderWithoutTidalEffectsTest {
37  
38      @Test
39      public void testRoughRotation() {
40  
41          AbsoluteDate date1 = new AbsoluteDate(new DateComponents(2006, 02, 24),
42                                                new TimeComponents(15, 38, 00),
43                                                TimeScalesFactory.getUTC());
44          Frame itrf2008 = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
45          Transform t0 = itrf2008.getTransformTo(FramesFactory.getEME2000(), date1);
46  
47          double dt = 10.0;
48          AbsoluteDate date2 = date1.shiftedBy(dt);
49          Transform t1 = itrf2008.getTransformTo(FramesFactory.getEME2000(), date2);
50          Transform evolution = new Transform(date2, t0.getInverse(), t1);
51  
52          Vector3D p = new Vector3D(6000, 6000, 0);
53          Assert.assertEquals(0.0, evolution.transformPosition(Vector3D.ZERO).getNorm(), 1.0e-15);
54          Assert.assertEquals(0.0, evolution.transformVector(p).getZ(), 0.003);
55          Assert.assertEquals(2 * FastMath.PI * dt / 86164,
56                              Vector3D.angle(t0.transformVector(p), t1.transformVector(p)),
57                              1.0e-9);
58  
59      }
60  
61      @Test
62      public void testRoughOrientation() {
63  
64          AbsoluteDate date = new AbsoluteDate(2001, 03, 21, 0, 4, 0, TimeScalesFactory.getUTC());
65          Frame itrf2008 = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
66  
67          Vector3D u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I);
68          Assert.assertTrue(Vector3D.angle(u, Vector3D.MINUS_I) < FastMath.toRadians(0.5));
69  
70          date = date.shiftedBy(6 * 3600);
71          u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I);
72          Assert.assertTrue(Vector3D.angle(u, Vector3D.MINUS_J) < FastMath.toRadians(0.5));
73  
74          date = date.shiftedBy(6 * 3600);
75          u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I);
76          Assert.assertTrue(Vector3D.angle(u, Vector3D.PLUS_I) < FastMath.toRadians(0.5));
77  
78          date = date.shiftedBy(6 * 3600);
79          u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I);
80          Assert.assertTrue(Vector3D.angle(u, Vector3D.PLUS_J) < FastMath.toRadians(0.5));
81  
82      }
83  
84      @Test
85      public void testRoughERA() {
86  
87          AbsoluteDate date = new AbsoluteDate(2001, 03, 21, 0, 4, 0, TimeScalesFactory.getUTC());
88          TIRFProvider TIRF2000 = (TIRFProvider) FramesFactory.getTIRF(IERSConventions.IERS_2010).getTransformProvider();
89  
90          Assert.assertEquals(180, FastMath.toDegrees(TIRF2000.getEarthRotationAngle(date)), 0.5);
91  
92          date = date.shiftedBy(6 * 3600);
93          Assert.assertEquals(-90, FastMath.toDegrees(TIRF2000.getEarthRotationAngle(date)), 0.5);
94  
95          date = date.shiftedBy(6 * 3600);
96          Assert.assertEquals(0, FastMath.toDegrees(TIRF2000.getEarthRotationAngle(date)), 0.5);
97  
98          date = date.shiftedBy(6 * 3600);
99          Assert.assertEquals(90, FastMath.toDegrees(TIRF2000.getEarthRotationAngle(date)), 0.5);
100 
101     }
102 
103     @Test
104     public void testMSLIBTransformJ2000_TerVrai() {
105 
106         AbsoluteDate date = new AbsoluteDate(new DateComponents(2003, 10, 14),
107                                              new TimeComponents(02, 00, 00),
108                                              TimeScalesFactory.getUTC());
109         Transform trans = FramesFactory.getEME2000().getTransformTo(FramesFactory.getTIRF(IERSConventions.IERS_2010), date);
110 
111         // Positions
112         Vector3D posTIRF =
113             trans.transformPosition(new Vector3D(6500000.0, -1234567.0, 4000000.0));
114         Assert.assertEquals(0,  3011109.361 - posTIRF.getX(), 0.38);
115         Assert.assertEquals(0, -5889822.669 - posTIRF.getY(), 0.38);
116         Assert.assertEquals(0,  4002170.039 - posTIRF.getZ(), 0.27);
117 
118     }
119 
120     @Test
121     public void testMSLIBTransformJ2000_TerRef() {
122 
123         AbsoluteDate t0 = new AbsoluteDate(new DateComponents(2003, 10, 14),
124                                            new TimeComponents(02, 00, 00),
125                                            TimeScalesFactory.getUTC());
126         Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
127         Transform trans = FramesFactory.getEME2000().getTransformTo(itrf, t0);
128 
129         // Coordinates in EME2000
130         PVCoordinates pvEME2000 =
131             new PVCoordinates(new Vector3D(6500000.0, -1234567.0, 4000000.0),
132                               new Vector3D(3609.28229, 3322.88979, -7083.950661));
133 
134         // Reference coordinates in ITRF
135         PVCoordinates pvRef =
136             new PVCoordinates(new Vector3D(3011113.971820046, -5889827.854375269, 4002158.938875904),
137                               new Vector3D(4410.393506651586, -1033.61784235127, -7082.633883124906));
138 
139 
140         // tests using direct transform
141         checkPV(pvRef, trans.transformPVCoordinates(pvEME2000), 0.594, 1.79e-4);
142 
143         // compute local evolution using finite differences
144         double h = 1.0;
145         Rotation r0 = trans.getRotation();
146         AbsoluteDate date = t0.shiftedBy(-2 * h);
147         Rotation evoM2h = FramesFactory.getEME2000().getTransformTo(itrf, date).getRotation().compose(r0.revert(),
148                                                                                                       RotationConvention.VECTOR_OPERATOR);
149         double alphaM2h = -evoM2h.getAngle();
150         Vector3D axisM2h = evoM2h.getAxis(RotationConvention.VECTOR_OPERATOR);
151         date = t0.shiftedBy(-h);
152         Rotation evoM1h = FramesFactory.getEME2000().getTransformTo(itrf, date).getRotation().compose(r0.revert(),
153                                                                                                       RotationConvention.VECTOR_OPERATOR);
154         double alphaM1h = -evoM1h.getAngle();
155         Vector3D axisM1h = evoM1h.getAxis(RotationConvention.VECTOR_OPERATOR);
156         date = t0.shiftedBy(h);
157         Rotation evoP1h = FramesFactory.getEME2000().getTransformTo(itrf, date).getRotation().compose(r0.revert(),
158                                                                                                       RotationConvention.VECTOR_OPERATOR);
159         double alphaP1h =  evoP1h.getAngle();
160         Vector3D axisP1h = evoP1h.getAxis(RotationConvention.VECTOR_OPERATOR).negate();
161         date = t0.shiftedBy(2 * h);
162         Rotation evoP2h = FramesFactory.getEME2000().getTransformTo(itrf, date).getRotation().compose(r0.revert(),
163                                                                                                       RotationConvention.VECTOR_OPERATOR);
164         double alphaP2h =  evoP2h.getAngle();
165         Vector3D axisP2h = evoP2h.getAxis(RotationConvention.VECTOR_OPERATOR).negate();
166         double w = (8 * (alphaP1h - alphaM1h) - (alphaP2h - alphaM2h)) / (12 * h);
167         Vector3D axis = axisM2h.add(axisM1h).add(axisP1h.add(axisP2h)).normalize();
168         Transform finiteDiffTransform = new Transform(t0, trans.getRotation() , new Vector3D(w, axis));
169 
170         checkPV(pvRef, finiteDiffTransform.transformPVCoordinates(pvEME2000), 0.594, 1.78e-4);
171 
172     }
173 
174     @Test
175     public void testMontenbruck() {
176         AbsoluteDate t0 = new AbsoluteDate(new DateComponents(1999, 3, 4), TimeComponents.H00,
177                                            TimeScalesFactory.getGPS());
178         Transform trans = FramesFactory.getITRF(IERSConventions.IERS_2010, true).getTransformTo(FramesFactory.getGCRF(), t0);
179         PVCoordinates pvWGS =
180             new PVCoordinates(new Vector3D(19440953.805, 16881609.273, -6777115.092),
181                               new Vector3D(-811.1827456, -257.3799137, -3068.9508125));
182         checkPV(new PVCoordinates(new Vector3D(-23830592.685,  -9747073.881,  -6779831.010),
183                                   new Vector3D( 1561.9646362, -1754.3454485, -3068.8504996)),
184                                   trans.transformPVCoordinates(pvWGS), 0.146, 3.43e-5);
185 
186     }
187 
188     private void checkPV(PVCoordinates reference, PVCoordinates result,
189                          double expectedPositionError, double expectedVelocityError) {
190 
191         Vector3D dP = result.getPosition().subtract(reference.getPosition());
192         Vector3D dV = result.getVelocity().subtract(reference.getVelocity());
193         Assert.assertEquals(expectedPositionError, dP.getNorm(), 0.01 * expectedPositionError);
194         Assert.assertEquals(expectedVelocityError, dV.getNorm(), 0.01 * expectedVelocityError);
195     }
196 
197     @Before
198     public void setUp() {
199         Utils.setDataRoot("compressed-data");
200     }
201 
202 }