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
22 import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
23 import org.apache.commons.math3.analysis.interpolation.HermiteInterpolator;
24 import org.apache.commons.math3.geometry.euclidean.threed.FieldVector3D;
25 import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
26 import org.apache.commons.math3.util.FastMath;
27 import org.orekit.errors.OrekitException;
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 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 throws OrekitException {
224 final TimeStampedPVCoordinates shifted = shiftedBy(d.durationFrom(date));
225 final Transform transform = instanceFrame.getTransformTo(f, d);
226 return transform.transformPVCoordinates(shifted);
227 }
228 };
229 }
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250 public static TimeStampedPVCoordinates interpolate(final AbsoluteDate date,
251 final CartesianDerivativesFilter filter,
252 final Collection<TimeStampedPVCoordinates> sample) {
253
254
255 final HermiteInterpolator interpolator = new HermiteInterpolator();
256
257
258 switch (filter) {
259 case USE_P :
260
261 for (final TimeStampedPVCoordinates pv : sample) {
262 final Vector3D position = pv.getPosition();
263 interpolator.addSamplePoint(pv.getDate().durationFrom(date),
264 new double[] {
265 position.getX(), position.getY(), position.getZ()
266 });
267 }
268 break;
269 case USE_PV :
270
271 for (final TimeStampedPVCoordinates pv : sample) {
272 final Vector3D position = pv.getPosition();
273 final Vector3D velocity = pv.getVelocity();
274 interpolator.addSamplePoint(pv.getDate().durationFrom(date),
275 new double[] {
276 position.getX(), position.getY(), position.getZ()
277 }, new double[] {
278 velocity.getX(), velocity.getY(), velocity.getZ()
279 });
280 }
281 break;
282 case USE_PVA :
283
284 for (final TimeStampedPVCoordinates pv : sample) {
285 final Vector3D position = pv.getPosition();
286 final Vector3D velocity = pv.getVelocity();
287 final Vector3D acceleration = pv.getAcceleration();
288 interpolator.addSamplePoint(pv.getDate().durationFrom(date),
289 new double[] {
290 position.getX(), position.getY(), position.getZ()
291 }, new double[] {
292 velocity.getX(), velocity.getY(), velocity.getZ()
293 }, new double[] {
294 acceleration.getX(), acceleration.getY(), acceleration.getZ()
295 });
296 }
297 break;
298 default :
299
300 throw new OrekitInternalError(null);
301 }
302
303
304 final DerivativeStructure zero = new DerivativeStructure(1, 2, 0, 0.0);
305 final DerivativeStructure[] p = interpolator.value(zero);
306
307
308 return new TimeStampedPVCoordinates(date,
309 new Vector3D(p[0].getValue(),
310 p[1].getValue(),
311 p[2].getValue()),
312 new Vector3D(p[0].getPartialDerivative(1),
313 p[1].getPartialDerivative(1),
314 p[2].getPartialDerivative(1)),
315 new Vector3D(p[0].getPartialDerivative(2),
316 p[1].getPartialDerivative(2),
317 p[2].getPartialDerivative(2)));
318
319 }
320
321
322
323
324 public String toString() {
325 final String comma = ", ";
326 return new StringBuffer().append('{').append(date).append(", P(").
327 append(getPosition().getX()).append(comma).
328 append(getPosition().getY()).append(comma).
329 append(getPosition().getZ()).append("), V(").
330 append(getVelocity().getX()).append(comma).
331 append(getVelocity().getY()).append(comma).
332 append(getVelocity().getZ()).append("), A(").
333 append(getAcceleration().getX()).append(comma).
334 append(getAcceleration().getY()).append(comma).
335 append(getAcceleration().getZ()).append(")}").toString();
336 }
337
338
339
340
341 private Object writeReplace() {
342 return new DTO(this);
343 }
344
345
346 private static class DTO implements Serializable {
347
348
349 private static final long serialVersionUID = 20140723L;
350
351
352 private double[] d;
353
354
355
356
357 private DTO(final TimeStampedPVCoordinates pv) {
358
359
360 final double epoch = FastMath.floor(pv.getDate().durationFrom(AbsoluteDate.J2000_EPOCH));
361 final double offset = pv.getDate().durationFrom(AbsoluteDate.J2000_EPOCH.shiftedBy(epoch));
362
363 this.d = new double[] {
364 epoch, offset,
365 pv.getPosition().getX(), pv.getPosition().getY(), pv.getPosition().getZ(),
366 pv.getVelocity().getX(), pv.getVelocity().getY(), pv.getVelocity().getZ(),
367 pv.getAcceleration().getX(), pv.getAcceleration().getY(), pv.getAcceleration().getZ()
368 };
369
370 }
371
372
373
374
375 private Object readResolve() {
376 return new TimeStampedPVCoordinates(AbsoluteDate.J2000_EPOCH.shiftedBy(d[0]).shiftedBy(d[1]),
377 new Vector3D(d[2], d[3], d[ 4]),
378 new Vector3D(d[5], d[6], d[ 7]),
379 new Vector3D(d[8], d[9], d[10]));
380 }
381
382 }
383
384 }