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
19 import org.orekit.errors.OrekitIllegalArgumentException;
20 import org.orekit.errors.OrekitMessages;
21 import org.orekit.frames.Frame;
22 import org.orekit.time.AbsoluteDate;
23 import org.orekit.time.AbstractTimeInterpolator;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.List;
28
29 /**
30 * Abstract class for orbit interpolator.
31 *
32 * @author Vincent Cucchietti
33 */
34 public abstract class AbstractOrbitInterpolator extends AbstractTimeInterpolator<Orbit> {
35
36 /** Output inertial frame. */
37 private final Frame outputInertialFrame;
38
39 /**
40 * Constructor.
41 *
42 * @param interpolationPoints number of interpolation points
43 * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
44 * @param outputInertialFrame output inertial frame
45 */
46 public AbstractOrbitInterpolator(final int interpolationPoints, final double extrapolationThreshold,
47 final Frame outputInertialFrame) {
48 super(interpolationPoints, extrapolationThreshold);
49 checkFrameIsInertial(outputInertialFrame);
50 this.outputInertialFrame = outputInertialFrame;
51 }
52
53 /**
54 * Check orbits consistency by comparing their gravitational parameters ยต.
55 *
56 * @param sample orbits sample
57 */
58 public static void checkOrbitsConsistency(final Collection<Orbit> sample) {
59 // Convert sample to list
60 final List<Orbit> sampleList = new ArrayList<>(sample);
61
62 // Check consistency
63 for (int i = 0; i < sampleList.size() - 1; i++) {
64 final Orbit currentOrbit = sampleList.get(i);
65 final Orbit nextOrbit = sampleList.get(i + 1);
66
67 if (currentOrbit.getMu() != nextOrbit.getMu()) {
68 throw new OrekitIllegalArgumentException(OrekitMessages.ORBITS_MUS_MISMATCH, currentOrbit.getMu(),
69 nextOrbit.getMu());
70 }
71 }
72 }
73
74 /** {@inheritDoc}. */
75 @Override
76 public Orbit interpolate(final AbsoluteDate interpolationDate, final Collection<Orbit> sample) {
77
78 // Check orbits consistency
79 checkOrbitsConsistency(sample);
80
81 return super.interpolate(interpolationDate, sample);
82 }
83
84 /** Get output inertial frame.
85 * @return output inertial frame
86 */
87 public Frame getOutputInertialFrame() {
88 return outputInertialFrame;
89 }
90
91 /**
92 * Check if given frame is pseudo inertial and throw an error otherwise.
93 *
94 * @param frame frame to check
95 *
96 * @throws OrekitIllegalArgumentException if given frame is not pseudo inertial
97 */
98 private void checkFrameIsInertial(final Frame frame) {
99 if (!frame.isPseudoInertial()) {
100 throw new OrekitIllegalArgumentException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME, frame.getName());
101 }
102 }
103 }