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