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