AttitudeInterpolator.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.orekit.frames.Frame;
  19. import org.orekit.time.AbstractTimeInterpolator;
  20. import org.orekit.time.TimeInterpolator;
  21. import org.orekit.utils.TimeStampedAngularCoordinates;

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

  25. /**
  26.  * Class for attitude interpolation.
  27.  * <p>
  28.  * The type of interpolation used is defined by given time stamped angular coordinates interpolator at construction.
  29.  *
  30.  * @author Vincent Cucchietti
  31.  * @see TimeStampedAngularCoordinates
  32.  * @see TimeInterpolator
  33.  */
  34. public class AttitudeInterpolator extends AbstractTimeInterpolator<Attitude> {

  35.     /** Reference frame from which attitude is defined. */
  36.     private final Frame referenceFrame;

  37.     /** Time stamped angular coordinates interpolator. */
  38.     private final TimeInterpolator<TimeStampedAngularCoordinates> interpolator;

  39.     /**
  40.      * Constructor.
  41.      *
  42.      * @param referenceFrame reference frame from which attitude is defined
  43.      * @param interpolator time stamped angular coordinates interpolator
  44.      */
  45.     public AttitudeInterpolator(final Frame referenceFrame,
  46.                                 final TimeInterpolator<TimeStampedAngularCoordinates> interpolator) {
  47.         super(interpolator.getNbInterpolationPoints(), interpolator.getExtrapolationThreshold());
  48.         this.referenceFrame = referenceFrame;
  49.         this.interpolator   = interpolator;
  50.     }

  51.     /** Get reference frame from which attitude is defined.
  52.      * @return reference frame from which attitude is defined
  53.      */
  54.     public Frame getReferenceFrame() {
  55.         return referenceFrame;
  56.     }

  57.     /** Get time stamped angular coordinates interpolator.
  58.      * @return time stamped angular coordinates interpolator
  59.      */
  60.     public TimeInterpolator<TimeStampedAngularCoordinates> getAngularInterpolator() {
  61.         return interpolator;
  62.     }

  63.     /** {@inheritDoc} */
  64.     @Override
  65.     protected Attitude interpolate(final InterpolationData interpolationData) {

  66.         // Convert sample to stream
  67.         final Stream<Attitude> sample = interpolationData.getNeighborList().stream();

  68.         // Express all attitudes in the same reference frame
  69.         final Stream<Attitude> consistentSample =
  70.                 sample.map(attitude -> attitude.withReferenceFrame(referenceFrame));

  71.         // Map time stamped angular coordinates
  72.         final List<TimeStampedAngularCoordinates> angularSample =
  73.                 consistentSample.map(Attitude::getOrientation).collect(Collectors.toList());

  74.         // Interpolate
  75.         final TimeStampedAngularCoordinates interpolated = interpolator.interpolate(interpolationData.getInterpolationDate(),
  76.                                                                                     angularSample);

  77.         return new Attitude(referenceFrame, interpolated);
  78.     }
  79. }