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