FieldAttitudeInterpolator.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.orekit.frames.Frame;
  20. import org.orekit.time.AbstractFieldTimeInterpolator;
  21. import org.orekit.time.FieldTimeInterpolator;
  22. import org.orekit.utils.TimeStampedFieldAngularCoordinates;

  23. import java.util.List;
  24. import java.util.stream.Collectors;
  25. import java.util.stream.Stream;

  26. /**
  27.  * Class for attitude interpolation.
  28.  * <p>
  29.  * The type of interpolation used is defined by given time stamped angular coordinates interpolator at construction.
  30.  *
  31.  * @param <KK> type of the field element
  32.  *
  33.  * @author Vincent Cucchietti
  34.  * @see TimeStampedFieldAngularCoordinates
  35.  * @see FieldTimeInterpolator
  36.  */
  37. public class FieldAttitudeInterpolator<KK extends CalculusFieldElement<KK>>
  38.         extends AbstractFieldTimeInterpolator<FieldAttitude<KK>, KK> {

  39.     /** Reference frame from which attitude is defined. */
  40.     private final Frame referenceFrame;

  41.     /** Time stamped angular coordinates interpolator. */
  42.     private final FieldTimeInterpolator<TimeStampedFieldAngularCoordinates<KK>, KK> interpolator;

  43.     /**
  44.      * Constructor.
  45.      *
  46.      * @param referenceFrame reference frame from which attitude is defined
  47.      * @param interpolator time stamped angular coordinates interpolator
  48.      */
  49.     public FieldAttitudeInterpolator(final Frame referenceFrame,
  50.                                      final FieldTimeInterpolator<TimeStampedFieldAngularCoordinates<KK>, KK> interpolator) {
  51.         super(interpolator.getNbInterpolationPoints(), interpolator.getExtrapolationThreshold());
  52.         this.referenceFrame = referenceFrame;
  53.         this.interpolator   = interpolator;
  54.     }

  55.     /** Get reference frame from which attitude is defined.
  56.      * @return reference frame from which attitude is defined
  57.      */
  58.     public Frame getReferenceFrame() {
  59.         return referenceFrame;
  60.     }

  61.     /** Get time stamped angular coordinates interpolator.
  62.      * @return time stamped angular coordinates interpolator
  63.      */
  64.     public FieldTimeInterpolator<TimeStampedFieldAngularCoordinates<KK>, KK> getAngularInterpolator() {
  65.         return interpolator;
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     protected FieldAttitude<KK> interpolate(final InterpolationData interpolationData) {

  70.         // Convert sample to stream
  71.         final Stream<FieldAttitude<KK>> sample = interpolationData.getNeighborList().stream();

  72.         // Express all attitudes in the same reference frame
  73.         final Stream<FieldAttitude<KK>> consistentSample =
  74.                 sample.map(attitude -> attitude.withReferenceFrame(referenceFrame));

  75.         // Map time stamped angular coordinates
  76.         final List<TimeStampedFieldAngularCoordinates<KK>> angularSample =
  77.                 consistentSample.map(FieldAttitude::getOrientation).collect(Collectors.toList());

  78.         // Interpolate
  79.         final TimeStampedFieldAngularCoordinates<KK> interpolated =
  80.                 interpolator.interpolate(interpolationData.getInterpolationDate(), angularSample);

  81.         return new FieldAttitude<>(referenceFrame, interpolated);
  82.     }
  83. }