1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.frames;
18
19 import org.hipparchus.Field;
20 import org.hipparchus.CalculusFieldElement;
21 import org.hipparchus.analysis.UnivariateFunction;
22 import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
23 import org.hipparchus.analysis.solvers.UnivariateSolver;
24 import org.hipparchus.exception.MathRuntimeException;
25 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
26 import org.hipparchus.geometry.euclidean.threed.Rotation;
27 import org.hipparchus.geometry.euclidean.threed.Vector3D;
28 import org.hipparchus.util.FastMath;
29 import org.hipparchus.util.FieldSinCos;
30 import org.hipparchus.util.MathUtils;
31 import org.hipparchus.util.SinCos;
32 import org.orekit.bodies.BodyShape;
33 import org.orekit.bodies.FieldGeodeticPoint;
34 import org.orekit.bodies.GeodeticPoint;
35 import org.orekit.errors.OrekitException;
36 import org.orekit.time.AbsoluteDate;
37 import org.orekit.time.FieldAbsoluteDate;
38 import org.orekit.utils.Constants;
39 import org.orekit.utils.FieldPVCoordinates;
40 import org.orekit.utils.FieldTrackingCoordinates;
41 import org.orekit.utils.PVCoordinates;
42 import org.orekit.utils.PVCoordinatesProvider;
43 import org.orekit.utils.TimeStampedPVCoordinates;
44 import org.orekit.utils.TrackingCoordinates;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 public class TopocentricFrame extends Frame implements PVCoordinatesProvider {
63
64
65 private static final long serialVersionUID = -5997915708080966466L;
66
67
68 private final BodyShape parentShape;
69
70
71 private final GeodeticPoint point;
72
73
74
75
76 private final Vector3D cartesianPoint;
77
78
79
80
81
82
83 public TopocentricFrame(final BodyShape parentShape, final GeodeticPoint point,
84 final String name) {
85
86 super(parentShape.getBodyFrame(),
87 new Transform(AbsoluteDate.ARBITRARY_EPOCH,
88 new Transform(AbsoluteDate.ARBITRARY_EPOCH,
89 parentShape.transform(point).negate()),
90 new Transform(AbsoluteDate.ARBITRARY_EPOCH,
91 new Rotation(point.getEast(), point.getZenith(),
92 Vector3D.PLUS_I, Vector3D.PLUS_K),
93 Vector3D.ZERO)),
94 name, false);
95 this.parentShape = parentShape;
96 this.point = point;
97 this.cartesianPoint = getTransformProvider().
98 getStaticTransform(AbsoluteDate.ARBITRARY_EPOCH).
99 getInverse().
100 transformPosition(Vector3D.ZERO);
101 }
102
103
104
105
106 public BodyShape getParentShape() {
107 return parentShape;
108 }
109
110
111
112
113 public GeodeticPoint getPoint() {
114 return point;
115 }
116
117
118
119
120
121 public Vector3D getCartesianPoint() {
122 return cartesianPoint;
123 }
124
125
126
127
128
129
130
131 public <T extends CalculusFieldElement<T>> FieldGeodeticPoint<T> getPoint(final Field<T> field) {
132 final T zero = field.getZero();
133 return new FieldGeodeticPoint<>(zero.newInstance(point.getLatitude()),
134 zero.newInstance(point.getLongitude()),
135 zero.newInstance(point.getAltitude()));
136 }
137
138
139
140
141
142
143 public Vector3D getZenith() {
144 return point.getZenith();
145 }
146
147
148
149
150
151
152 public Vector3D getNadir() {
153 return point.getNadir();
154 }
155
156
157
158
159
160
161
162 public Vector3D getNorth() {
163 return point.getNorth();
164 }
165
166
167
168
169
170
171 public Vector3D getSouth() {
172 return point.getSouth();
173 }
174
175
176
177
178
179
180
181 public Vector3D getEast() {
182 return point.getEast();
183 }
184
185
186
187
188
189
190 public Vector3D getWest() {
191 return point.getWest();
192 }
193
194
195
196
197
198
199
200
201 public TrackingCoordinates getTrackingCoordinates(final Vector3D extPoint, final Frame frame,
202 final AbsoluteDate date) {
203
204
205 final Vector3D extPointTopo = transformPoint(extPoint, frame, date);
206
207 final double azimuth = computeAzimuthFromTopoPoint(extPointTopo);
208
209 return new TrackingCoordinates(azimuth, extPointTopo.getDelta(), extPointTopo.getNorm());
210
211 }
212
213
214
215
216
217
218
219
220
221 public <T extends CalculusFieldElement<T>> FieldTrackingCoordinates<T> getTrackingCoordinates(final FieldVector3D<T> extPoint,
222 final Frame frame,
223 final FieldAbsoluteDate<T> date) {
224
225
226 final FieldVector3D<T> extPointTopo = transformPoint(extPoint, frame, date);
227
228 final T azimuth = computeAzimuthFromTopoPoint(extPointTopo);
229
230 return new FieldTrackingCoordinates<>(azimuth, extPointTopo.getDelta(), extPointTopo.getNorm());
231
232 }
233
234
235
236
237
238
239
240
241
242 public double getElevation(final Vector3D extPoint, final Frame frame,
243 final AbsoluteDate date) {
244
245
246 final Vector3D extPointTopo = transformPoint(extPoint, frame, date);
247
248 return extPointTopo.getDelta();
249 }
250
251
252
253
254
255
256
257
258
259
260
261 public <T extends CalculusFieldElement<T>> T getElevation(final FieldVector3D<T> extPoint, final Frame frame,
262 final FieldAbsoluteDate<T> date) {
263
264
265 final FieldVector3D<T> extPointTopo = transformPoint(extPoint, frame, date);
266
267 return extPointTopo.getDelta();
268 }
269
270
271
272
273
274
275
276
277
278
279 public double getAzimuth(final Vector3D extPoint, final Frame frame,
280 final AbsoluteDate date) {
281
282
283 final Vector3D extPointTopo = transformPoint(extPoint, frame, date);
284
285 return computeAzimuthFromTopoPoint(extPointTopo);
286
287 }
288
289
290
291
292
293
294
295
296
297
298
299
300 public <T extends CalculusFieldElement<T>> T getAzimuth(final FieldVector3D<T> extPoint, final Frame frame,
301 final FieldAbsoluteDate<T> date) {
302
303
304 final FieldVector3D<T> extPointTopo = transformPoint(extPoint, frame, date);
305
306 return computeAzimuthFromTopoPoint(extPointTopo);
307
308 }
309
310
311
312
313
314
315
316 public double getRange(final Vector3D extPoint, final Frame frame,
317 final AbsoluteDate date) {
318
319
320 final Vector3D extPointTopo = transformPoint(extPoint, frame, date);
321
322 return extPointTopo.getNorm();
323
324 }
325
326
327
328
329
330
331
332
333
334 public <T extends CalculusFieldElement<T>> T getRange(final FieldVector3D<T> extPoint, final Frame frame,
335 final FieldAbsoluteDate<T> date) {
336
337
338 final FieldVector3D<T> extPointTopo = transformPoint(extPoint, frame, date);
339
340 return extPointTopo.getNorm();
341
342 }
343
344
345
346
347
348
349
350 public double getRangeRate(final PVCoordinates extPV, final Frame frame,
351 final AbsoluteDate date) {
352
353
354 final KinematicTransform t = frame.getKinematicTransformTo(this, date);
355 final PVCoordinates extPVTopo = t.transformOnlyPV(extPV);
356
357
358 return Vector3D.dotProduct(extPVTopo.getPosition(), extPVTopo.getVelocity()) /
359 extPVTopo.getPosition().getNorm();
360
361 }
362
363
364
365
366
367
368
369
370
371 public <T extends CalculusFieldElement<T>> T getRangeRate(final FieldPVCoordinates<T> extPV, final Frame frame,
372 final FieldAbsoluteDate<T> date) {
373
374
375 final FieldKinematicTransform<T> t = frame.getKinematicTransformTo(this, date);
376 final FieldPVCoordinates<T> extPVTopo = t.transformOnlyPV(extPV);
377
378
379 return FieldVector3D.dotProduct(extPVTopo.getPosition(), extPVTopo.getVelocity()).divide(
380 extPVTopo.getPosition().getNorm());
381
382 }
383
384
385
386
387
388
389
390
391
392
393
394
395
396 public GeodeticPoint computeLimitVisibilityPoint(final double radius,
397 final double azimuth, final double elevation) {
398 try {
399
400 final double deltaP = 0.001;
401 final UnivariateSolver solver =
402 new BracketingNthOrderBrentSolver(deltaP / Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
403 deltaP, deltaP, 5);
404
405
406
407 final double distance = solver.solve(1000, new UnivariateFunction() {
408
409 public double value(final double x) {
410 final GeodeticPoint gp = pointAtDistance(azimuth, elevation, x);
411 return parentShape.transform(gp).getNorm() - radius;
412 }
413 }, 0, 2 * radius);
414
415
416 return pointAtDistance(azimuth, elevation, distance);
417
418 } catch (MathRuntimeException mrte) {
419 throw new OrekitException(mrte);
420 }
421 }
422
423
424
425
426
427
428
429 public GeodeticPoint pointAtDistance(final double azimuth, final double elevation,
430 final double distance) {
431 final SinCos scAz = FastMath.sinCos(azimuth);
432 final SinCos scEl = FastMath.sinCos(elevation);
433 final Vector3D observed = new Vector3D(distance * scEl.cos() * scAz.sin(),
434 distance * scEl.cos() * scAz.cos(),
435 distance * scEl.sin());
436 return parentShape.transform(observed, this, AbsoluteDate.ARBITRARY_EPOCH);
437 }
438
439
440 @Override
441 public Vector3D getPosition(final AbsoluteDate date, final Frame frame) {
442 return getStaticTransformTo(frame, date).transformPosition(Vector3D.ZERO);
443 }
444
445
446
447
448
449
450 public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date, final Frame frame) {
451 return getTransformTo(frame, date).transformPVCoordinates(new TimeStampedPVCoordinates(date,
452 Vector3D.ZERO,
453 Vector3D.ZERO,
454 Vector3D.ZERO));
455 }
456
457
458
459
460
461
462 public static Vector3D getTopocentricPosition(final TrackingCoordinates coords) {
463 return getTopocentricPosition(coords.getAzimuth(), coords.getElevation(), coords.getRange());
464 }
465
466
467
468
469
470
471
472 public static <T extends CalculusFieldElement<T>> FieldVector3D<T> getTopocentricPosition(final FieldTrackingCoordinates<T> coords) {
473 return getTopocentricPosition(coords.getAzimuth(), coords.getElevation(), coords.getRange());
474 }
475
476
477
478
479
480
481
482
483
484 private static Vector3D getTopocentricPosition(final double azimuth, final double elevation, final double range) {
485 final SinCos sinCosAz = FastMath.sinCos(azimuth);
486 final SinCos sinCosEL = FastMath.sinCos(elevation);
487 return new Vector3D(range * sinCosEL.cos() * sinCosAz.sin(), range * sinCosEL.cos() * sinCosAz.cos(), range * sinCosEL.sin());
488 }
489
490
491
492
493
494
495
496
497
498
499 private static <T extends CalculusFieldElement<T>> FieldVector3D<T> getTopocentricPosition(final T azimuth, final T elevation, final T range) {
500 final FieldSinCos<T> sinCosAz = FastMath.sinCos(azimuth);
501 final FieldSinCos<T> sinCosEl = FastMath.sinCos(elevation);
502 return new FieldVector3D<>(
503 range.multiply(sinCosEl.cos()).multiply(sinCosAz.sin()),
504 range.multiply(sinCosEl.cos()).multiply(sinCosAz.cos()),
505 range.multiply(sinCosEl.sin())
506 );
507 }
508
509
510
511
512
513
514
515 private Vector3D transformPoint(final Vector3D extPoint, final Frame frame, final AbsoluteDate date) {
516 final StaticTransform t = frame.getStaticTransformTo(this, date);
517 return t.transformPosition(extPoint);
518 }
519
520
521
522
523
524
525
526
527 private <T extends CalculusFieldElement<T>> FieldVector3D<T> transformPoint(final FieldVector3D<T> extPoint,
528 final Frame frame,
529 final FieldAbsoluteDate<T> date) {
530 final FieldStaticTransform<T> t = frame.getStaticTransformTo(this, date);
531 return t.transformPosition(extPoint);
532 }
533
534
535
536
537
538 private double computeAzimuthFromTopoPoint(final Vector3D extPointTopo) {
539 final double azimuth = FastMath.atan2(extPointTopo.getX(), extPointTopo.getY());
540 if (azimuth < 0.0) {
541 return azimuth + MathUtils.TWO_PI;
542 } else {
543 return azimuth;
544 }
545 }
546
547
548
549
550
551
552 private <T extends CalculusFieldElement<T>> T computeAzimuthFromTopoPoint(final FieldVector3D<T> extPointTopo) {
553 final T azimuth = FastMath.atan2(extPointTopo.getX(), extPointTopo.getY());
554 if (azimuth.getReal() < 0.0) {
555 return azimuth.add(MathUtils.TWO_PI);
556 } else {
557 return azimuth;
558 }
559 }
560
561 }