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.TimeScale;
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
184 public <U extends Derivative<U>> TimeStampedPVCoordinates(final AbsoluteDate date, final FieldVector3D<U> 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 Vector3D getPosition(final AbsoluteDate d, final Frame f) {
223 final TimeStampedPVCoordinates shifted = shiftedBy(d.durationFrom(getDate()));
224 final StaticTransform transform = instanceFrame.getStaticTransformTo(f, d);
225 return transform.transformPosition(shifted.getPosition());
226 }
227
228 public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate d, final Frame f) {
229 final TimeStampedPVCoordinates shifted = shiftedBy(d.durationFrom(date));
230 final Transform transform = instanceFrame.getTransformTo(f, d);
231 return transform.transformPVCoordinates(shifted);
232 }
233 };
234 }
235
236
237
238
239
240
241
242 @Override
243 @DefaultDataContext
244 public String toString() {
245 return toString(DataContext.getDefault().getTimeScales().getUTC());
246 }
247
248
249
250
251
252
253
254 public String toString(final TimeScale utc) {
255 final String comma = ", ";
256 return new StringBuilder().append('{').
257 append(date.toString(utc)).append(", P(").
258 append(getPosition().getX()).append(comma).
259 append(getPosition().getY()).append(comma).
260 append(getPosition().getZ()).append("), V(").
261 append(getVelocity().getX()).append(comma).
262 append(getVelocity().getY()).append(comma).
263 append(getVelocity().getZ()).append("), A(").
264 append(getAcceleration().getX()).append(comma).
265 append(getAcceleration().getY()).append(comma).
266 append(getAcceleration().getZ()).append(")}").toString();
267 }
268
269
270
271
272 @DefaultDataContext
273 private Object writeReplace() {
274 return new DTO(this);
275 }
276
277
278 @DefaultDataContext
279 private static class DTO implements Serializable {
280
281
282 private static final long serialVersionUID = 20140723L;
283
284
285 private double[] d;
286
287
288
289
290 private DTO(final TimeStampedPVCoordinates pv) {
291
292
293 final AbsoluteDate j2000Epoch =
294 DataContext.getDefault().getTimeScales().getJ2000Epoch();
295 final double epoch = FastMath.floor(pv.getDate().durationFrom(j2000Epoch));
296 final double offset = pv.getDate().durationFrom(j2000Epoch.shiftedBy(epoch));
297
298 this.d = new double[] {
299 epoch, offset,
300 pv.getPosition().getX(), pv.getPosition().getY(), pv.getPosition().getZ(),
301 pv.getVelocity().getX(), pv.getVelocity().getY(), pv.getVelocity().getZ(),
302 pv.getAcceleration().getX(), pv.getAcceleration().getY(), pv.getAcceleration().getZ()
303 };
304
305 }
306
307
308
309
310 private Object readResolve() {
311 final AbsoluteDate j2000Epoch =
312 DataContext.getDefault().getTimeScales().getJ2000Epoch();
313 return new TimeStampedPVCoordinates(j2000Epoch.shiftedBy(d[0]).shiftedBy(d[1]),
314 new Vector3D(d[2], d[3], d[ 4]),
315 new Vector3D(d[5], d[6], d[ 7]),
316 new Vector3D(d[8], d[9], d[10]));
317 }
318
319 }
320
321 }