1 /* Copyright 2002-2025 CS GROUP
2 * Licensed to CS GROUP (CS) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * CS licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.orekit.utils;
18
19 import org.hipparchus.analysis.differentiation.Derivative;
20 import org.hipparchus.geometry.euclidean.threed.FieldRotation;
21 import org.hipparchus.geometry.euclidean.threed.Rotation;
22 import org.hipparchus.geometry.euclidean.threed.RotationConvention;
23 import org.hipparchus.geometry.euclidean.threed.Vector3D;
24 import org.orekit.time.AbsoluteDate;
25 import org.orekit.time.TimeOffset;
26 import org.orekit.time.TimeStamped;
27
28 /** {@link TimeStamped time-stamped} version of {@link AngularCoordinates}.
29 * <p>Instances of this class are guaranteed to be immutable.</p>
30 * @author Luc Maisonobe
31 * @since 7.0
32 */
33 public class TimeStampedAngularCoordinates extends AngularCoordinates implements TimeStamped {
34
35 /** Serializable UID. */
36 private static final long serialVersionUID = 20140723L;
37
38 /** The date. */
39 private final AbsoluteDate date;
40
41 /** Builds a rotation/rotation rate pair.
42 * @param date coordinates date
43 * @param rotation rotation
44 * @param rotationRate rotation rate Ω (rad/s)
45 * @param rotationAcceleration rotation acceleration dΩ/dt (rad²/s²)
46 */
47 public TimeStampedAngularCoordinates(final AbsoluteDate date,
48 final Rotation rotation,
49 final Vector3D rotationRate,
50 final Vector3D rotationAcceleration) {
51 super(rotation, rotationRate, rotationAcceleration);
52 this.date = date;
53 }
54
55 /** Build the rotation that transforms a pair of pv coordinates into another pair.
56
57 * <p><em>WARNING</em>! This method requires much more stringent assumptions on
58 * its parameters than the similar {@link Rotation#Rotation(Vector3D, Vector3D,
59 * Vector3D, Vector3D) constructor} from the {@link Rotation Rotation} class.
60 * As far as the Rotation constructor is concerned, the {@code v₂} vector from
61 * the second pair can be slightly misaligned. The Rotation constructor will
62 * compensate for this misalignment and create a rotation that ensure {@code
63 * v₁ = r(u₁)} and {@code v₂ ∈ plane (r(u₁), r(u₂))}. <em>THIS IS NOT
64 * TRUE ANYMORE IN THIS CLASS</em>! As derivatives are involved and must be
65 * preserved, this constructor works <em>only</em> if the two pairs are fully
66 * consistent, i.e. if a rotation exists that fulfill all the requirements: {@code
67 * v₁ = r(u₁)}, {@code v₂ = r(u₂)}, {@code dv₁/dt = dr(u₁)/dt}, {@code dv₂/dt
68 * = dr(u₂)/dt}, {@code d²v₁/dt² = d²r(u₁)/dt²}, {@code d²v₂/dt² = d²r(u₂)/dt²}.</p>
69
70 * @param date coordinates date
71 * @param u1 first vector of the origin pair
72 * @param u2 second vector of the origin pair
73 * @param v1 desired image of u1 by the rotation
74 * @param v2 desired image of u2 by the rotation
75 * @param tolerance relative tolerance factor used to check singularities
76 */
77 public TimeStampedAngularCoordinates(final AbsoluteDate date,
78 final PVCoordinates u1, final PVCoordinates u2,
79 final PVCoordinates v1, final PVCoordinates v2,
80 final double tolerance) {
81 super(u1, u2, v1, v2, tolerance);
82 this.date = date;
83 }
84
85 /** Build one of the rotations that transform one pv coordinates into another one.
86
87 * <p>Except for a possible scale factor, if the instance were
88 * applied to the vector u it will produce the vector v. There is an
89 * infinite number of such rotations, this constructor choose the
90 * one with the smallest associated angle (i.e. the one whose axis
91 * is orthogonal to the (u, v) plane). If u and v are collinear, an
92 * arbitrary rotation axis is chosen.</p>
93
94 * @param date coordinates date
95 * @param u origin vector
96 * @param v desired image of u by the rotation
97 */
98 public TimeStampedAngularCoordinates(final AbsoluteDate date,
99 final PVCoordinates u, final PVCoordinates v) {
100 super(u, v);
101 this.date = date;
102 }
103
104 /** Builds a TimeStampedAngularCoordinates from a {@link FieldRotation}<{@link Derivative}>.
105 * <p>
106 * The rotation components must have time as their only derivation parameter and
107 * have consistent derivation orders.
108 * </p>
109 * @param date coordinates date
110 * @param r rotation with time-derivatives embedded within the coordinates
111 * @param <U> type of the derivative
112 */
113 public <U extends Derivative<U>>TimeStampedAngularCoordinates(final AbsoluteDate date,
114 final FieldRotation<U> r) {
115 super(r);
116 this.date = date;
117 }
118
119 /** {@inheritDoc} */
120 public AbsoluteDate getDate() {
121 return date;
122 }
123
124 /** Revert a rotation/rotation rate pair.
125 * Build a pair which reverse the effect of another pair.
126 * @return a new pair whose effect is the reverse of the effect
127 * of the instance
128 */
129 public TimeStampedAngularCoordinates revert() {
130 return new TimeStampedAngularCoordinates(date,
131 getRotation().revert(),
132 getRotation().applyInverseTo(getRotationRate().negate()),
133 getRotation().applyInverseTo(getRotationAcceleration().negate()));
134 }
135
136 /** Get a time-shifted state.
137 * <p>
138 * The state can be slightly shifted to close dates. This shift is based on
139 * a simple linear model. It is <em>not</em> intended as a replacement for
140 * proper attitude propagation but should be sufficient for either small
141 * time shifts or coarse accuracy.
142 * </p>
143 * @param dt time shift in seconds
144 * @return a new state, shifted with respect to the instance (which is immutable)
145 */
146 public TimeStampedAngularCoordinates shiftedBy(final double dt) {
147 final AngularCoordinates sac = super.shiftedBy(dt);
148 return new TimeStampedAngularCoordinates(date.shiftedBy(dt),
149 sac.getRotation(), sac.getRotationRate(), sac.getRotationAcceleration());
150
151 }
152
153 /** Get a time-shifted state.
154 * <p>
155 * The state can be slightly shifted to close dates. This shift is based on
156 * a simple linear model. It is <em>not</em> intended as a replacement for
157 * proper attitude propagation but should be sufficient for either small
158 * time shifts or coarse accuracy.
159 * </p>
160 * @param dt time shift in seconds
161 * @return a new state, shifted with respect to the instance (which is immutable)
162 * @since 13.0
163 */
164 public TimeStampedAngularCoordinates shiftedBy(final TimeOffset dt) {
165 final AngularCoordinates sac = super.shiftedBy(dt);
166 return new TimeStampedAngularCoordinates(date.shiftedBy(dt),
167 sac.getRotation(), sac.getRotationRate(), sac.getRotationAcceleration());
168
169 }
170
171 /** Add an offset from the instance.
172 * <p>
173 * We consider here that the offset rotation is applied first and the
174 * instance is applied afterward. Note that angular coordinates do <em>not</em>
175 * commute under this operation, i.e. {@code a.addOffset(b)} and {@code
176 * b.addOffset(a)} lead to <em>different</em> results in most cases.
177 * </p>
178 * <p>
179 * The two methods {@link #addOffset(AngularCoordinates) addOffset} and
180 * {@link #subtractOffset(AngularCoordinates) subtractOffset} are designed
181 * so that round trip applications are possible. This means that both {@code
182 * ac1.subtractOffset(ac2).addOffset(ac2)} and {@code
183 * ac1.addOffset(ac2).subtractOffset(ac2)} return angular coordinates equal to ac1.
184 * </p>
185 * @param offset offset to subtract
186 * @return new instance, with offset subtracted
187 * @see #subtractOffset(AngularCoordinates)
188 */
189 @Override
190 public TimeStampedAngularCoordinates addOffset(final AngularCoordinates offset) {
191 final Vector3D rOmega = getRotation().applyTo(offset.getRotationRate());
192 final Vector3D rOmegaDot = getRotation().applyTo(offset.getRotationAcceleration());
193 return new TimeStampedAngularCoordinates(date,
194 getRotation().compose(offset.getRotation(), RotationConvention.VECTOR_OPERATOR),
195 getRotationRate().add(rOmega),
196 new Vector3D( 1.0, getRotationAcceleration(),
197 1.0, rOmegaDot,
198 -1.0, Vector3D.crossProduct(getRotationRate(), rOmega)));
199 }
200
201 /** Subtract an offset from the instance.
202 * <p>
203 * We consider here that the offset rotation is applied first and the
204 * instance is applied afterward. Note that angular coordinates do <em>not</em>
205 * commute under this operation, i.e. {@code a.subtractOffset(b)} and {@code
206 * b.subtractOffset(a)} lead to <em>different</em> results in most cases.
207 * </p>
208 * <p>
209 * The two methods {@link #addOffset(AngularCoordinates) addOffset} and
210 * {@link #subtractOffset(AngularCoordinates) subtractOffset} are designed
211 * so that round trip applications are possible. This means that both {@code
212 * ac1.subtractOffset(ac2).addOffset(ac2)} and {@code
213 * ac1.addOffset(ac2).subtractOffset(ac2)} return angular coordinates equal to ac1.
214 * </p>
215 * @param offset offset to subtract
216 * @return new instance, with offset subtracted
217 * @see #addOffset(AngularCoordinates)
218 */
219 @Override
220 public TimeStampedAngularCoordinates subtractOffset(final AngularCoordinates offset) {
221 return addOffset(offset.revert());
222 }
223
224 }