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  
19  import org.orekit.frames.Frame;
20  import org.orekit.time.AbstractTimeInterpolator;
21  import org.orekit.time.TimeInterpolator;
22  import org.orekit.utils.TimeStampedAngularCoordinates;
23  
24  import java.util.List;
25  import java.util.stream.Collectors;
26  import java.util.stream.Stream;
27  
28  /**
29   * Class for attitude interpolation.
30   * <p>
31   * The type of interpolation used is defined by given time stamped angular coordinates interpolator at construction.
32   *
33   * @author Vincent Cucchietti
34   * @see TimeStampedAngularCoordinates
35   * @see TimeInterpolator
36   */
37  public class AttitudeInterpolator extends AbstractTimeInterpolator<Attitude> {
38  
39      /** Reference frame from which attitude is defined. */
40      private final Frame referenceFrame;
41  
42      /** Time stamped angular coordinates interpolator. */
43      private final TimeInterpolator<TimeStampedAngularCoordinates> interpolator;
44  
45      /**
46       * Constructor.
47       *
48       * @param referenceFrame reference frame from which attitude is defined
49       * @param interpolator time stamped angular coordinates interpolator
50       */
51      public AttitudeInterpolator(final Frame referenceFrame,
52                                  final TimeInterpolator<TimeStampedAngularCoordinates> interpolator) {
53          super(interpolator.getNbInterpolationPoints(), interpolator.getExtrapolationThreshold());
54          this.referenceFrame = referenceFrame;
55          this.interpolator   = interpolator;
56      }
57  
58      /** Get reference frame from which attitude is defined.
59       * @return reference frame from which attitude is defined
60       */
61      public Frame getReferenceFrame() {
62          return referenceFrame;
63      }
64  
65      /** Get time stamped angular coordinates interpolator.
66       * @return time stamped angular coordinates interpolator
67       */
68      public TimeInterpolator<TimeStampedAngularCoordinates> getAngularInterpolator() {
69          return interpolator;
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      protected Attitude interpolate(final InterpolationData interpolationData) {
75  
76          // Convert sample to stream
77          final Stream<Attitude> sample = interpolationData.getNeighborList().stream();
78  
79          // Express all attitudes in the same reference frame
80          final Stream<Attitude> consistentSample =
81                  sample.map(attitude -> attitude.withReferenceFrame(referenceFrame));
82  
83          // Map time stamped angular coordinates
84          final List<TimeStampedAngularCoordinates> angularSample =
85                  consistentSample.map(Attitude::getOrientation).collect(Collectors.toList());
86  
87          // Interpolate
88          final TimeStampedAngularCoordinates interpolated = interpolator.interpolate(interpolationData.getInterpolationDate(),
89                                                                                      angularSample);
90  
91          return new Attitude(referenceFrame, interpolated);
92      }
93  }