1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.frames.encounter;
18
19 import org.hipparchus.Field;
20 import org.hipparchus.geometry.euclidean.threed.FieldRotation;
21 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
22 import org.hipparchus.geometry.euclidean.threed.Rotation;
23 import org.hipparchus.geometry.euclidean.threed.Vector3D;
24 import org.hipparchus.geometry.euclidean.twod.Vector2D;
25 import org.hipparchus.linear.BlockFieldMatrix;
26 import org.hipparchus.linear.BlockRealMatrix;
27 import org.hipparchus.linear.FieldMatrix;
28 import org.hipparchus.linear.RealMatrix;
29 import org.hipparchus.util.Binary64;
30 import org.hipparchus.util.Binary64Field;
31 import org.hipparchus.util.FastMath;
32 import org.hipparchus.util.MathUtils;
33 import org.hipparchus.util.SinCos;
34 import org.junit.jupiter.api.Assertions;
35 import org.junit.jupiter.api.DisplayName;
36 import org.junit.jupiter.api.Test;
37 import org.mockito.Mockito;
38 import org.orekit.TestUtils;
39 import org.orekit.frames.LOF;
40 import org.orekit.utils.FieldPVCoordinates;
41 import org.orekit.utils.PVCoordinates;
42
43 class ValsecchiEncounterFrameTest {
44
45 @Test
46 @DisplayName("Test rotationFromInertial method")
47 void testReturnExpectedRotation() {
48
49 final PVCoordinates originPV = new PVCoordinates(new Vector3D(6378000. + 400000., 0., 0.),
50 new Vector3D(0., 7668.63, 0.));
51
52 final PVCoordinates otherPV = new PVCoordinates(new Vector3D(6378000. + 400000 + 1., 0., 0.),
53 new Vector3D(0., 0., 7668.63));
54
55 final EncounterLOF encounterFrame = new ValsecchiEncounterFrame(otherPV);
56
57
58 final Rotation computedRotation = encounterFrame.rotationFromInertial(originPV);
59 final RealMatrix computedRotationMatrix = new BlockRealMatrix(computedRotation.getMatrix());
60
61
62 final SinCos sinCos = FastMath.sinCos(MathUtils.SEMI_PI * 1.5);
63 final double sin = sinCos.sin();
64 final double cos = sinCos.cos();
65
66 final RealMatrix expectedRotationMatrix = new BlockRealMatrix(
67 new double[][] { { 1, 0, 0 }, { 0, cos, sin }, { 0, -sin, cos } });
68
69 TestUtils.validateRealMatrix(expectedRotationMatrix, computedRotationMatrix, 1e-15);
70
71 }
72
73 @Test
74 @DisplayName("Test rotationFromInertial (field version) method")
75 void testReturnExpectedFieldRotation() {
76
77 final Binary64Field field = Binary64Field.getInstance();
78 final FieldPVCoordinates<Binary64> originPV = new FieldPVCoordinates<>(field, new PVCoordinates(
79 new Vector3D(6378000. + 400000., 0., 0.), new Vector3D(0., 7668.63, 0.)));
80
81 final PVCoordinates otherPV = new PVCoordinates(new Vector3D(6378000. + 400000 + 1., 0., 0.),
82 new Vector3D(0., 0., 7668.63));
83
84 final EncounterLOF encounterFrame = new ValsecchiEncounterFrame(otherPV);
85
86
87 final FieldRotation<Binary64> computedRotation = encounterFrame.rotationFromInertial(field, originPV);
88 final FieldMatrix<Binary64> computedRotationMatrix = new BlockFieldMatrix<>(computedRotation.getMatrix());
89
90
91 final SinCos sinCos = FastMath.sinCos(MathUtils.SEMI_PI * 1.5);
92 final double sin = sinCos.sin();
93 final double cos = sinCos.cos();
94
95 final RealMatrix expectedRotationMatrix = new BlockRealMatrix(
96 new double[][] { { 1, 0, 0 }, { 0, cos, sin }, { 0, -sin, cos } });
97
98 TestUtils.validateFieldMatrix(expectedRotationMatrix, computedRotationMatrix, 1e-15);
99 }
100
101 @Test
102 @DisplayName("Test isQuasiInertial method")
103 void testReturnTrue() {
104
105 final PVCoordinates otherMock = Mockito.mock(PVCoordinates.class);
106
107 final LOF encounterLOF = new ValsecchiEncounterFrame(otherMock);
108
109
110 final boolean returnedInertialFlag = encounterLOF.isQuasiInertial();
111
112
113 Assertions.assertTrue(returnedInertialFlag);
114
115 }
116
117 @Test
118 @DisplayName("Test projectOntoCollisionPlane")
119 void testReturnExpectedProjectedMatrix() {
120
121 final PVCoordinates otherPV = Mockito.mock(PVCoordinates.class);
122
123 final RealMatrix matrixInEncounterFrame = new BlockRealMatrix(new double[][] {
124 { 1, 2, 3 },
125 { 4, 5, 6 },
126 { 7, 8, 9 }
127 });
128
129 final EncounterLOF encounterFrame = new ValsecchiEncounterFrame(otherPV);
130
131
132 final RealMatrix computedProjectedMatrix = encounterFrame.projectOntoCollisionPlane(matrixInEncounterFrame);
133
134
135 final RealMatrix expectedProjectedMatrix = new BlockRealMatrix(new double[][] {
136 { 1, 3 },
137 { 7, 9 }
138 });
139
140 TestUtils.validateRealMatrix(expectedProjectedMatrix, computedProjectedMatrix, 1e-15);
141
142 }
143
144 @Test
145 @DisplayName("Test projectOntoCollisionPlane")
146 void testReturnExpectedProjectedVector() {
147
148 final PVCoordinates otherPVMock = Mockito.mock(PVCoordinates.class);
149
150 final Vector3D vectorInEncounterFrame = new Vector3D(1, 2, 3);
151
152 final EncounterLOF encounterFrame = new ValsecchiEncounterFrame(otherPVMock);
153
154
155 final Vector2D computedProjectedVector = encounterFrame.projectOntoCollisionPlane(vectorInEncounterFrame);
156
157
158 final Vector2D expectedProjectedVector = new Vector2D(1, 3);
159
160 TestUtils.validateVector2D(expectedProjectedVector, computedProjectedVector, 1e-15);
161
162 }
163
164 @Test
165 @DisplayName("Test getAxisNormalToCollisionPlane")
166 void testReturnExpectedAxisNormalToCollisionPlane() {
167
168 final Field<Binary64> field = Binary64Field.getInstance();
169
170 final PVCoordinates pvMock = Mockito.mock(PVCoordinates.class);
171
172 final EncounterLOF encounterFrame = new ValsecchiEncounterFrame(pvMock);
173
174
175 final Vector3D gottenAxis = encounterFrame.getAxisNormalToCollisionPlane();
176 final FieldVector3D<Binary64> gottenFieldAxis = encounterFrame.getAxisNormalToCollisionPlane(field);
177
178
179 final Vector3D expectedAxis = new Vector3D(0, 1, 0);
180
181 TestUtils.validateVector3D(expectedAxis, gottenAxis, 1e-15);
182 TestUtils.validateFieldVector3D(expectedAxis, gottenFieldAxis, 1e-15);
183 }
184
185 @Test
186 void testReturnExpectedName() {
187
188 final PVCoordinates pvMock = Mockito.mock(PVCoordinates.class);
189
190 final ValsecchiEncounterFrame encounterLOF = new ValsecchiEncounterFrame(pvMock);
191
192
193 final String name = encounterLOF.getName();
194
195
196 final String expectedName = "VALSECCHI_ENCOUNTER_LOF";
197
198 Assertions.assertEquals(expectedName, name);
199 }
200
201 }