1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.bodies;
18
19 import java.io.Serializable;
20 import java.text.NumberFormat;
21
22 import org.hipparchus.geometry.euclidean.threed.Vector3D;
23 import org.hipparchus.util.CompositeFormat;
24 import org.hipparchus.util.FastMath;
25 import org.hipparchus.util.MathUtils;
26 import org.hipparchus.util.SinCos;
27
28
29
30
31
32
33
34 public class GeodeticPoint implements Serializable {
35
36
37
38
39 public static final GeodeticPoint NORTH_POLE = new GeodeticPoint(+0.5 * FastMath.PI, 0.0, 0.0);
40
41
42
43
44 public static final GeodeticPoint SOUTH_POLE = new GeodeticPoint(-0.5 * FastMath.PI, 0.0, 0.0);
45
46
47 private static final long serialVersionUID = 7862466825590075399L;
48
49
50 private final double latitude;
51
52
53 private final double longitude;
54
55
56 private final double altitude;
57
58
59 private transient Vector3D zenith;
60
61
62 private transient Vector3D nadir;
63
64
65 private transient Vector3D north;
66
67
68 private transient Vector3D south;
69
70
71 private transient Vector3D east;
72
73
74 private transient Vector3D west;
75
76
77
78
79
80
81
82
83
84 public GeodeticPoint(final double latitude, final double longitude,
85 final double altitude) {
86 double lat = MathUtils.normalizeAngle(latitude, FastMath.PI / 2);
87 double lon = MathUtils.normalizeAngle(longitude, 0);
88 if (lat > FastMath.PI / 2.0) {
89
90 lat = FastMath.PI - lat;
91 lon = MathUtils.normalizeAngle(longitude + FastMath.PI, 0);
92 }
93 this.latitude = lat;
94 this.longitude = lon;
95 this.altitude = altitude;
96 }
97
98
99
100
101 public double getLatitude() {
102 return latitude;
103 }
104
105
106
107
108 public double getLongitude() {
109 return longitude;
110 }
111
112
113
114
115 public double getAltitude() {
116 return altitude;
117 }
118
119
120
121
122
123
124 public Vector3D getZenith() {
125 if (zenith == null) {
126 final SinCos scLat = FastMath.sinCos(latitude);
127 final SinCos scLon = FastMath.sinCos(longitude);
128 zenith = new Vector3D(scLon.cos() * scLat.cos(), scLon.sin() * scLat.cos(), scLat.sin());
129 }
130 return zenith;
131 }
132
133
134
135
136
137
138 public Vector3D getNadir() {
139 if (nadir == null) {
140 nadir = getZenith().negate();
141 }
142 return nadir;
143 }
144
145
146
147
148
149
150
151 public Vector3D getNorth() {
152 if (north == null) {
153 final SinCos scLat = FastMath.sinCos(latitude);
154 final SinCos scLon = FastMath.sinCos(longitude);
155 north = new Vector3D(-scLon.cos() * scLat.sin(), -scLon.sin() * scLat.sin(), scLat.cos());
156 }
157 return north;
158 }
159
160
161
162
163
164
165 public Vector3D getSouth() {
166 if (south == null) {
167 south = getNorth().negate();
168 }
169 return south;
170 }
171
172
173
174
175
176
177
178 public Vector3D getEast() {
179 if (east == null) {
180 final SinCos scLon = FastMath.sinCos(longitude);
181 east = new Vector3D(-scLon.sin(), scLon.cos(), 0);
182 }
183 return east;
184 }
185
186
187
188
189
190
191 public Vector3D getWest() {
192 if (west == null) {
193 west = getEast().negate();
194 }
195 return west;
196 }
197
198 @Override
199 public boolean equals(final Object object) {
200 if (object instanceof GeodeticPoint) {
201 final GeodeticPoint other = (GeodeticPoint) object;
202 return this.getLatitude() == other.getLatitude() &&
203 this.getLongitude() == other.getLongitude() &&
204 this.getAltitude() == other.getAltitude();
205 }
206 return false;
207 }
208
209 @Override
210 public int hashCode() {
211 return Double.valueOf(this.getLatitude()).hashCode() ^
212 Double.valueOf(this.getLongitude()).hashCode() ^
213 Double.valueOf(this.getAltitude()).hashCode();
214 }
215
216 @Override
217 public String toString() {
218 final NumberFormat format = CompositeFormat.getDefaultNumberFormat();
219 return "{lat: " +
220 format.format(FastMath.toDegrees(this.getLatitude())) +
221 " deg, lon: " +
222 format.format(FastMath.toDegrees(this.getLongitude())) +
223 " deg, alt: " +
224 format.format(this.getAltitude()) +
225 "}";
226 }
227 }