FrameAlignedProvider.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.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  20. import org.hipparchus.geometry.euclidean.threed.Rotation;
  21. import org.orekit.annotation.DefaultDataContext;
  22. import org.orekit.data.DataContext;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.frames.Transform;
  25. import org.orekit.frames.FieldTransform;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.time.FieldAbsoluteDate;
  28. import org.orekit.utils.FieldPVCoordinatesProvider;
  29. import org.orekit.utils.PVCoordinatesProvider;


  30. /**
  31.  * This class handles an attitude provider aligned with a frame or a fixed offset to it.
  32.  * <p>Instances of this class are guaranteed to be immutable.</p>
  33.  * @author Luc Maisonobe
  34.  */
  35. public class FrameAlignedProvider implements AttitudeProvider {

  36.     /** Fixed satellite frame. */
  37.     private final Frame satelliteFrame;

  38.     /** Creates new instance.
  39.      *
  40.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  41.      *
  42.      * @param rotation rotation from EME2000 to the desired satellite frame
  43.      * @see #FrameAlignedProvider(Rotation, Frame)
  44.      */
  45.     @DefaultDataContext
  46.     public FrameAlignedProvider(final Rotation rotation) {
  47.         this(rotation, DataContext.getDefault().getFrames().getEME2000());
  48.     }

  49.     /**
  50.      * Creates new instance aligned with the given frame.
  51.      *
  52.      * @param frame the reference frame for the attitude.
  53.      */
  54.     public FrameAlignedProvider(final Frame frame) {
  55.         // it is faster to use the frame directly here rather than call the other
  56.         // constructor because of the == shortcut in frame.getTransformTo
  57.         this.satelliteFrame = frame;
  58.     }

  59.     /**
  60.      * Creates new instance with a fixed attitude in the given frame.
  61.      *
  62.      * @param rotation  rotation from {@code reference} to the desired satellite frame
  63.      * @param reference frame for {@code rotation}.
  64.      * @since 10.1
  65.      */
  66.     public FrameAlignedProvider(final Rotation rotation,
  67.                                 final Frame reference) {
  68.         satelliteFrame =
  69.             new Frame(reference,
  70.                       new Transform(AbsoluteDate.ARBITRARY_EPOCH, rotation), null, false);
  71.     }

  72.     /**
  73.      * Creates an attitude provider aligned with the given frame.
  74.      *
  75.      * <p>This attitude provider returned by this method is designed to be as fast as
  76.      * possible for when attitude is irrelevant while still being a valid implementation
  77.      * of {@link AttitudeProvider}. To ensure good performance the specified attitude
  78.      * reference frame should be the same frame used for propagation so that computing the
  79.      * frame transformation is trivial.
  80.      *
  81.      * @param satelliteFrame with which the satellite is aligned.
  82.      * @return new attitude provider aligned with the given frame.
  83.      * @since 11.0
  84.      */
  85.     public static AttitudeProvider of(final Frame satelliteFrame) {
  86.         return new FrameAlignedProvider(satelliteFrame);
  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  91.                                 final AbsoluteDate date,
  92.                                 final Frame frame) {
  93.         final Transform t = frame.getTransformTo(satelliteFrame, date);
  94.         return new Attitude(date, frame, t.getRotation(), t.getRotationRate(), t.getRotationAcceleration());
  95.     }

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     public <T extends CalculusFieldElement<T>>FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  99.                                                                            final FieldAbsoluteDate<T> date,
  100.                                                                            final Frame frame) {
  101.         final FieldTransform<T> t = frame.getTransformTo(satelliteFrame, date);
  102.         return new FieldAttitude<>(date, frame, t.getRotation(), t.getRotationRate(), t.getRotationAcceleration());
  103.     }

  104.     /** {@inheritDoc} */
  105.     @Override
  106.     public Rotation getAttitudeRotation(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) {
  107.         return frame.getStaticTransformTo(satelliteFrame, date).getRotation();
  108.     }

  109.     /** {@inheritDoc} */
  110.     @Override
  111.     public <T extends CalculusFieldElement<T>> FieldRotation<T> getAttitudeRotation(final FieldPVCoordinatesProvider<T> pvProv,
  112.                                                                                     final FieldAbsoluteDate<T> date,
  113.                                                                                     final Frame frame) {
  114.         return frame.getStaticTransformTo(satelliteFrame, date).getRotation();
  115.     }

  116. }