1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.irurueta.navigation.frames;
17
18 import com.irurueta.units.Angle;
19 import com.irurueta.units.AngleConverter;
20 import com.irurueta.units.AngleUnit;
21 import com.irurueta.units.Distance;
22 import com.irurueta.units.DistanceConverter;
23 import com.irurueta.units.DistanceUnit;
24
25 import java.io.Serializable;
26 import java.util.Objects;
27
28
29
30
31 public class NEDPosition implements Serializable, Cloneable {
32
33
34
35
36 private double latitude;
37
38
39
40
41 private double longitude;
42
43
44
45
46 private double height;
47
48
49
50
51 public NEDPosition() {
52 }
53
54
55
56
57
58
59
60
61 public NEDPosition(final double latitude, final double longitude, final double height) {
62 setCoordinates(latitude, longitude, height);
63 }
64
65
66
67
68
69
70
71
72 public NEDPosition(final Angle latitude, final Angle longitude, final Distance height) {
73 setCoordinates(latitude, longitude, height);
74 }
75
76
77
78
79
80
81 public NEDPosition(final NEDPosition input) {
82 copyFrom(input);
83 }
84
85
86
87
88
89
90 public double getLatitude() {
91 return latitude;
92 }
93
94
95
96
97
98
99 public void setLatitude(final double latitude) {
100 this.latitude = latitude;
101 }
102
103
104
105
106
107
108 public double getLongitude() {
109 return longitude;
110 }
111
112
113
114
115
116
117 public void setLongitude(final double longitude) {
118 this.longitude = longitude;
119 }
120
121
122
123
124
125
126 public double getHeight() {
127 return height;
128 }
129
130
131
132
133
134
135 public void setHeight(final double height) {
136 this.height = height;
137 }
138
139
140
141
142
143
144
145
146 public void setCoordinates(final double latitude, final double longitude, final double height) {
147 this.latitude = latitude;
148 this.longitude = longitude;
149 this.height = height;
150 }
151
152
153
154
155
156
157 public void getLatitudeAngle(final Angle result) {
158 result.setValue(latitude);
159 result.setUnit(AngleUnit.RADIANS);
160 }
161
162
163
164
165
166
167 public Angle getLatitudeAngle() {
168 return new Angle(latitude, AngleUnit.RADIANS);
169 }
170
171
172
173
174
175
176 public void setLatitudeAngle(final Angle latitude) {
177 this.latitude = AngleConverter.convert(latitude.getValue().doubleValue(), latitude.getUnit(),
178 AngleUnit.RADIANS);
179 }
180
181
182
183
184
185
186 public void getLongitudeAngle(final Angle result) {
187 result.setValue(longitude);
188 result.setUnit(AngleUnit.RADIANS);
189 }
190
191
192
193
194
195
196 public Angle getLongitudeAngle() {
197 return new Angle(longitude, AngleUnit.RADIANS);
198 }
199
200
201
202
203
204
205 public void setLongitudeAngle(final Angle longitude) {
206 this.longitude = AngleConverter.convert(longitude.getValue().doubleValue(), longitude.getUnit(),
207 AngleUnit.RADIANS);
208 }
209
210
211
212
213
214
215 public void getHeightDistance(final Distance result) {
216 result.setValue(height);
217 result.setUnit(DistanceUnit.METER);
218 }
219
220
221
222
223
224
225 public Distance getHeightDistance() {
226 return new Distance(height, DistanceUnit.METER);
227 }
228
229
230
231
232
233
234 public void setHeightDistance(final Distance height) {
235 this.height = DistanceConverter.convert(height.getValue().doubleValue(), height.getUnit(), DistanceUnit.METER);
236 }
237
238
239
240
241
242
243
244
245 public void setCoordinates(
246 final Angle latitude, final Angle longitude, final Distance height) {
247 setLatitudeAngle(latitude);
248 setLongitudeAngle(longitude);
249 setHeightDistance(height);
250 }
251
252
253
254
255
256
257 public void copyTo(final NEDPosition output) {
258 output.latitude = latitude;
259 output.longitude = longitude;
260 output.height = height;
261 }
262
263
264
265
266
267
268 public void copyFrom(final NEDPosition input) {
269 latitude = input.latitude;
270 longitude = input.longitude;
271 height = input.height;
272 }
273
274
275
276
277
278
279
280 @Override
281 public int hashCode() {
282 return Objects.hash(latitude, longitude, height);
283 }
284
285
286
287
288
289
290
291
292 @Override
293 public boolean equals(final Object obj) {
294 if (obj == null) {
295 return false;
296 }
297 if (obj == this) {
298 return true;
299 }
300 if (!(obj instanceof NEDPosition other)) {
301 return false;
302 }
303
304 return equals(other);
305 }
306
307
308
309
310
311
312
313 public boolean equals(final NEDPosition other) {
314 return equals(other, 0.0);
315 }
316
317
318
319
320
321
322
323
324
325
326 public boolean equals(final NEDPosition other, final double threshold) {
327 if (other == null) {
328 return false;
329 }
330
331 return Math.abs(latitude - other.latitude) <= threshold
332 && Math.abs(longitude - other.longitude) <= threshold
333 && Math.abs(height - other.height) <= threshold;
334 }
335
336
337
338
339
340
341
342 @Override
343 protected Object clone() throws CloneNotSupportedException {
344 final var result = (NEDPosition) super.clone();
345 copyTo(result);
346 return result;
347 }
348 }