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.time;
18  
19  import org.hipparchus.analysis.interpolation.HermiteInterpolator;
20  
21  import java.util.List;
22  
23  /**
24   * Hermite interpolator of time stamped double value.
25   *
26   * @author Vincent Cucchietti
27   * @see HermiteInterpolator
28   * @see TimeInterpolator
29   */
30  public class TimeStampedDoubleHermiteInterpolator extends AbstractTimeInterpolator<TimeStampedDouble> {
31  
32      /**
33       * Constructor with :
34       * <ul>
35       *     <li>Default number of interpolation points of {@code DEFAULT_INTERPOLATION_POINTS}</li>
36       *     <li>Default extrapolation threshold value ({@code DEFAULT_EXTRAPOLATION_THRESHOLD_SEC} s)</li>
37       * </ul>
38       * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
39       * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
40       * phenomenon</a> and numerical problems (including NaN appearing).
41       */
42      public TimeStampedDoubleHermiteInterpolator() {
43          this(DEFAULT_INTERPOLATION_POINTS);
44      }
45  
46      /**
47       * Constructor with default extrapolation threshold value ({@code DEFAULT_EXTRAPOLATION_THRESHOLD_SEC} s).
48       * <p>
49       * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
50       * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
51       * phenomenon</a> and numerical problems (including NaN appearing).
52       *
53       * @param interpolationPoints number of interpolation points
54       */
55      public TimeStampedDoubleHermiteInterpolator(final int interpolationPoints) {
56          this(interpolationPoints, DEFAULT_EXTRAPOLATION_THRESHOLD_SEC);
57      }
58  
59      /**
60       * Constructor.
61       * <p>
62       * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
63       * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
64       * phenomenon</a> and numerical problems (including NaN appearing).
65       *
66       * @param interpolationPoints number of interpolation points
67       * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
68       */
69      public TimeStampedDoubleHermiteInterpolator(final int interpolationPoints, final double extrapolationThreshold) {
70          super(interpolationPoints, extrapolationThreshold);
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      protected TimeStampedDouble interpolate(final InterpolationData interpolationData) {
76          final HermiteInterpolator interpolator = new HermiteInterpolator();
77  
78          // Fill interpolator with sample
79          final AbsoluteDate            interpolationDate = interpolationData.getInterpolationDate();
80          final List<TimeStampedDouble> neighborList      = interpolationData.getNeighborList();
81          for (TimeStampedDouble value : neighborList) {
82              final double deltaT = value.getDate().durationFrom(interpolationDate);
83              interpolator.addSamplePoint(deltaT, new double[] { value.getValue() });
84          }
85  
86          return new TimeStampedDouble(interpolator.value(0)[0], interpolationDate);
87      }
88  }