1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.bodies;
18
19 import org.hipparchus.CalculusFieldElement;
20 import org.hipparchus.complex.Complex;
21 import org.hipparchus.complex.ComplexField;
22 import org.hipparchus.geometry.euclidean.threed.Vector3D;
23 import org.hipparchus.util.Binary64;
24 import org.hipparchus.util.Binary64Field;
25 import org.hipparchus.util.FastMath;
26 import org.junit.jupiter.api.Assertions;
27 import org.junit.jupiter.api.Test;
28
29
30
31
32
33
34
35 public class FieldGeodeticPointTest {
36
37
38
39
40
41 @Test
42 void testGeodeticPointAngleNormalization() {
43
44 FieldGeodeticPoint<Binary64> point =
45 new FieldGeodeticPoint<>(new Binary64(FastMath.toRadians(135)),
46 new Binary64(FastMath.toRadians(90 - 360)),
47 new Binary64(0));
48
49
50 Assertions.assertEquals(FastMath.toRadians(45), point.getLatitude().getReal(), 1.0e-15);
51 Assertions.assertEquals(FastMath.toRadians(-90), point.getLongitude().getReal(), 1.0e-15);
52
53 Assertions.assertEquals(0, Vector3D.distance(point.getEast().toVector3D(), Vector3D.PLUS_I), 1.0e-15);
54 Assertions.assertEquals(0, Vector3D.distance(point.getNorth().toVector3D(), new Vector3D( 0.50 * FastMath.PI, 0.25 * FastMath.PI)), 1.0e-15);
55 Assertions.assertEquals(0, Vector3D.distance(point.getWest().toVector3D(), Vector3D.MINUS_I), 1.0e-15);
56 Assertions.assertEquals(0, Vector3D.distance(point.getSouth().toVector3D(), new Vector3D(-0.50 * FastMath.PI, -0.25 * FastMath.PI)), 1.0e-15);
57 Assertions.assertEquals(0, Vector3D.distance(point.getZenith().toVector3D(), new Vector3D(-0.50 * FastMath.PI, 0.25 * FastMath.PI)), 1.0e-15);
58 Assertions.assertEquals(0, Vector3D.distance(point.getNadir().toVector3D(), new Vector3D( 0.50 * FastMath.PI, -0.25 * FastMath.PI)), 1.0e-15);
59
60 }
61
62
63
64
65
66 @Test
67 void testGeodeticPoint() {
68
69
70 final double pi = FastMath.PI;
71 double[][] points = {
72
73
74 { pi / 6, pi / 6, pi / 6, pi / 6 },
75
76 { 4 * pi / 6, 4 * pi / 6, pi / 3, -pi / 3 },
77
78 { 7 * pi / 6, 7 * pi / 6, -pi / 6, pi / 6 },
79
80 { -pi / 6, -pi / 6, -pi / 6, -pi / 6 },
81 { -4 * pi / 6, -4 * pi / 6, -pi / 3, pi / 3 },
82 { -pi / 6, -4 * pi / 3, -pi / 6, 2 * pi / 3 } };
83
84 for (double[] point : points) {
85
86 FieldGeodeticPoint<Binary64> gp =
87 new FieldGeodeticPoint<>(new Binary64(point[0]),
88 new Binary64(point[1]),
89 Binary64.ZERO);
90 Assertions.assertEquals(0, gp.getEast().crossProduct(gp.getNorth()).distance(gp.getZenith()).getReal(), 1.0e-15);
91 Assertions.assertEquals(0, gp.getNorth().crossProduct(gp.getWest()).distance(gp.getZenith()).getReal(), 1.0e-15);
92 Assertions.assertEquals(0, gp.getSouth().crossProduct(gp.getWest()).distance(gp.getNadir()).getReal(), 1.0e-15);
93 Assertions.assertEquals(0, gp.getEast().crossProduct(gp.getSouth()).distance(gp.getNadir()).getReal(), 1.0e-15);
94 Assertions.assertEquals(0, gp.getZenith().crossProduct(gp.getSouth()).distance(gp.getEast()).getReal(), 1.0e-15);
95 Assertions.assertEquals(0, gp.getNadir().crossProduct(gp.getWest()).distance(gp.getNorth()).getReal(), 1.0e-15);
96
97
98 Assertions.assertEquals(point[2], gp.getLatitude().getReal(), 5 * FastMath.ulp(point[2]));
99 Assertions.assertEquals(point[3], gp.getLongitude().getReal(), 5 * FastMath.ulp(point[3]));
100 }
101 }
102
103
104
105
106 @Test
107 void testEquals() {
108
109 FieldGeodeticPoint<Binary64> point =
110 new FieldGeodeticPoint<>(new Binary64(1),
111 new Binary64(2),
112 new Binary64(3));
113
114
115 Assertions.assertEquals(point, new FieldGeodeticPoint<>(Binary64Field.getInstance(),
116 new GeodeticPoint(1, 2, 3)));
117 Assertions.assertNotEquals(point, new FieldGeodeticPoint<>(new Binary64(0), new Binary64(2), new Binary64(3)));
118 Assertions.assertNotEquals(point, new FieldGeodeticPoint<>(new Binary64(1), new Binary64(0), new Binary64(3)));
119 Assertions.assertNotEquals(point,new FieldGeodeticPoint<>(new Binary64(1), new Binary64(2), new Binary64(0)));
120 Assertions.assertNotEquals(point, new Object());
121 Assertions.assertEquals(point.hashCode(),
122 new FieldGeodeticPoint<>(new Binary64(1),
123 new Binary64(2),
124 new Binary64(3)).hashCode());
125 Assertions.assertNotEquals(point.hashCode(),
126 new FieldGeodeticPoint<>(new Binary64(1),
127 new Binary64(FastMath.nextUp(2)),
128 new Binary64(3)).hashCode());
129 }
130
131
132
133
134 @Test
135 void testToString() {
136
137 FieldGeodeticPoint<Binary64> point =
138 new FieldGeodeticPoint<>(new Binary64(FastMath.toRadians(30)),
139 new Binary64(FastMath.toRadians(60)),
140 new Binary64(90));
141
142
143 String actual = point.toString();
144
145
146 Assertions.assertEquals("{lat: 30 deg, lon: 60 deg, alt: 90}", actual);
147 }
148
149 @Test
150 void testToGeodeticPoint() {
151
152 final GeodeticPoint geodeticPoint = new GeodeticPoint(1., 2., 3.);
153 final ComplexField field = ComplexField.getInstance();
154 final FieldGeodeticPoint<Complex> fieldGeodeticPoint = new FieldGeodeticPoint<>(field, geodeticPoint);
155
156 final GeodeticPoint actualPoint = fieldGeodeticPoint.toGeodeticPoint();
157
158 Assertions.assertEquals(geodeticPoint.getAltitude(), actualPoint.getAltitude());
159 Assertions.assertEquals(geodeticPoint.getLatitude(), actualPoint.getLatitude());
160 Assertions.assertEquals(geodeticPoint.getLongitude(), actualPoint.getLongitude());
161 }
162
163 }