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.attitudes;
18  
19  import org.hipparchus.geometry.euclidean.threed.Rotation;
20  import org.hipparchus.geometry.euclidean.threed.RotationConvention;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.orekit.frames.Frame;
23  import org.orekit.frames.Transform;
24  import org.orekit.time.AbsoluteDate;
25  import org.orekit.time.TimeOffset;
26  import org.orekit.time.TimeShiftable;
27  import org.orekit.time.TimeStamped;
28  import org.orekit.utils.AngularCoordinates;
29  import org.orekit.utils.TimeStampedAngularCoordinates;
30  
31  
32  /** This class handles attitude definition at a given date.
33  
34   * <p>This class represents the rotation between a reference frame and
35   * the satellite frame, as well as the spin of the satellite (axis and
36   * rotation rate).</p>
37   * <p>
38   * The state can be slightly shifted to close dates. This shift is based on
39   * a linear extrapolation for attitude taking the spin rate into account.
40   * It is <em>not</em> intended as a replacement for proper attitude propagation
41   * but should be sufficient for either small time shifts or coarse accuracy.
42   * </p>
43   * <p>The instance <code>Attitude</code> is guaranteed to be immutable.</p>
44   * @see     org.orekit.orbits.Orbit
45   * @see AttitudeProvider
46   * @author V&eacute;ronique Pommier-Maurussane
47   */
48  
49  public class Attitude implements TimeStamped, TimeShiftable<Attitude> {
50  
51      /** Reference frame. */
52      private final Frame referenceFrame;
53  
54       /** Attitude and spin.  */
55      private final TimeStampedAngularCoordinates orientation;
56  
57      /** Creates a new instance.
58       * @param referenceFrame reference frame from which attitude is defined
59       * @param orientation complete orientation between reference frame and satellite frame,
60       * including rotation rate
61       */
62      public Attitude(final Frame referenceFrame, final TimeStampedAngularCoordinates orientation) {
63          this.referenceFrame = referenceFrame;
64          this.orientation    = orientation;
65      }
66  
67      /** Creates a new instance.
68       * @param date date at which attitude is defined
69       * @param referenceFrame reference frame from which attitude is defined
70       * @param orientation complete orientation between reference frame and satellite frame,
71       * including rotation rate
72       */
73      public Attitude(final AbsoluteDate date, final Frame referenceFrame,
74                      final AngularCoordinates orientation) {
75          this(referenceFrame,
76               new TimeStampedAngularCoordinates(date, orientation));
77      }
78  
79      /** Creates a new instance.
80       * @param date date at which attitude is defined
81       * @param referenceFrame reference frame from which attitude is defined
82       * @param attitude rotation between reference frame and satellite frame
83       * @param spin satellite spin (axis and velocity, in <strong>satellite</strong> frame)
84       * @param acceleration satellite rotation acceleration (in <strong>satellite</strong> frame)
85       */
86      public Attitude(final AbsoluteDate date, final Frame referenceFrame,
87                      final Rotation attitude, final Vector3D spin, final Vector3D acceleration) {
88          this(referenceFrame, new TimeStampedAngularCoordinates(date, attitude, spin, acceleration));
89      }
90  
91      /** Get a time-shifted attitude.
92       * <p>
93       * The state can be slightly shifted to close dates. This shift is based on
94       * a linear extrapolation for attitude taking the spin rate into account.
95       * It is <em>not</em> intended as a replacement for proper attitude propagation
96       * but should be sufficient for either small time shifts or coarse accuracy.
97       * </p>
98       * @param dt time shift in seconds
99       * @return a new attitude, shifted with respect to the instance (which is immutable)
100      */
101     public Attitude shiftedBy(final double dt) {
102         return new Attitude(referenceFrame, orientation.shiftedBy(dt));
103     }
104 
105     /** Get a time-shifted attitude.
106      * <p>
107      * The state can be slightly shifted to close dates. This shift is based on
108      * a linear extrapolation for attitude taking the spin rate into account.
109      * It is <em>not</em> intended as a replacement for proper attitude propagation
110      * but should be sufficient for either small time shifts or coarse accuracy.
111      * </p>
112      * @param dt time shift
113      * @return a new attitude, shifted with respect to the instance (which is immutable)
114      * @since 13.0
115      */
116     @Override
117     public Attitude shiftedBy(final TimeOffset dt) {
118         return new Attitude(referenceFrame, orientation.shiftedBy(dt));
119     }
120 
121     /** Get a similar attitude with a specific reference frame.
122      * <p>
123      * If the instance reference frame is already the specified one, the instance
124      * itself is returned without any object creation. Otherwise, a new instance
125      * will be created with the specified reference frame. In this case, the
126      * required intermediate rotation and spin between the specified and the
127      * original reference frame will be inserted.
128      * </p>
129      * @param newReferenceFrame desired reference frame for attitude
130      * @return an attitude that has the same orientation and motion as the instance,
131      * but guaranteed to have the specified reference frame
132      */
133     public Attitude withReferenceFrame(final Frame newReferenceFrame) {
134 
135         if (newReferenceFrame == referenceFrame) {
136             // simple case, the instance is already compliant
137             return this;
138         }
139 
140         // we have to take an intermediate rotation into account
141         final Transform t = newReferenceFrame.getTransformTo(referenceFrame, orientation.getDate());
142         return new Attitude(orientation.getDate(), newReferenceFrame,
143                             orientation.getRotation().compose(t.getRotation(), RotationConvention.VECTOR_OPERATOR),
144                             orientation.getRotationRate().add(orientation.getRotation().applyTo(t.getRotationRate())),
145                             orientation.getRotationAcceleration().add(orientation.getRotation().applyTo(t.getRotationAcceleration())));
146 
147     }
148 
149     /** Get the date of attitude parameters.
150      * @return date of the attitude parameters
151      */
152     public AbsoluteDate getDate() {
153         return orientation.getDate();
154     }
155 
156     /** Get the reference frame.
157      * @return referenceFrame reference frame from which attitude is defined.
158      */
159     public Frame getReferenceFrame() {
160         return referenceFrame;
161     }
162 
163     /** Get the complete orientation including spin.
164      * @return complete orientation including spin
165      * @see #getRotation()
166      * @see #getSpin()
167      */
168     public TimeStampedAngularCoordinates getOrientation() {
169         return orientation;
170     }
171 
172     /** Get the attitude rotation.
173      * @return attitude satellite rotation from reference frame.
174      * @see #getOrientation()
175      * @see #getSpin()
176      */
177     public Rotation getRotation() {
178         return orientation.getRotation();
179     }
180 
181     /** Get the satellite spin.
182      * <p>The spin vector is defined in <strong>satellite</strong> frame.</p>
183      * @return spin satellite spin (axis and velocity).
184      * @see #getOrientation()
185      * @see #getRotation()
186      */
187     public Vector3D getSpin() {
188         return orientation.getRotationRate();
189     }
190 
191     /** Get the satellite rotation acceleration.
192      * <p>The rotation acceleration. vector is defined in <strong>satellite</strong> frame.</p>
193      * @return rotation acceleration
194      * @see #getOrientation()
195      * @see #getRotation()
196      */
197     public Vector3D getRotationAcceleration() {
198         return orientation.getRotationAcceleration();
199     }
200 
201 }