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