1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.utils;
18
19 import java.io.Serializable;
20 import java.util.stream.Stream;
21
22 import org.hipparchus.analysis.differentiation.Derivative;
23 import org.hipparchus.analysis.interpolation.HermiteInterpolator;
24 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
25 import org.hipparchus.geometry.euclidean.threed.Vector3D;
26 import org.hipparchus.util.FastMath;
27 import org.orekit.annotation.DefaultDataContext;
28 import org.orekit.data.DataContext;
29 import org.orekit.errors.OrekitException;
30 import org.orekit.errors.OrekitIllegalArgumentException;
31 import org.orekit.errors.OrekitInternalError;
32 import org.orekit.errors.OrekitMessages;
33 import org.orekit.frames.Frame;
34 import org.orekit.frames.Transform;
35 import org.orekit.time.AbsoluteDate;
36 import org.orekit.time.TimeInterpolable;
37 import org.orekit.time.TimeStamped;
38
39
40
41 public class AbsolutePVCoordinates extends TimeStampedPVCoordinates
42 implements TimeStamped, TimeInterpolable<AbsolutePVCoordinates>,
43 Serializable, PVCoordinatesProvider {
44
45
46 private static final long serialVersionUID = 20150824L;
47
48
49 private final Frame frame;
50
51
52
53
54
55
56
57
58 public AbsolutePVCoordinates(final Frame frame, final AbsoluteDate date,
59 final Vector3D position, final Vector3D velocity, final Vector3D acceleration) {
60 super(date, position, velocity, acceleration);
61 this.frame = frame;
62 }
63
64
65
66
67
68
69
70 public AbsolutePVCoordinates(final Frame frame, final AbsoluteDate date,
71 final Vector3D position,
72 final Vector3D velocity) {
73 this(frame, date, position, velocity, Vector3D.ZERO);
74 }
75
76
77
78
79
80
81 public AbsolutePVCoordinates(final Frame frame, final AbsoluteDate date, final PVCoordinates pva) {
82 super(date, pva);
83 this.frame = frame;
84 }
85
86
87
88
89
90 public AbsolutePVCoordinates(final Frame frame, final TimeStampedPVCoordinates pva) {
91 super(pva.getDate(), pva);
92 this.frame = frame;
93 }
94
95
96
97
98
99
100
101
102 public AbsolutePVCoordinates(final AbsoluteDate date,
103 final double a, final AbsolutePVCoordinates AbsPva) {
104 super(date, a, AbsPva);
105 this.frame = AbsPva.frame;
106 }
107
108
109
110
111
112
113
114
115
116
117 public AbsolutePVCoordinates(final AbsoluteDate date,
118 final AbsolutePVCoordinates start, final AbsolutePVCoordinates end) {
119 super(date, start, end);
120 ensureIdenticalFrames(start, end);
121 this.frame = start.frame;
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135 public AbsolutePVCoordinates(final AbsoluteDate date,
136 final double a1, final AbsolutePVCoordinates absPv1,
137 final double a2, final AbsolutePVCoordinates absPv2) {
138 super(date, a1, absPv1.getPVCoordinates(), a2, absPv2.getPVCoordinates());
139 ensureIdenticalFrames(absPv1, absPv2);
140 this.frame = absPv1.getFrame();
141 }
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 public AbsolutePVCoordinates(final AbsoluteDate date,
157 final double a1, final AbsolutePVCoordinates absPv1,
158 final double a2, final AbsolutePVCoordinates absPv2,
159 final double a3, final AbsolutePVCoordinates absPv3) {
160 super(date, a1, absPv1.getPVCoordinates(), a2, absPv2.getPVCoordinates(),
161 a3, absPv3.getPVCoordinates());
162 ensureIdenticalFrames(absPv1, absPv2);
163 ensureIdenticalFrames(absPv1, absPv3);
164 this.frame = absPv1.getFrame();
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 public AbsolutePVCoordinates(final AbsoluteDate date,
183 final double a1, final AbsolutePVCoordinates absPv1,
184 final double a2, final AbsolutePVCoordinates absPv2,
185 final double a3, final AbsolutePVCoordinates absPv3,
186 final double a4, final AbsolutePVCoordinates absPv4) {
187 super(date, a1, absPv1.getPVCoordinates(), a2, absPv2.getPVCoordinates(),
188 a3, absPv3.getPVCoordinates(), a4, absPv4.getPVCoordinates());
189 ensureIdenticalFrames(absPv1, absPv2);
190 ensureIdenticalFrames(absPv1, absPv3);
191 ensureIdenticalFrames(absPv1, absPv4);
192 this.frame = absPv1.getFrame();
193 }
194
195
196
197
198
199
200
201
202
203
204
205 public <U extends Derivative<U>> AbsolutePVCoordinates(final Frame frame, final AbsoluteDate date,
206 final FieldVector3D<U> p) {
207 super(date, p);
208 this.frame = frame;
209 }
210
211
212
213
214
215
216 private static void ensureIdenticalFrames(final AbsolutePVCoordinates absPv1, final AbsolutePVCoordinates absPv2)
217 throws OrekitIllegalArgumentException {
218 if (!absPv1.frame.equals(absPv2.frame)) {
219 throw new OrekitIllegalArgumentException(OrekitMessages.INCOMPATIBLE_FRAMES,
220 absPv1.frame.getName(), absPv2.frame.getName());
221 }
222 }
223
224
225
226
227
228
229
230
231
232
233
234 public AbsolutePVCoordinates shiftedBy(final double dt) {
235 final TimeStampedPVCoordinates spv = super.shiftedBy(dt);
236 return new AbsolutePVCoordinates(frame, spv);
237 }
238
239
240
241
242
243
244
245
246
247 public PVCoordinatesProvider toTaylorProvider() {
248 return new PVCoordinatesProvider() {
249
250 public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate d, final Frame f) {
251 final TimeStampedPVCoordinates shifted = shiftedBy(d.durationFrom(getDate()));
252 final Transform transform = frame.getTransformTo(f, d);
253 return transform.transformPVCoordinates(shifted);
254 }
255 };
256 }
257
258
259
260
261 public Frame getFrame() {
262 return frame;
263 }
264
265
266
267
268 public TimeStampedPVCoordinates getPVCoordinates() {
269 return this;
270 }
271
272
273
274
275
276
277
278 public TimeStampedPVCoordinates getPVCoordinates(final Frame outputFrame) {
279
280
281 if (outputFrame == frame) {
282 return getPVCoordinates();
283 }
284
285
286 final Transform t = frame.getTransformTo(outputFrame, getDate());
287 return t.transformPVCoordinates(getPVCoordinates());
288 }
289
290 @Override
291 public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate otherDate, final Frame outputFrame) {
292 return shiftedBy(otherDate.durationFrom(getDate())).getPVCoordinates(outputFrame);
293 }
294
295 @Override
296 public AbsolutePVCoordinates interpolate(final AbsoluteDate date, final Stream<AbsolutePVCoordinates> sample) {
297 return interpolate(getFrame(), date, CartesianDerivativesFilter.USE_PVA, sample);
298 }
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322 public static AbsolutePVCoordinates interpolate(final Frame frame, final AbsoluteDate date,
323 final CartesianDerivativesFilter filter,
324 final Stream<AbsolutePVCoordinates> sample) {
325
326
327
328 final HermiteInterpolator interpolator = new HermiteInterpolator();
329
330
331 switch (filter) {
332 case USE_P :
333
334 sample.forEach(pv -> {
335 final Vector3D position = pv.getPosition();
336 interpolator.addSamplePoint(pv.getDate().durationFrom(date),
337 position.toArray());
338 });
339 break;
340 case USE_PV :
341
342 sample.forEach(pv -> {
343 final Vector3D position = pv.getPosition();
344 final Vector3D velocity = pv.getVelocity();
345 interpolator.addSamplePoint(pv.getDate().durationFrom(date),
346 position.toArray(), velocity.toArray());
347 });
348 break;
349 case USE_PVA :
350
351 sample.forEach(pv -> {
352 final Vector3D position = pv.getPosition();
353 final Vector3D velocity = pv.getVelocity();
354 final Vector3D acceleration = pv.getAcceleration();
355 interpolator.addSamplePoint(pv.getDate().durationFrom(date),
356 position.toArray(), velocity.toArray(), acceleration.toArray());
357 });
358 break;
359 default :
360
361 throw new OrekitInternalError(null);
362 }
363
364
365 final double[][] p = interpolator.derivatives(0.0, 2);
366
367
368 return new AbsolutePVCoordinates(frame, date, new Vector3D(p[0]), new Vector3D(p[1]), new Vector3D(p[2]));
369
370 }
371
372
373
374
375 @DefaultDataContext
376 private Object writeReplace() {
377 return new DTO(this);
378 }
379
380
381 @DefaultDataContext
382 private static class DTO implements Serializable {
383
384
385 private static final long serialVersionUID = 20150916L;
386
387
388 private double[] d;
389
390
391 private final Frame frame;
392
393
394
395
396 private DTO(final AbsolutePVCoordinates absPva) {
397
398
399 final AbsoluteDate j2000Epoch =
400 DataContext.getDefault().getTimeScales().getJ2000Epoch();
401 final double epoch = FastMath.floor(absPva.getDate().durationFrom(j2000Epoch));
402 final double offset = absPva.getDate().durationFrom(j2000Epoch.shiftedBy(epoch));
403
404 this.d = new double[] {
405 epoch, offset,
406 absPva.getPosition().getX(), absPva.getPosition().getY(), absPva.getPosition().getZ(),
407 absPva.getVelocity().getX(), absPva.getVelocity().getY(), absPva.getVelocity().getZ(),
408 absPva.getAcceleration().getX(), absPva.getAcceleration().getY(), absPva.getAcceleration().getZ()
409 };
410 this.frame = absPva.frame;
411
412 }
413
414
415
416
417 private Object readResolve() {
418 final AbsoluteDate j2000Epoch =
419 DataContext.getDefault().getTimeScales().getJ2000Epoch();
420 return new AbsolutePVCoordinates(frame,
421 j2000Epoch.shiftedBy(d[0]).shiftedBy(d[1]),
422 new Vector3D(d[2], d[3], d[ 4]),
423 new Vector3D(d[5], d[6], d[ 7]),
424 new Vector3D(d[8], d[9], d[10]));
425 }
426
427 }
428
429 }
430
431
432