1   /* Copyright 2022-2025 Luc Maisonobe
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.estimation.measurements.modifiers;
18  
19  import org.hipparchus.geometry.euclidean.threed.Rotation;
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.hipparchus.random.RandomGenerator;
22  import org.hipparchus.random.Well1024a;
23  import org.hipparchus.util.FastMath;
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.frames.Transform;
28  import org.orekit.gnss.antenna.FrequencyPattern;
29  import org.orekit.gnss.antenna.OneDVariation;
30  import org.orekit.time.AbsoluteDate;
31  import org.orekit.utils.AngularCoordinates;
32  import org.orekit.utils.PVCoordinates;
33  
34  public class PhaseCentersOffsetComputerTest {
35  
36      @Test
37      public void testAllZero() {
38          PhaseCentersOffsetComputer computer =
39                          new PhaseCentersOffsetComputer(FrequencyPattern.ZERO_CORRECTION,
40                                                         FrequencyPattern.ZERO_CORRECTION);
41          final RandomGenerator random = new Well1024a(0xb84f12fc3ba761d6l);
42          for (int i = 0; i < 1000; ++i) {
43              final Transform eTransform = new Transform(emitterToInert.getDate(), emitterToInert,
44                                                         randomTransform(random, emitterToInert.getDate()));
45              final Transform rTransform = new Transform(reveiverToInert.getDate(), reveiverToInert,
46                                                         randomTransform(random, reveiverToInert.getDate()));
47              Assertions.assertEquals(0.0, computer.offset(eTransform, rTransform), 1.0e-15);
48          }
49      }
50  
51      @Test
52      public void testPCVWithoutEffect() {
53          PhaseCentersOffsetComputer computer =
54                          new PhaseCentersOffsetComputer(new FrequencyPattern(Vector3D.ZERO,
55                                                                              new OneDVariation(0.0, FastMath.PI,
56                                                                                                new double[] { 0.0, 0.0 })),
57                                                         new FrequencyPattern(Vector3D.ZERO,
58                                                                              new OneDVariation(0.0, FastMath.PI,
59                                                                                                new double[] { 0.0, 0.0 })));
60          final RandomGenerator random = new Well1024a(0x787f77a831792a43l);
61          for (int i = 0; i < 1000; ++i) {
62              final Transform eTransform = new Transform(emitterToInert.getDate(), emitterToInert,
63                                                         randomTransform(random, emitterToInert.getDate()));
64              final Transform rTransform = new Transform(reveiverToInert.getDate(), reveiverToInert,
65                                                         randomTransform(random, reveiverToInert.getDate()));
66              Assertions.assertEquals(0.0, computer.offset(eTransform, rTransform), 1.0e-15);
67          }
68      }
69  
70      @Test
71      public void testOnlyMeanOffset() {
72          PhaseCentersOffsetComputer computer =
73                          new PhaseCentersOffsetComputer(new FrequencyPattern(new Vector3D(0, -1, 1), null),
74                                                         new FrequencyPattern(new Vector3D(-1, 0, 0), null));
75          Assertions.assertEquals(4.0 - FastMath.sqrt(5.0),
76                                  computer.offset(emitterToInert, reveiverToInert),
77                                  1.0e-15);
78      }
79  
80      @Test
81      public void testComplete() {
82          for (double pcvE = -1.0; pcvE < 1.0; pcvE += 0.015625) {
83              for (double pcvR = -1.0; pcvR < 1.0; pcvR += 0.015625) {
84                  PhaseCentersOffsetComputer computer =
85                                  new PhaseCentersOffsetComputer(new FrequencyPattern(new Vector3D(0, -1, 1),
86                                                                                      new OneDVariation(0.0, 0.5 * FastMath.PI,
87                                                                                                        new double[] { 0.0, pcvE, 10.0 })),
88                                                                 new FrequencyPattern(new Vector3D(-1, 0, 0),
89                                                                                      new OneDVariation(0.0, 0.5 * FastMath.PI,
90                                                                                                        new double[] { 0.0, pcvR, 12.0 })));
91                  Assertions.assertEquals(4.0 - FastMath.sqrt(5.0) + pcvE + pcvR,
92                                          computer.offset(emitterToInert, reveiverToInert),
93                                          1.0e-15);
94              }
95          }
96      }
97  
98      @BeforeEach
99      public void setUp() {
100 
101         emitterToInert  = new Transform(AbsoluteDate.ARBITRARY_EPOCH,
102                                         new PVCoordinates(new Vector3D(0, -2, -2)),
103                                         new AngularCoordinates(new Rotation(Vector3D.PLUS_I, Vector3D.PLUS_J,
104                                                                             Vector3D.PLUS_K, Vector3D.MINUS_I)));
105 
106         Assertions.assertEquals(0.0, Vector3D.distance(new Vector3D(2, 2, 0), emitterToInert.transformPosition(Vector3D.ZERO)),   1.0e-15);
107         Assertions.assertEquals(0.0, Vector3D.distance(new Vector3D(2, 2, 1), emitterToInert.transformPosition(Vector3D.PLUS_I)), 1.0e-15);
108         Assertions.assertEquals(0.0, Vector3D.distance(new Vector3D(1, 2, 0), emitterToInert.transformPosition(Vector3D.PLUS_J)), 1.0e-15);
109         Assertions.assertEquals(0.0, Vector3D.distance(new Vector3D(2, 1, 0), emitterToInert.transformPosition(Vector3D.PLUS_K)), 1.0e-15);
110 
111         reveiverToInert = new Transform(AbsoluteDate.ARBITRARY_EPOCH,
112                                        new PVCoordinates(new Vector3D(0, 1, 0)),
113                                        new AngularCoordinates(Rotation.IDENTITY));
114         Assertions.assertEquals(0.0, Vector3D.distance(new Vector3D(0, 1, 0), reveiverToInert.transformPosition(Vector3D.ZERO)),   1.0e-15);
115         Assertions.assertEquals(0.0, Vector3D.distance(new Vector3D(1, 1, 0), reveiverToInert.transformPosition(Vector3D.PLUS_I)), 1.0e-15);
116         Assertions.assertEquals(0.0, Vector3D.distance(new Vector3D(0, 2, 0), reveiverToInert.transformPosition(Vector3D.PLUS_J)), 1.0e-15);
117         Assertions.assertEquals(0.0, Vector3D.distance(new Vector3D(0, 1, 1), reveiverToInert.transformPosition(Vector3D.PLUS_K)), 1.0e-15);
118 
119     }
120 
121     private Transform randomTransform(final RandomGenerator random, final AbsoluteDate date) {
122         return new Transform(date,
123                              new PVCoordinates(randomVector(random)),
124                              new AngularCoordinates(randomRotation(random)));
125     }
126 
127     private Vector3D randomVector(final RandomGenerator random) {
128         return new Vector3D(random.nextDouble(), random.nextDouble(), random.nextDouble());
129     }
130 
131     private Rotation randomRotation(final RandomGenerator random) {
132         return new Rotation(random.nextDouble(), random.nextDouble(), random.nextDouble(), random.nextDouble(),
133                             true);
134     }
135 
136     Transform emitterToInert;
137     Transform reveiverToInert;
138 
139 }
140 
141