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