AbstractOrbitInterpolator.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.orbits;

  18. import org.orekit.errors.OrekitIllegalArgumentException;
  19. import org.orekit.errors.OrekitMessages;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.time.AbsoluteDate;
  22. import org.orekit.time.AbstractTimeInterpolator;

  23. import java.util.ArrayList;
  24. import java.util.Collection;
  25. import java.util.List;

  26. /**
  27.  * Abstract class for orbit interpolator.
  28.  *
  29.  * @author Vincent Cucchietti
  30.  */
  31. public abstract class AbstractOrbitInterpolator extends AbstractTimeInterpolator<Orbit> {

  32.     /** Output inertial frame. */
  33.     private final Frame outputInertialFrame;

  34.     /**
  35.      * Constructor.
  36.      *
  37.      * @param interpolationPoints number of interpolation points
  38.      * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
  39.      * @param outputInertialFrame output inertial frame
  40.      */
  41.     public AbstractOrbitInterpolator(final int interpolationPoints, final double extrapolationThreshold,
  42.                                      final Frame outputInertialFrame) {
  43.         super(interpolationPoints, extrapolationThreshold);
  44.         checkFrameIsInertial(outputInertialFrame);
  45.         this.outputInertialFrame = outputInertialFrame;
  46.     }

  47.     /**
  48.      * Check orbits consistency by comparing their gravitational parameters ยต.
  49.      *
  50.      * @param sample orbits sample
  51.      */
  52.     public static void checkOrbitsConsistency(final Collection<Orbit> sample) {
  53.         // Convert sample to list
  54.         final List<Orbit> sampleList = new ArrayList<>(sample);

  55.         // Check consistency
  56.         for (int i = 0; i < sampleList.size() - 1; i++) {
  57.             final Orbit currentOrbit = sampleList.get(i);
  58.             final Orbit nextOrbit    = sampleList.get(i + 1);

  59.             if (currentOrbit.getMu() != nextOrbit.getMu()) {
  60.                 throw new OrekitIllegalArgumentException(OrekitMessages.ORBITS_MUS_MISMATCH, currentOrbit.getMu(),
  61.                                                          nextOrbit.getMu());
  62.             }
  63.         }
  64.     }

  65.     /** {@inheritDoc}. */
  66.     @Override
  67.     public Orbit interpolate(final AbsoluteDate interpolationDate, final Collection<Orbit> sample) {

  68.         // Check orbits consistency
  69.         checkOrbitsConsistency(sample);

  70.         return super.interpolate(interpolationDate, sample);
  71.     }

  72.     /** Get output inertial frame.
  73.      * @return output inertial frame
  74.      */
  75.     public Frame getOutputInertialFrame() {
  76.         return outputInertialFrame;
  77.     }

  78.     /**
  79.      * Check if given frame is pseudo inertial and throw an error otherwise.
  80.      *
  81.      * @param frame frame to check
  82.      *
  83.      * @throws OrekitIllegalArgumentException if given frame is not pseudo inertial
  84.      */
  85.     private void checkFrameIsInertial(final Frame frame) {
  86.         if (!frame.isPseudoInertial()) {
  87.             throw new OrekitIllegalArgumentException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME, frame.getName());
  88.         }
  89.     }
  90. }