List of usage examples for org.apache.commons.math3.analysis.interpolation HermiteInterpolator addSamplePoint
public void addSamplePoint(final double x, final double[]... value) throws ZeroException, MathArithmeticException
From source file:org.orekit.propagation.SpacecraftState.java
/** {@inheritDoc} * <p>/*ww w.j av a2 s. c o m*/ * 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> */ public SpacecraftState interpolate(final AbsoluteDate date, final Collection<SpacecraftState> sample) throws OrekitException { // prepare interpolators final List<Orbit> orbits = new ArrayList<Orbit>(sample.size()); final List<Attitude> attitudes = new ArrayList<Attitude>(sample.size()); final HermiteInterpolator massInterpolator = new HermiteInterpolator(); final Map<String, HermiteInterpolator> additionalInterpolators = new HashMap<String, HermiteInterpolator>( additional.size()); for (final String name : additional.keySet()) { additionalInterpolators.put(name, new HermiteInterpolator()); } // extract sample data for (final SpacecraftState state : sample) { final double deltaT = state.getDate().durationFrom(date); orbits.add(state.getOrbit()); attitudes.add(state.getAttitude()); massInterpolator.addSamplePoint(deltaT, new double[] { state.getMass() }); for (final Map.Entry<String, HermiteInterpolator> entry : additionalInterpolators.entrySet()) { entry.getValue().addSamplePoint(deltaT, state.getAdditionalState(entry.getKey())); } } // perform interpolations final Orbit interpolatedOrbit = orbit.interpolate(date, orbits); final Attitude interpolatedAttitude = attitude.interpolate(date, attitudes); final double interpolatedMass = massInterpolator.value(0)[0]; final Map<String, double[]> interpolatedAdditional; if (additional.isEmpty()) { interpolatedAdditional = null; } else { interpolatedAdditional = new HashMap<String, double[]>(additional.size()); for (final Map.Entry<String, HermiteInterpolator> entry : additionalInterpolators.entrySet()) { interpolatedAdditional.put(entry.getKey(), entry.getValue().value(0)); } } // create the complete interpolated state return new SpacecraftState(interpolatedOrbit, interpolatedAttitude, interpolatedMass, interpolatedAdditional); }
From source file:org.orekit.utils.TimeStampedPVCoordinates.java
/** Interpolate position-velocity. * <p>//from w ww . jav a2 s. c om * The interpolated instance is created by polynomial Hermite interpolation * ensuring velocity remains the exact derivative of position. * </p> * <p> * Note that even if first time derivatives (velocities) * from sample can be ignored, the interpolated instance always includes * interpolated derivatives. This feature can be used explicitly to * compute these derivatives when it would be too complex to compute them * from an analytical formula: just compute a few sample points from the * explicit formula and set the derivatives to zero in these sample points, * then use interpolation to add derivatives consistent with the positions. * </p> * @param date interpolation date * @param filter filter for derivatives from the sample to use in interpolation * @param sample sample points on which interpolation should be done * @return a new position-velocity, interpolated at specified date */ public static TimeStampedPVCoordinates interpolate(final AbsoluteDate date, final CartesianDerivativesFilter filter, final Collection<TimeStampedPVCoordinates> sample) { // set up an interpolator taking derivatives into account final HermiteInterpolator interpolator = new HermiteInterpolator(); // add sample points switch (filter) { case USE_P: // populate sample with position data, ignoring velocity for (final TimeStampedPVCoordinates pv : sample) { final Vector3D position = pv.getPosition(); interpolator.addSamplePoint(pv.getDate().durationFrom(date), new double[] { position.getX(), position.getY(), position.getZ() }); } break; case USE_PV: // populate sample with position and velocity data for (final TimeStampedPVCoordinates pv : sample) { final Vector3D position = pv.getPosition(); final Vector3D velocity = pv.getVelocity(); interpolator.addSamplePoint(pv.getDate().durationFrom(date), new double[] { position.getX(), position.getY(), position.getZ() }, new double[] { velocity.getX(), velocity.getY(), velocity.getZ() }); } break; case USE_PVA: // populate sample with position, velocity and acceleration data for (final TimeStampedPVCoordinates pv : sample) { final Vector3D position = pv.getPosition(); final Vector3D velocity = pv.getVelocity(); final Vector3D acceleration = pv.getAcceleration(); interpolator.addSamplePoint(pv.getDate().durationFrom(date), new double[] { position.getX(), position.getY(), position.getZ() }, new double[] { velocity.getX(), velocity.getY(), velocity.getZ() }, new double[] { acceleration.getX(), acceleration.getY(), acceleration.getZ() }); } break; default: // this should never happen throw new OrekitInternalError(null); } // interpolate final DerivativeStructure zero = new DerivativeStructure(1, 2, 0, 0.0); final DerivativeStructure[] p = interpolator.value(zero); // build a new interpolated instance return new TimeStampedPVCoordinates(date, new Vector3D(p[0].getValue(), p[1].getValue(), p[2].getValue()), new Vector3D(p[0].getPartialDerivative(1), p[1].getPartialDerivative(1), p[2].getPartialDerivative(1)), new Vector3D(p[0].getPartialDerivative(2), p[1].getPartialDerivative(2), p[2].getPartialDerivative(2))); }