FixedRate.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.Field;
  19. import org.hipparchus.CalculusFieldElement;
  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.orekit.frames.FieldStaticTransform;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.frames.StaticTransform;
  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 a simple attitude provider at constant rate around a fixed axis.
  32.  * <p>This attitude provider is a simple linear extrapolation from an initial
  33.  * orientation, a rotation axis and a rotation rate. All this elements can be
  34.  * specified as a simple {@link Attitude reference attitude}.</p>
  35.  * <p>Instances of this class are guaranteed to be immutable.</p>
  36.  * @author Luc Maisonobe
  37.  */
  38. public class FixedRate implements AttitudeProvider {

  39.     /** Reference attitude.  */
  40.     private final Attitude referenceAttitude;

  41.     /** Creates a new instance.
  42.      * @param referenceAttitude attitude at reference date
  43.      */
  44.     public FixedRate(final Attitude referenceAttitude) {
  45.         this.referenceAttitude = referenceAttitude;
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     public Rotation getAttitudeRotation(final PVCoordinatesProvider pvProv, final AbsoluteDate date,
  50.                                         final Frame frame) {
  51.         final Rotation rotation = getShiftedAttitude(date).getRotation();
  52.         final StaticTransform transform = referenceAttitude.getReferenceFrame().getStaticTransformTo(frame, date);
  53.         return rotation.compose(transform.getRotation(), RotationConvention.FRAME_TRANSFORM);
  54.     }

  55.     /** {@inheritDoc} */
  56.     @Override
  57.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  58.                                 final AbsoluteDate date, final Frame frame) {
  59.         final Attitude shifted = getShiftedAttitude(date);
  60.         return shifted.withReferenceFrame(frame);
  61.     }

  62.     /**
  63.      * Get shifted reference attitude.
  64.      * @param date date of shift
  65.      * @return shifted attitude
  66.      */
  67.     private Attitude getShiftedAttitude(final AbsoluteDate date) {
  68.         final double timeShift = date.durationFrom(referenceAttitude.getDate());
  69.         return referenceAttitude.shiftedBy(timeShift);
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public <T extends CalculusFieldElement<T>> FieldRotation<T> getAttitudeRotation(final FieldPVCoordinatesProvider<T> pvProv,
  74.                                                                                     final FieldAbsoluteDate<T> date,
  75.                                                                                     final Frame frame) {
  76.         final FieldRotation<T> rotation = getShiftedAttitude(date).getRotation();
  77.         final FieldStaticTransform<T> transform = referenceAttitude.getReferenceFrame().getStaticTransformTo(frame, date);
  78.         return rotation.compose(transform.getRotation(), RotationConvention.FRAME_TRANSFORM);
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public <T extends CalculusFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  83.                                                                             final FieldAbsoluteDate<T> date,
  84.                                                                             final Frame frame) {
  85.         final FieldAttitude<T> shifted = getShiftedAttitude(date);
  86.         return shifted.withReferenceFrame(frame);
  87.     }

  88.     /**
  89.      * Get shifted reference attitude.
  90.      * @param date date of shift
  91.      * @param <T> field type
  92.      * @return shifted attitude
  93.      */
  94.     private <T extends CalculusFieldElement<T>> FieldAttitude<T> getShiftedAttitude(final FieldAbsoluteDate<T> date) {
  95.         final Field<T> field = date.getField();
  96.         final T timeShift = date.durationFrom(referenceAttitude.getDate());
  97.         return new FieldAttitude<>(field, referenceAttitude).shiftedBy(timeShift);
  98.     }

  99.     /** Get the reference attitude.
  100.      * @return reference attitude
  101.      */
  102.     public Attitude getReferenceAttitude() {
  103.         return referenceAttitude;
  104.     }

  105. }