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