1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.frames;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.List;
24
25 import org.hipparchus.RealFieldElement;
26 import org.hipparchus.geometry.euclidean.threed.FieldRotation;
27 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
28 import org.hipparchus.geometry.euclidean.threed.Line;
29 import org.hipparchus.geometry.euclidean.threed.Rotation;
30 import org.hipparchus.geometry.euclidean.threed.RotationConvention;
31 import org.hipparchus.geometry.euclidean.threed.Vector3D;
32 import org.orekit.errors.OrekitException;
33 import org.orekit.time.AbsoluteDate;
34 import org.orekit.time.TimeInterpolable;
35 import org.orekit.time.TimeShiftable;
36 import org.orekit.time.TimeStamped;
37 import org.orekit.utils.AngularCoordinates;
38 import org.orekit.utils.AngularDerivativesFilter;
39 import org.orekit.utils.CartesianDerivativesFilter;
40 import org.orekit.utils.FieldPVCoordinates;
41 import org.orekit.utils.PVCoordinates;
42 import org.orekit.utils.TimeStampedAngularCoordinates;
43 import org.orekit.utils.TimeStampedFieldPVCoordinates;
44 import org.orekit.utils.TimeStampedPVCoordinates;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 public class Transform
102 implements TimeStamped, TimeShiftable<Transform>, TimeInterpolable<Transform>, Serializable {
103
104
105 public static final Transform IDENTITY = new IdentityTransform();
106
107
108 private static final long serialVersionUID = 210140410L;
109
110
111 private final AbsoluteDate date;
112
113
114 private final PVCoordinates cartesian;
115
116
117 private final AngularCoordinates angular;
118
119
120
121
122
123
124 private Transform(final AbsoluteDate date,
125 final PVCoordinates cartesian, final AngularCoordinates angular) {
126 this.date = date;
127 this.cartesian = cartesian;
128 this.angular = angular;
129 }
130
131
132
133
134
135
136
137 public Transform(final AbsoluteDate date, final Vector3D translation) {
138 this(date,
139 new PVCoordinates(translation, Vector3D.ZERO, Vector3D.ZERO),
140 AngularCoordinates.IDENTITY);
141 }
142
143
144
145
146
147
148
149 public Transform(final AbsoluteDate date, final Rotation rotation) {
150 this(date,
151 PVCoordinates.ZERO,
152 new AngularCoordinates(rotation, Vector3D.ZERO));
153 }
154
155
156
157
158
159
160
161
162
163 public Transform(final AbsoluteDate date, final Vector3D translation,
164 final Vector3D velocity) {
165 this(date,
166 new PVCoordinates(translation, velocity, Vector3D.ZERO),
167 AngularCoordinates.IDENTITY);
168 }
169
170
171
172
173
174
175
176
177
178
179
180 public Transform(final AbsoluteDate date, final Vector3D translation,
181 final Vector3D velocity, final Vector3D acceleration) {
182 this(date,
183 new PVCoordinates(translation, velocity, acceleration),
184 AngularCoordinates.IDENTITY);
185 }
186
187
188
189
190
191
192
193 public Transform(final AbsoluteDate date, final PVCoordinates cartesian) {
194 this(date,
195 cartesian,
196 AngularCoordinates.IDENTITY);
197 }
198
199
200
201
202
203
204
205
206
207 public Transform(final AbsoluteDate date, final Rotation rotation, final Vector3D rotationRate) {
208 this(date,
209 PVCoordinates.ZERO,
210 new AngularCoordinates(rotation, rotationRate, Vector3D.ZERO));
211 }
212
213
214
215
216
217
218
219
220
221
222 public Transform(final AbsoluteDate date, final Rotation rotation, final Vector3D rotationRate,
223 final Vector3D rotationAcceleration) {
224 this(date,
225 PVCoordinates.ZERO,
226 new AngularCoordinates(rotation, rotationRate, rotationAcceleration));
227 }
228
229
230
231
232
233
234
235 public Transform(final AbsoluteDate date, final AngularCoordinates angular) {
236 this(date, PVCoordinates.ZERO, angular);
237 }
238
239
240
241
242
243
244
245
246
247
248
249
250 public Transform(final AbsoluteDate date, final Transform first, final Transform second) {
251 this(date,
252 new PVCoordinates(compositeTranslation(first, second),
253 compositeVelocity(first, second),
254 compositeAcceleration(first, second)),
255 new AngularCoordinates(compositeRotation(first, second),
256 compositeRotationRate(first, second),
257 compositeRotationAcceleration(first, second)));
258 }
259
260
261
262
263
264
265 private static Vector3D compositeTranslation(final Transform first, final Transform second) {
266
267 final Vector3D p1 = first.cartesian.getPosition();
268 final Rotation r1 = first.angular.getRotation();
269 final Vector3D p2 = second.cartesian.getPosition();
270
271 return p1.add(r1.applyInverseTo(p2));
272
273 }
274
275
276
277
278
279
280 private static Vector3D compositeVelocity(final Transform first, final Transform second) {
281
282 final Vector3D v1 = first.cartesian.getVelocity();
283 final Rotation r1 = first.angular.getRotation();
284 final Vector3D o1 = first.angular.getRotationRate();
285 final Vector3D p2 = second.cartesian.getPosition();
286 final Vector3D v2 = second.cartesian.getVelocity();
287
288 final Vector3D crossP = Vector3D.crossProduct(o1, p2);
289
290 return v1.add(r1.applyInverseTo(v2.add(crossP)));
291
292 }
293
294
295
296
297
298
299 private static Vector3D compositeAcceleration(final Transform first, final Transform second) {
300
301 final Vector3D a1 = first.cartesian.getAcceleration();
302 final Rotation r1 = first.angular.getRotation();
303 final Vector3D o1 = first.angular.getRotationRate();
304 final Vector3D oDot1 = first.angular.getRotationAcceleration();
305 final Vector3D p2 = second.cartesian.getPosition();
306 final Vector3D v2 = second.cartesian.getVelocity();
307 final Vector3D a2 = second.cartesian.getAcceleration();
308
309 final Vector3D crossCrossP = Vector3D.crossProduct(o1, Vector3D.crossProduct(o1, p2));
310 final Vector3D crossV = Vector3D.crossProduct(o1, v2);
311 final Vector3D crossDotP = Vector3D.crossProduct(oDot1, p2);
312
313 return a1.add(r1.applyInverseTo(new Vector3D(1, a2, 2, crossV, 1, crossCrossP, 1, crossDotP)));
314
315 }
316
317
318
319
320
321
322 private static Rotation compositeRotation(final Transform first, final Transform second) {
323
324 final Rotation r1 = first.angular.getRotation();
325 final Rotation r2 = second.angular.getRotation();
326
327 return r1.compose(r2, RotationConvention.FRAME_TRANSFORM);
328
329 }
330
331
332
333
334
335
336 private static Vector3D compositeRotationRate(final Transform first, final Transform second) {
337
338 final Vector3D o1 = first.angular.getRotationRate();
339 final Rotation r2 = second.angular.getRotation();
340 final Vector3D o2 = second.angular.getRotationRate();
341
342 return o2.add(r2.applyTo(o1));
343
344 }
345
346
347
348
349
350
351 private static Vector3D compositeRotationAcceleration(final Transform first, final Transform second) {
352
353 final Vector3D o1 = first.angular.getRotationRate();
354 final Vector3D oDot1 = first.angular.getRotationAcceleration();
355 final Rotation r2 = second.angular.getRotation();
356 final Vector3D o2 = second.angular.getRotationRate();
357 final Vector3D oDot2 = second.angular.getRotationAcceleration();
358
359 return new Vector3D( 1, oDot2,
360 1, r2.applyTo(oDot1),
361 -1, Vector3D.crossProduct(o2, r2.applyTo(o1)));
362
363 }
364
365
366 public AbsoluteDate getDate() {
367 return date;
368 }
369
370
371 public Transform shiftedBy(final double dt) {
372 return new Transform(date.shiftedBy(dt), cartesian.shiftedBy(dt), angular.shiftedBy(dt));
373 };
374
375
376
377
378
379
380
381
382
383
384
385 public Transform interpolate(final AbsoluteDate interpolationDate, final Collection<Transform> sample)
386 throws OrekitException {
387 return interpolate(interpolationDate,
388 CartesianDerivativesFilter.USE_PVA, AngularDerivativesFilter.USE_RRA,
389 sample);
390 }
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417 public static Transform interpolate(final AbsoluteDate date,
418 final CartesianDerivativesFilter cFilter,
419 final AngularDerivativesFilter aFilter,
420 final Collection<Transform> sample)
421 throws OrekitException {
422 final List<TimeStampedPVCoordinates> datedPV = new ArrayList<TimeStampedPVCoordinates>(sample.size());
423 final List<TimeStampedAngularCoordinates> datedAC = new ArrayList<TimeStampedAngularCoordinates>(sample.size());
424 for (final Transform t : sample) {
425 datedPV.add(new TimeStampedPVCoordinates(t.getDate(), t.getTranslation(), t.getVelocity(), t.getAcceleration()));
426 datedAC.add(new TimeStampedAngularCoordinates(t.getDate(), t.getRotation(), t.getRotationRate(), t.getRotationAcceleration()));
427 }
428 final TimeStampedPVCoordinates interpolatedPV = TimeStampedPVCoordinates.interpolate(date, cFilter, datedPV);
429 final TimeStampedAngularCoordinates interpolatedAC = TimeStampedAngularCoordinates.interpolate(date, aFilter, datedAC);
430 return new Transform(date, interpolatedPV, interpolatedAC);
431 }
432
433
434
435
436 public Transform getInverse() {
437
438 final Rotation r = angular.getRotation();
439 final Vector3D o = angular.getRotationRate();
440 final Vector3D oDot = angular.getRotationAcceleration();
441 final Vector3D rp = r.applyTo(cartesian.getPosition());
442 final Vector3D rv = r.applyTo(cartesian.getVelocity());
443 final Vector3D ra = r.applyTo(cartesian.getAcceleration());
444
445 final Vector3D pInv = rp.negate();
446 final Vector3D crossP = Vector3D.crossProduct(o, rp);
447 final Vector3D vInv = crossP.subtract(rv);
448 final Vector3D crossV = Vector3D.crossProduct(o, rv);
449 final Vector3D crossDotP = Vector3D.crossProduct(oDot, rp);
450 final Vector3D crossCrossP = Vector3D.crossProduct(o, crossP);
451 final Vector3D aInv = new Vector3D(-1, ra,
452 2, crossV,
453 1, crossDotP,
454 -1, crossCrossP);
455
456 return new Transform(date, new PVCoordinates(pInv, vInv, aInv), angular.revert());
457
458 }
459
460
461
462
463
464
465
466
467 public Transform freeze() {
468 return new Transform(date,
469 new PVCoordinates(cartesian.getPosition(), Vector3D.ZERO, Vector3D.ZERO),
470 new AngularCoordinates(angular.getRotation(), Vector3D.ZERO, Vector3D.ZERO));
471 }
472
473
474
475
476
477 public Vector3D transformPosition(final Vector3D position) {
478 return angular.getRotation().applyTo(cartesian.getPosition().add(position));
479 }
480
481
482
483
484
485
486 public <T extends RealFieldElement<T>> FieldVector3D<T> transformPosition(final FieldVector3D<T> position) {
487 return FieldRotation.applyTo(angular.getRotation(), position.add(cartesian.getPosition()));
488 }
489
490
491
492
493
494 public Vector3D transformVector(final Vector3D vector) {
495 return angular.getRotation().applyTo(vector);
496 }
497
498
499
500
501
502
503 public <T extends RealFieldElement<T>> FieldVector3D<T> transformVector(final FieldVector3D<T> vector) {
504 return FieldRotation.applyTo(angular.getRotation(), vector);
505 }
506
507
508
509
510
511 public Line transformLine(final Line line) {
512 final Vector3D transformedP0 = transformPosition(line.getOrigin());
513 final Vector3D transformedP1 = transformPosition(line.pointAt(1.0e6));
514 return new Line(transformedP0, transformedP1, 1.0e-10);
515 }
516
517
518
519
520
521 public PVCoordinates transformPVCoordinates(final PVCoordinates pva) {
522 return angular.applyTo(new PVCoordinates(1, pva, 1, cartesian));
523 }
524
525
526
527
528
529
530
531
532
533
534
535
536
537 public TimeStampedPVCoordinates transformPVCoordinates(final TimeStampedPVCoordinates pv) {
538 return angular.applyTo(new TimeStampedPVCoordinates(pv.getDate(), 1, pv, 1, cartesian));
539 }
540
541
542
543
544
545
546 public <T extends RealFieldElement<T>> FieldPVCoordinates<T> transformPVCoordinates(final FieldPVCoordinates<T> pv) {
547
548
549 final FieldVector3D<T> intermediateP = pv.getPosition().add(cartesian.getPosition());
550 final FieldVector3D<T> intermediateV = pv.getVelocity().add(cartesian.getVelocity());
551 final FieldVector3D<T> intermediateA = pv.getAcceleration().add(cartesian.getAcceleration());
552
553
554 final FieldVector3D<T> transformedP = FieldRotation.applyTo(angular.getRotation(), intermediateP);
555 final FieldVector3D<T> crossP = FieldVector3D.crossProduct(angular.getRotationRate(), transformedP);
556 final FieldVector3D<T> transformedV = FieldRotation.applyTo(angular.getRotation(), intermediateV).subtract(crossP);
557 final FieldVector3D<T> crossV = FieldVector3D.crossProduct(angular.getRotationRate(), transformedV);
558 final FieldVector3D<T> crossCrossP = FieldVector3D.crossProduct(angular.getRotationRate(), crossP);
559 final FieldVector3D<T> crossDotP = FieldVector3D.crossProduct(angular.getRotationAcceleration(), transformedP);
560 final FieldVector3D<T> transformedA =
561 new FieldVector3D<T>( 1, FieldRotation.applyTo(angular.getRotation(), intermediateA),
562 -2, crossV,
563 -1, crossCrossP,
564 -1, crossDotP);
565
566
567 return new FieldPVCoordinates<T>(transformedP, transformedV, transformedA);
568
569 }
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584 public <T extends RealFieldElement<T>> TimeStampedFieldPVCoordinates<T> transformPVCoordinates(final TimeStampedFieldPVCoordinates<T> pv) {
585
586
587 final FieldVector3D<T> intermediateP = pv.getPosition().add(cartesian.getPosition());
588 final FieldVector3D<T> intermediateV = pv.getVelocity().add(cartesian.getVelocity());
589 final FieldVector3D<T> intermediateA = pv.getAcceleration().add(cartesian.getAcceleration());
590
591
592 final FieldVector3D<T> transformedP = FieldRotation.applyTo(angular.getRotation(), intermediateP);
593 final FieldVector3D<T> crossP = FieldVector3D.crossProduct(angular.getRotationRate(), transformedP);
594 final FieldVector3D<T> transformedV = FieldRotation.applyTo(angular.getRotation(), intermediateV).subtract(crossP);
595 final FieldVector3D<T> crossV = FieldVector3D.crossProduct(angular.getRotationRate(), transformedV);
596 final FieldVector3D<T> crossCrossP = FieldVector3D.crossProduct(angular.getRotationRate(), crossP);
597 final FieldVector3D<T> crossDotP = FieldVector3D.crossProduct(angular.getRotationAcceleration(), transformedP);
598 final FieldVector3D<T> transformedA =
599 new FieldVector3D<T>( 1, FieldRotation.applyTo(angular.getRotation(), intermediateA),
600 -2, crossV,
601 -1, crossCrossP,
602 -1, crossDotP);
603
604
605 return new TimeStampedFieldPVCoordinates<T>(pv.getDate(), transformedP, transformedV, transformedA);
606
607 }
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633 public void getJacobian(final CartesianDerivativesFilter selector, final double[][] jacobian) {
634
635
636 final double[][] mData = angular.getRotation().getMatrix();
637
638
639 System.arraycopy(mData[0], 0, jacobian[0], 0, 3);
640 System.arraycopy(mData[1], 0, jacobian[1], 0, 3);
641 System.arraycopy(mData[2], 0, jacobian[2], 0, 3);
642
643 if (selector.getMaxOrder() >= 1) {
644
645
646 Arrays.fill(jacobian[0], 3, 6, 0.0);
647 Arrays.fill(jacobian[1], 3, 6, 0.0);
648 Arrays.fill(jacobian[2], 3, 6, 0.0);
649
650
651 final Vector3D o = angular.getRotationRate();
652 final double ox = o.getX();
653 final double oy = o.getY();
654 final double oz = o.getZ();
655 for (int i = 0; i < 3; ++i) {
656 jacobian[3][i] = -(oy * mData[2][i] - oz * mData[1][i]);
657 jacobian[4][i] = -(oz * mData[0][i] - ox * mData[2][i]);
658 jacobian[5][i] = -(ox * mData[1][i] - oy * mData[0][i]);
659 }
660
661
662 System.arraycopy(mData[0], 0, jacobian[3], 3, 3);
663 System.arraycopy(mData[1], 0, jacobian[4], 3, 3);
664 System.arraycopy(mData[2], 0, jacobian[5], 3, 3);
665
666 if (selector.getMaxOrder() >= 2) {
667
668
669 Arrays.fill(jacobian[0], 6, 9, 0.0);
670 Arrays.fill(jacobian[1], 6, 9, 0.0);
671 Arrays.fill(jacobian[2], 6, 9, 0.0);
672
673
674 Arrays.fill(jacobian[3], 6, 9, 0.0);
675 Arrays.fill(jacobian[4], 6, 9, 0.0);
676 Arrays.fill(jacobian[5], 6, 9, 0.0);
677
678
679 final Vector3D oDot = angular.getRotationAcceleration();
680 final double oDotx = oDot.getX();
681 final double oDoty = oDot.getY();
682 final double oDotz = oDot.getZ();
683 for (int i = 0; i < 3; ++i) {
684 jacobian[6][i] = -(oDoty * mData[2][i] - oDotz * mData[1][i]) - (oy * jacobian[5][i] - oz * jacobian[4][i]);
685 jacobian[7][i] = -(oDotz * mData[0][i] - oDotx * mData[2][i]) - (oz * jacobian[3][i] - ox * jacobian[5][i]);
686 jacobian[8][i] = -(oDotx * mData[1][i] - oDoty * mData[0][i]) - (ox * jacobian[4][i] - oy * jacobian[3][i]);
687 }
688
689
690 for (int i = 0; i < 3; ++i) {
691 jacobian[6][i + 3] = -2 * (oy * mData[2][i] - oz * mData[1][i]);
692 jacobian[7][i + 3] = -2 * (oz * mData[0][i] - ox * mData[2][i]);
693 jacobian[8][i + 3] = -2 * (ox * mData[1][i] - oy * mData[0][i]);
694 }
695
696
697 System.arraycopy(mData[0], 0, jacobian[6], 6, 3);
698 System.arraycopy(mData[1], 0, jacobian[7], 6, 3);
699 System.arraycopy(mData[2], 0, jacobian[8], 6, 3);
700
701 }
702
703 }
704
705 }
706
707
708
709
710
711
712
713
714
715 public PVCoordinates getCartesian() {
716 return cartesian;
717 }
718
719
720
721
722
723
724
725
726
727
728 public Vector3D getTranslation() {
729 return cartesian.getPosition();
730 }
731
732
733
734
735
736
737
738 public Vector3D getVelocity() {
739 return cartesian.getVelocity();
740 }
741
742
743
744
745
746
747
748 public Vector3D getAcceleration() {
749 return cartesian.getAcceleration();
750 }
751
752
753
754
755
756
757
758
759
760
761 public AngularCoordinates getAngular() {
762 return angular;
763 }
764
765
766
767
768
769
770
771
772
773
774 public Rotation getRotation() {
775 return angular.getRotation();
776 }
777
778
779
780
781
782
783
784
785 public Vector3D getRotationRate() {
786 return angular.getRotationRate();
787 }
788
789
790
791
792
793
794
795 public Vector3D getRotationAcceleration() {
796 return angular.getRotationAcceleration();
797 }
798
799
800 private static class IdentityTransform extends Transform {
801
802
803 private static final long serialVersionUID = -9042082036141830517L;
804
805
806 IdentityTransform() {
807 super(AbsoluteDate.J2000_EPOCH, PVCoordinates.ZERO, AngularCoordinates.IDENTITY);
808 }
809
810
811 @Override
812 public Transform shiftedBy(final double dt) {
813 return this;
814 }
815
816
817 @Override
818 public Transform getInverse() {
819 return this;
820 };
821
822
823 @Override
824 public Vector3D transformPosition(final Vector3D position) {
825 return position;
826 }
827
828
829 @Override
830 public Vector3D transformVector(final Vector3D vector) {
831 return vector;
832 }
833
834
835 @Override
836 public Line transformLine(final Line line) {
837 return line;
838 }
839
840
841 @Override
842 public PVCoordinates transformPVCoordinates(final PVCoordinates pv) {
843 return pv;
844 }
845
846
847 @Override
848 public void getJacobian(final CartesianDerivativesFilter selector, final double[][] jacobian) {
849 final int n = 3 * (selector.getMaxOrder() + 1);
850 for (int i = 0; i < n; ++i) {
851 Arrays.fill(jacobian[i], 0, n, 0.0);
852 jacobian[i][i] = 1.0;
853 }
854 }
855
856 }
857
858 }