TimeStampedDoubleAndDerivativeHermiteInterpolator.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.  * @author Luc Maisonobe
  25.  * @see HermiteInterpolator
  26.  * @see TimeInterpolator
  27.  */
  28. public class TimeStampedDoubleAndDerivativeHermiteInterpolator
  29.     extends AbstractTimeInterpolator<TimeStampedDoubleAndDerivative> {

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

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

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

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     protected TimeStampedDoubleAndDerivative interpolate(final InterpolationData interpolationData) {
  71.         final HermiteInterpolator interpolator = new HermiteInterpolator();

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

  81.         final double[][] y = interpolator.derivatives(0, 1);
  82.         return new TimeStampedDoubleAndDerivative(y[0][0], y[1][0], interpolationDate);
  83.     }

  84. }