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