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