1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.orekit.utils;
19
20 import org.hipparchus.geometry.euclidean.threed.Vector3D;
21 import org.hipparchus.linear.MatrixUtils;
22 import org.hipparchus.linear.RealMatrix;
23 import org.junit.jupiter.api.Assertions;
24 import org.junit.jupiter.api.Test;
25 import org.junit.jupiter.params.ParameterizedTest;
26 import org.junit.jupiter.params.provider.EnumSource;
27 import org.orekit.frames.*;
28 import org.orekit.orbits.CartesianOrbit;
29 import org.orekit.orbits.OrbitType;
30 import org.orekit.orbits.PositionAngleType;
31 import org.orekit.propagation.StateCovariance;
32 import org.orekit.time.AbsoluteDate;
33
34 class CartesianCovarianceUtilsTest {
35
36 @Test
37 void testConvertToLofType() {
38
39 final Frame inputFrame = FramesFactory.getEME2000();
40 final Frame outputFrame = FramesFactory.getGCRF();
41 final RealMatrix matrix = buildSomeMatrix();
42 final AbsoluteDate date = AbsoluteDate.ARBITRARY_EPOCH;
43
44 final RealMatrix actualMatrix = CartesianCovarianceUtils.changeReferenceFrame(inputFrame, matrix, date,
45 outputFrame);
46
47 final Transform transform = inputFrame.getTransformTo(outputFrame, date);
48 final RealMatrix jacobianMatrix = MatrixUtils.createRealMatrix(transform.getPVJacobian());
49 final RealMatrix expectedMatrix = jacobianMatrix.multiply(matrix).multiplyTransposed(jacobianMatrix);
50 Assertions.assertEquals(0., expectedMatrix.subtract(actualMatrix).getNorm1(), 1e-15);
51 }
52
53 @ParameterizedTest
54 @EnumSource(value = LOFType.class, names = {"QSW_INERTIAL", "TNW_INERTIAL", "LVLH_INERTIAL", "NTW_INERTIAL"})
55 void testConvertToLofType(final LOFType lofType) {
56
57 final Vector3D position = new Vector3D(1.0, 2.0, 3.0);
58 final Vector3D velocity = new Vector3D(4., -0.5);
59 final RealMatrix matrix = buildSomeMatrix();
60
61 final RealMatrix actualMatrix = CartesianCovarianceUtils.convertToLofType(position, velocity, matrix, lofType);
62
63 final StateCovariance covariance = new StateCovariance(matrix, AbsoluteDate.ARBITRARY_EPOCH,
64 FramesFactory.getGCRF(), OrbitType.CARTESIAN, null);
65 final CartesianOrbit orbit = new CartesianOrbit(new PVCoordinates(position, velocity), covariance.getFrame(),
66 covariance.getDate(), 1.);
67 final RealMatrix expectedMatrix = covariance.changeCovarianceFrame(orbit, lofType).getMatrix();
68 Assertions.assertEquals(0, expectedMatrix.subtract(actualMatrix).getNorm1(), 1e-15);
69 }
70
71 @ParameterizedTest
72 @EnumSource(LOFType.class)
73 void testConvertFromLofType(final LOFType lofType) {
74
75 final Vector3D position = new Vector3D(1.0, 2.0, 3.0);
76 final Vector3D velocity = new Vector3D(4., -0.5);
77 final RealMatrix expectedMatrix = buildSomeMatrix();
78
79 final RealMatrix matrix = CartesianCovarianceUtils.convertToLofType(position, velocity, expectedMatrix, lofType);
80
81 final RealMatrix actualMatrix = CartesianCovarianceUtils.convertFromLofType(lofType, matrix, position, velocity);
82 Assertions.assertEquals(0., expectedMatrix.subtract(actualMatrix).getNorm1(), 1e-14);
83 }
84
85 private static RealMatrix buildSomeMatrix() {
86 final RealMatrix matrix = MatrixUtils.createRealIdentityMatrix(6);
87 final double entry = 0.4;
88 final int index2 = 2;
89 final int index3 = 3;
90 matrix.setEntry(index3, index3, entry);
91 matrix.setEntry(index2, index2, entry);
92 final int index4 = 4;
93 final int index5 = 5;
94 final double otherEntry = -0.2;
95 matrix.setEntry(index4, index5, otherEntry);
96 matrix.setEntry(index5, index4, otherEntry);
97 return matrix;
98 }
99
100 }