use of org.orekit.orbits.FieldOrbit in project Orekit by CS-SI.
the class FieldSpacecraftState method interpolate.
/**
* Get an interpolated instance.
* <p>
* The additional states that are interpolated are the ones already present
* in the instance. The sample instances must therefore have at least the same
* additional states has the instance. They may have more additional states,
* but the extra ones will be ignored.
* </p>
* <p>
* As this implementation of interpolation is polynomial, it should be used only
* with small samples (about 10-20 points) in order to avoid <a
* href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's phenomenon</a>
* and numerical problems (including NaN appearing).
* </p>
* @param date interpolation date
* @param sample sample points on which interpolation should be done
* @return a new instance, interpolated at specified date
* @exception OrekitException if the number of point is too small for interpolating
*/
public FieldSpacecraftState<T> interpolate(final FieldAbsoluteDate<T> date, final Stream<FieldSpacecraftState<T>> sample) throws OrekitException {
// prepare interpolators
final List<FieldOrbit<T>> orbits = new ArrayList<>();
final List<FieldAttitude<T>> attitudes = new ArrayList<>();
final FieldHermiteInterpolator<T> massInterpolator = new FieldHermiteInterpolator<>();
final Map<String, FieldHermiteInterpolator<T>> additionalInterpolators = new HashMap<String, FieldHermiteInterpolator<T>>(additional.size());
for (final String name : additional.keySet()) {
additionalInterpolators.put(name, new FieldHermiteInterpolator<>());
}
// extract sample data
try {
sample.forEach(state -> {
try {
final T deltaT = state.getDate().durationFrom(date);
orbits.add(state.getOrbit());
attitudes.add(state.getAttitude());
final T[] mm = MathArrays.buildArray(orbit.getA().getField(), 1);
mm[0] = state.getMass();
massInterpolator.addSamplePoint(deltaT, mm);
for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
entry.getValue().addSamplePoint(deltaT, state.getAdditionalState(entry.getKey()));
}
} catch (OrekitException oe) {
throw new OrekitExceptionWrapper(oe);
}
});
} catch (OrekitExceptionWrapper oew) {
throw oew.getException();
}
// perform interpolations
final FieldOrbit<T> interpolatedOrbit = orbit.interpolate(date, orbits);
final FieldAttitude<T> interpolatedAttitude = attitude.interpolate(date, attitudes);
final T interpolatedMass = massInterpolator.value(orbit.getA().getField().getZero())[0];
final Map<String, T[]> interpolatedAdditional;
if (additional.isEmpty()) {
interpolatedAdditional = null;
} else {
interpolatedAdditional = new HashMap<String, T[]>(additional.size());
for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
interpolatedAdditional.put(entry.getKey(), entry.getValue().value(orbit.getA().getField().getZero()));
}
}
// create the complete interpolated state
return new FieldSpacecraftState<>(interpolatedOrbit, interpolatedAttitude, interpolatedMass, interpolatedAdditional);
}
Aggregations