TimeStampedDoubleHermiteInterpolator.java

  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. import org.hipparchus.analysis.interpolation.HermiteInterpolator;

  19. import java.util.List;

  20. /**
  21.  * Hermite interpolator of time stamped double value.
  22.  *
  23.  * @author Vincent Cucchietti
  24.  * @see HermiteInterpolator
  25.  * @see TimeInterpolator
  26.  */
  27. public class TimeStampedDoubleHermiteInterpolator extends AbstractTimeInterpolator<TimeStampedDouble> {

  28.     /**
  29.      * Constructor with :
  30.      * <ul>
  31.      *     <li>Default number of interpolation points of {@code DEFAULT_INTERPOLATION_POINTS}</li>
  32.      *     <li>Default extrapolation threshold value ({@code DEFAULT_EXTRAPOLATION_THRESHOLD_SEC} s)</li>
  33.      * </ul>
  34.      * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
  35.      * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
  36.      * phenomenon</a> and numerical problems (including NaN appearing).
  37.      */
  38.     public TimeStampedDoubleHermiteInterpolator() {
  39.         this(DEFAULT_INTERPOLATION_POINTS);
  40.     }

  41.     /**
  42.      * Constructor with default extrapolation threshold value ({@code DEFAULT_EXTRAPOLATION_THRESHOLD_SEC} s).
  43.      * <p>
  44.      * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
  45.      * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
  46.      * phenomenon</a> and numerical problems (including NaN appearing).
  47.      *
  48.      * @param interpolationPoints number of interpolation points
  49.      */
  50.     public TimeStampedDoubleHermiteInterpolator(final int interpolationPoints) {
  51.         this(interpolationPoints, DEFAULT_EXTRAPOLATION_THRESHOLD_SEC);
  52.     }

  53.     /**
  54.      * Constructor.
  55.      * <p>
  56.      * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
  57.      * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
  58.      * phenomenon</a> and numerical problems (including NaN appearing).
  59.      *
  60.      * @param interpolationPoints number of interpolation points
  61.      * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
  62.      */
  63.     public TimeStampedDoubleHermiteInterpolator(final int interpolationPoints, final double extrapolationThreshold) {
  64.         super(interpolationPoints, extrapolationThreshold);
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     protected TimeStampedDouble interpolate(final InterpolationData interpolationData) {
  69.         final HermiteInterpolator interpolator = new HermiteInterpolator();

  70.         // Fill interpolator with sample
  71.         final AbsoluteDate            interpolationDate = interpolationData.getInterpolationDate();
  72.         final List<TimeStampedDouble> neighborList      = interpolationData.getNeighborList();
  73.         for (TimeStampedDouble value : neighborList) {
  74.             final double deltaT = value.getDate().durationFrom(interpolationDate);
  75.             interpolator.addSamplePoint(deltaT, new double[] { value.getValue() });
  76.         }

  77.         return new TimeStampedDouble(interpolator.value(0)[0], interpolationDate);
  78.     }
  79. }