1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.attitudes;
18
19 import org.hipparchus.geometry.euclidean.threed.Rotation;
20 import org.hipparchus.geometry.euclidean.threed.Vector3D;
21 import org.hipparchus.util.FastMath;
22 import org.junit.jupiter.api.Assertions;
23 import org.junit.jupiter.api.Test;
24 import org.orekit.frames.FramesFactory;
25 import org.orekit.time.AbsoluteDate;
26 import org.orekit.utils.AngularCoordinates;
27
28 public class AttitudeTest {
29
30 @Test
31 void testZeroRate() {
32
33 Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(),
34 new Rotation(0.48, 0.64, 0.36, 0.48, false),
35 Vector3D.ZERO, Vector3D.ZERO);
36 Assertions.assertEquals(Vector3D.ZERO, attitude.getSpin());
37 double dt = 10.0;
38 Attitude shifted = attitude.shiftedBy(dt);
39 Assertions.assertEquals(Vector3D.ZERO, shifted.getRotationAcceleration());
40 Assertions.assertEquals(Vector3D.ZERO, shifted.getSpin());
41 Assertions.assertEquals(0.0, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-15);
42 }
43
44 @Test
45 void testShift() {
46
47 double rate = 2 * FastMath.PI / (12 * 60);
48 Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(),
49 Rotation.IDENTITY,
50 new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO);
51 Assertions.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10);
52 double dt = 10.0;
53 double alpha = rate * dt;
54 Attitude shifted = attitude.shiftedBy(dt);
55 Assertions.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10);
56 Assertions.assertEquals(alpha, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10);
57
58 Vector3D xSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I);
59 Assertions.assertEquals(0.0, xSat.subtract(new Vector3D(FastMath.cos(alpha), FastMath.sin(alpha), 0)).getNorm(), 1.0e-10);
60 Vector3D ySat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J);
61 Assertions.assertEquals(0.0, ySat.subtract(new Vector3D(-FastMath.sin(alpha), FastMath.cos(alpha), 0)).getNorm(), 1.0e-10);
62 Vector3D zSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K);
63 Assertions.assertEquals(0.0, zSat.subtract(Vector3D.PLUS_K).getNorm(), 1.0e-10);
64
65 }
66
67 @Test
68 void testSpin() {
69
70 double rate = 2 * FastMath.PI / (12 * 60);
71 Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(),
72 new Rotation(0.48, 0.64, 0.36, 0.48, false),
73 new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO);
74 Assertions.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10);
75 double dt = 10.0;
76 Attitude shifted = attitude.shiftedBy(dt);
77 Assertions.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10);
78 Assertions.assertEquals(rate * dt, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10);
79
80 Vector3D shiftedX = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I);
81 Vector3D shiftedY = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J);
82 Vector3D shiftedZ = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K);
83 Vector3D originalX = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I);
84 Vector3D originalY = attitude.getRotation().applyInverseTo(Vector3D.PLUS_J);
85 Vector3D originalZ = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K);
86 Assertions.assertEquals( FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedX, originalX), 1.0e-10);
87 Assertions.assertEquals( FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedX, originalY), 1.0e-10);
88 Assertions.assertEquals( 0.0, Vector3D.dotProduct(shiftedX, originalZ), 1.0e-10);
89 Assertions.assertEquals(-FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedY, originalX), 1.0e-10);
90 Assertions.assertEquals( FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedY, originalY), 1.0e-10);
91 Assertions.assertEquals( 0.0, Vector3D.dotProduct(shiftedY, originalZ), 1.0e-10);
92 Assertions.assertEquals( 0.0, Vector3D.dotProduct(shiftedZ, originalX), 1.0e-10);
93 Assertions.assertEquals( 0.0, Vector3D.dotProduct(shiftedZ, originalY), 1.0e-10);
94 Assertions.assertEquals( 1.0, Vector3D.dotProduct(shiftedZ, originalZ), 1.0e-10);
95
96 Vector3D forward = AngularCoordinates.estimateRate(attitude.getRotation(), shifted.getRotation(), dt);
97 Assertions.assertEquals(0.0, forward.subtract(attitude.getSpin()).getNorm(), 1.0e-10);
98
99 Vector3D reversed = AngularCoordinates.estimateRate(shifted.getRotation(), attitude.getRotation(), dt);
100 Assertions.assertEquals(0.0, reversed.add(attitude.getSpin()).getNorm(), 1.0e-10);
101
102 }
103
104 }
105