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