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