Attitude.java

  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. import org.hipparchus.geometry.euclidean.threed.Rotation;
  19. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.frames.Transform;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.TimeOffset;
  25. import org.orekit.time.TimeShiftable;
  26. import org.orekit.time.TimeStamped;
  27. import org.orekit.utils.AngularCoordinates;
  28. import org.orekit.utils.TimeStampedAngularCoordinates;


  29. /** This class handles attitude definition at a given date.

  30.  * <p>This class represents the rotation between a reference frame and
  31.  * the satellite frame, as well as the spin of the satellite (axis and
  32.  * rotation rate).</p>
  33.  * <p>
  34.  * The state can be slightly shifted to close dates. This shift is based on
  35.  * a linear extrapolation for attitude taking the spin rate into account.
  36.  * It is <em>not</em> intended as a replacement for proper attitude propagation
  37.  * but should be sufficient for either small time shifts or coarse accuracy.
  38.  * </p>
  39.  * <p>The instance <code>Attitude</code> is guaranteed to be immutable.</p>
  40.  * @see     org.orekit.orbits.Orbit
  41.  * @see AttitudeProvider
  42.  * @author V&eacute;ronique Pommier-Maurussane
  43.  */

  44. public class Attitude implements TimeStamped, TimeShiftable<Attitude> {

  45.     /** Reference frame. */
  46.     private final Frame referenceFrame;

  47.      /** Attitude and spin.  */
  48.     private final TimeStampedAngularCoordinates orientation;

  49.     /** Creates a new instance.
  50.      * @param referenceFrame reference frame from which attitude is defined
  51.      * @param orientation complete orientation between reference frame and satellite frame,
  52.      * including rotation rate
  53.      */
  54.     public Attitude(final Frame referenceFrame, final TimeStampedAngularCoordinates orientation) {
  55.         this.referenceFrame = referenceFrame;
  56.         this.orientation    = orientation;
  57.     }

  58.     /** Creates a new instance.
  59.      * @param date date at which attitude is defined
  60.      * @param referenceFrame reference frame from which attitude is defined
  61.      * @param orientation complete orientation between reference frame and satellite frame,
  62.      * including rotation rate
  63.      */
  64.     public Attitude(final AbsoluteDate date, final Frame referenceFrame,
  65.                     final AngularCoordinates orientation) {
  66.         this(referenceFrame,
  67.              new TimeStampedAngularCoordinates(date,
  68.                                                orientation.getRotation(),
  69.                                                orientation.getRotationRate(),
  70.                                                orientation.getRotationAcceleration()));
  71.     }

  72.     /** Creates a new instance.
  73.      * @param date date at which attitude is defined
  74.      * @param referenceFrame reference frame from which attitude is defined
  75.      * @param attitude rotation between reference frame and satellite frame
  76.      * @param spin satellite spin (axis and velocity, in <strong>satellite</strong> frame)
  77.      * @param acceleration satellite rotation acceleration (in <strong>satellite</strong> frame)
  78.      */
  79.     public Attitude(final AbsoluteDate date, final Frame referenceFrame,
  80.                     final Rotation attitude, final Vector3D spin, final Vector3D acceleration) {
  81.         this(referenceFrame, new TimeStampedAngularCoordinates(date, attitude, spin, acceleration));
  82.     }

  83.     /** Get a time-shifted attitude.
  84.      * <p>
  85.      * The state can be slightly shifted to close dates. This shift is based on
  86.      * a linear extrapolation for attitude taking the spin rate into account.
  87.      * It is <em>not</em> intended as a replacement for proper attitude propagation
  88.      * but should be sufficient for either small time shifts or coarse accuracy.
  89.      * </p>
  90.      * @param dt time shift in seconds
  91.      * @return a new attitude, shifted with respect to the instance (which is immutable)
  92.      */
  93.     public Attitude shiftedBy(final double dt) {
  94.         return new Attitude(referenceFrame, orientation.shiftedBy(dt));
  95.     }

  96.     /** Get a time-shifted attitude.
  97.      * <p>
  98.      * The state can be slightly shifted to close dates. This shift is based on
  99.      * a linear extrapolation for attitude taking the spin rate into account.
  100.      * It is <em>not</em> intended as a replacement for proper attitude propagation
  101.      * but should be sufficient for either small time shifts or coarse accuracy.
  102.      * </p>
  103.      * @param dt time shift
  104.      * @return a new attitude, shifted with respect to the instance (which is immutable)
  105.      * @since 13.0
  106.      */
  107.     @Override
  108.     public Attitude shiftedBy(final TimeOffset dt) {
  109.         return new Attitude(referenceFrame, orientation.shiftedBy(dt));
  110.     }

  111.     /** Get a similar attitude with a specific reference frame.
  112.      * <p>
  113.      * If the instance reference frame is already the specified one, the instance
  114.      * itself is returned without any object creation. Otherwise, a new instance
  115.      * will be created with the specified reference frame. In this case, the
  116.      * required intermediate rotation and spin between the specified and the
  117.      * original reference frame will be inserted.
  118.      * </p>
  119.      * @param newReferenceFrame desired reference frame for attitude
  120.      * @return an attitude that has the same orientation and motion as the instance,
  121.      * but guaranteed to have the specified reference frame
  122.      */
  123.     public Attitude withReferenceFrame(final Frame newReferenceFrame) {

  124.         if (newReferenceFrame == referenceFrame) {
  125.             // simple case, the instance is already compliant
  126.             return this;
  127.         }

  128.         // we have to take an intermediate rotation into account
  129.         final Transform t = newReferenceFrame.getTransformTo(referenceFrame, orientation.getDate());
  130.         return new Attitude(orientation.getDate(), newReferenceFrame,
  131.                             orientation.getRotation().compose(t.getRotation(), RotationConvention.VECTOR_OPERATOR),
  132.                             orientation.getRotationRate().add(orientation.getRotation().applyTo(t.getRotationRate())),
  133.                             orientation.getRotationAcceleration().add(orientation.getRotation().applyTo(t.getRotationAcceleration())));

  134.     }

  135.     /** Get the date of attitude parameters.
  136.      * @return date of the attitude parameters
  137.      */
  138.     public AbsoluteDate getDate() {
  139.         return orientation.getDate();
  140.     }

  141.     /** Get the reference frame.
  142.      * @return referenceFrame reference frame from which attitude is defined.
  143.      */
  144.     public Frame getReferenceFrame() {
  145.         return referenceFrame;
  146.     }

  147.     /** Get the complete orientation including spin.
  148.      * @return complete orientation including spin
  149.      * @see #getRotation()
  150.      * @see #getSpin()
  151.      */
  152.     public TimeStampedAngularCoordinates getOrientation() {
  153.         return orientation;
  154.     }

  155.     /** Get the attitude rotation.
  156.      * @return attitude satellite rotation from reference frame.
  157.      * @see #getOrientation()
  158.      * @see #getSpin()
  159.      */
  160.     public Rotation getRotation() {
  161.         return orientation.getRotation();
  162.     }

  163.     /** Get the satellite spin.
  164.      * <p>The spin vector is defined in <strong>satellite</strong> frame.</p>
  165.      * @return spin satellite spin (axis and velocity).
  166.      * @see #getOrientation()
  167.      * @see #getRotation()
  168.      */
  169.     public Vector3D getSpin() {
  170.         return orientation.getRotationRate();
  171.     }

  172.     /** Get the satellite rotation acceleration.
  173.      * <p>The rotation acceleration. vector is defined in <strong>satellite</strong> frame.</p>
  174.      * @return rotation acceleration
  175.      * @see #getOrientation()
  176.      * @see #getRotation()
  177.      */
  178.     public Vector3D getRotationAcceleration() {
  179.         return orientation.getRotationAcceleration();
  180.     }

  181. }