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.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  
34  /**Unit tests for {@link CR3BPRotatingTransformProvider}.
35   * @author Vincent Mouraux
36   */
37  public class TwoBodiesBaryFrameTest {
38  
39      @Test
40      public void testTransformationOrientationForEarthMoon() {
41  
42          // Load Bodies
43          final CelestialBody barycenter = CelestialBodyFactory.getEarthMoonBarycenter();
44          final CelestialBody earth = CelestialBodyFactory.getEarth();
45          final CelestialBody moon = CelestialBodyFactory.getMoon();
46          // Set frames
47          final Frame eme2000 = FramesFactory.getEME2000();
48          final Frame baryFrame = new TwoBodiesBaryFrame(earth,moon);
49  
50          // Time settings
51          final AbsoluteDate date = new AbsoluteDate(2000, 01, 01, 0, 0, 00.000,
52                                                     TimeScalesFactory.getUTC());
53  
54          // Compute barycenter position and our frame origin in EME2000
55          Vector3D truePosBary = barycenter.getPosition(date, eme2000);
56          Vector3D posBary   = baryFrame.getTransformTo(eme2000,date).transformPosition(Vector3D.ZERO);
57  
58          // check barycenter and Moon are aligned as seen from Earth
59          Assertions.assertEquals(truePosBary.getX(), posBary.getX(), 1.0e-8);
60          Assertions.assertEquals(truePosBary.getY(), posBary.getY(), 1.0e-8);
61          Assertions.assertEquals(truePosBary.getZ(), posBary.getZ(), 1.0e-8);
62      }
63  
64      @Test
65      public void testFieldTransformationOrientationForEarthMoon() {
66          doTestFieldTransformationOrientationForEarthMoon(Binary64Field.getInstance());
67      }
68  
69      private <T extends CalculusFieldElement<T>> void doTestFieldTransformationOrientationForEarthMoon(final Field<T> field) {
70  
71          // Load Bodies
72          final CelestialBody barycenter = CelestialBodyFactory.getEarthMoonBarycenter();
73          final CelestialBody earth = CelestialBodyFactory.getEarth();
74          final CelestialBody moon = CelestialBodyFactory.getMoon();
75          // Set frames
76          final Frame eme2000 = FramesFactory.getEME2000();
77          final Frame baryFrame = new TwoBodiesBaryFrame(earth,moon);
78  
79          // Time settings
80          final FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field, 2000, 01, 01, 0, 0, 00.000,
81                                                                    TimeScalesFactory.getUTC());
82  
83          // Compute barycenter position and our frame origin in EME2000
84          FieldVector3D<T> truePosBary = barycenter.getPosition(date, eme2000);
85          FieldVector3D<T> posBary   = baryFrame.getTransformTo(eme2000,date).transformPosition(Vector3D.ZERO);
86  
87          // check barycenter and Moon are aligned as seen from Earth
88          Assertions.assertEquals(truePosBary.getX().getReal(), posBary.getX().getReal(), 1.0e-8);
89          Assertions.assertEquals(truePosBary.getY().getReal(), posBary.getY().getReal(), 1.0e-8);
90          Assertions.assertEquals(truePosBary.getZ().getReal(), posBary.getZ().getReal(), 1.0e-8);
91      }
92  
93      @BeforeEach
94      public void setUp() {
95          Utils.setDataRoot("regular-data");
96      }
97  
98  }