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
21 import org.hipparchus.analysis.differentiation.Derivative;
22 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
23 import org.hipparchus.geometry.euclidean.threed.Vector3D;
24 import org.hipparchus.util.FastMath;
25 import org.orekit.annotation.DefaultDataContext;
26 import org.orekit.data.DataContext;
27 import org.orekit.frames.Frame;
28 import org.orekit.frames.StaticTransform;
29 import org.orekit.frames.Transform;
30 import org.orekit.time.AbsoluteDate;
31 import org.orekit.time.TimeOffset;
32 import org.orekit.time.TimeScale;
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
185 public <U extends Derivative<U>> TimeStampedPVCoordinates(final AbsoluteDate date, final FieldVector3D<U> 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
221
222 public TimeStampedPVCoordinates shiftedBy(final TimeOffset dt) {
223 final PVCoordinates spv = super.shiftedBy(dt);
224 return new TimeStampedPVCoordinates(date.shiftedBy(dt),
225 spv.getPosition(), spv.getVelocity(), spv.getAcceleration());
226 }
227
228
229
230
231
232
233
234
235
236
237 public PVCoordinatesProvider toTaylorProvider(final Frame instanceFrame) {
238 return new PVCoordinatesProvider() {
239
240 public Vector3D getPosition(final AbsoluteDate d, final Frame f) {
241 final TimeStampedPVCoordinates shifted = shiftedBy(d.durationFrom(getDate()));
242 final StaticTransform transform = instanceFrame.getStaticTransformTo(f, d);
243 return transform.transformPosition(shifted.getPosition());
244 }
245
246 public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate d, final Frame f) {
247 final TimeStampedPVCoordinates shifted = shiftedBy(d.durationFrom(date));
248 final Transform transform = instanceFrame.getTransformTo(f, d);
249 return transform.transformPVCoordinates(shifted);
250 }
251 };
252 }
253
254
255
256
257
258
259
260 @Override
261 @DefaultDataContext
262 public String toString() {
263 return toString(DataContext.getDefault().getTimeScales().getUTC());
264 }
265
266
267
268
269
270
271
272 public String toString(final TimeScale utc) {
273 final String comma = ", ";
274 return new StringBuilder().append('{').
275 append(date.toString(utc)).append(", P(").
276 append(getPosition().getX()).append(comma).
277 append(getPosition().getY()).append(comma).
278 append(getPosition().getZ()).append("), V(").
279 append(getVelocity().getX()).append(comma).
280 append(getVelocity().getY()).append(comma).
281 append(getVelocity().getZ()).append("), A(").
282 append(getAcceleration().getX()).append(comma).
283 append(getAcceleration().getY()).append(comma).
284 append(getAcceleration().getZ()).append(")}").toString();
285 }
286
287
288
289
290 @DefaultDataContext
291 private Object writeReplace() {
292 return new DTO(this);
293 }
294
295
296 @DefaultDataContext
297 private static class DTO implements Serializable {
298
299
300 private static final long serialVersionUID = 20140723L;
301
302
303 private final double[] d;
304
305
306
307
308 private DTO(final TimeStampedPVCoordinates pv) {
309
310
311 final AbsoluteDate j2000Epoch =
312 DataContext.getDefault().getTimeScales().getJ2000Epoch();
313 final double epoch = FastMath.floor(pv.getDate().durationFrom(j2000Epoch));
314 final double offset = pv.getDate().durationFrom(j2000Epoch.shiftedBy(epoch));
315
316 this.d = new double[] {
317 epoch, offset,
318 pv.getPosition().getX(), pv.getPosition().getY(), pv.getPosition().getZ(),
319 pv.getVelocity().getX(), pv.getVelocity().getY(), pv.getVelocity().getZ(),
320 pv.getAcceleration().getX(), pv.getAcceleration().getY(), pv.getAcceleration().getZ()
321 };
322
323 }
324
325
326
327
328 private Object readResolve() {
329 final AbsoluteDate j2000Epoch =
330 DataContext.getDefault().getTimeScales().getJ2000Epoch();
331 return new TimeStampedPVCoordinates(j2000Epoch.shiftedBy(d[0]).shiftedBy(d[1]),
332 new Vector3D(d[2], d[3], d[ 4]),
333 new Vector3D(d[5], d[6], d[ 7]),
334 new Vector3D(d[8], d[9], d[10]));
335 }
336
337 }
338
339 }