List of usage examples for org.apache.commons.math3.analysis.polynomials PolynomialFunction polynomialDerivative
public PolynomialFunction polynomialDerivative()
From source file:jurbano.melodyshape.comparison.bspline.BSplinePitchNGramComparer.java
/** * {@inheritDoc}/*from w ww . ja v a 2 s . c o m*/ * * @return 0 if both {@link NGram}s are equivalent or the area between the * first derivatives of their corresponding Uniform B-Splines. */ @Override public double compare(NGram g1, NGram g2) { if (g1 == null) g1 = g2.getNullSpan(); if (g2 == null) g2 = g1.getNullSpan(); if (g1.size() < 2 || g1.size() > UniformBSpline.BASIS_FUNCTIONS.length) throw new IllegalArgumentException(this.getName() + " only supports n-grams with 2 to " + UniformBSpline.BASIS_FUNCTIONS.length + " notes."); if (this.getNGramId(g1).equals(this.getNGramId(g2))) return 0; PolynomialFunction p1p = new PolynomialFunction(new double[] { 0 }); PolynomialFunction p2p = new PolynomialFunction(new double[] { 0 }); for (int i = 1; i < g1.size(); i++) { PolynomialFunction basis = UniformBSpline.BASIS_FUNCTIONS[g1.size() - 1][i - 1]; p1p = p1p.add(basis.multiply(new PolynomialFunction( new double[] { g1.get(g1.size() - i).getPitch() - g1.get(0).getPitch() }))); p2p = p2p.add(basis.multiply(new PolynomialFunction( new double[] { g2.get(g2.size() - i).getPitch() - g2.get(0).getPitch() }))); } PolynomialFunction pp = p1p.polynomialDerivative().subtract(p2p.polynomialDerivative()); Laguerre laguerre = new Laguerre(); ArrayList<Double> realRoots = laguerre.findRoots(pp); return -laguerre.computeAreaBetweenDerivatives(p1p, p2p, realRoots); }
From source file:jurbano.melodyshape.comparison.bspline.BSplineTimeNGramComparer.java
/** * {@inheritDoc}/*from ww w . j a v a2 s .co m*/ * * @return 0 if both {@link NGram}s are equivalent or the area between the * first derivatives of their corresponding Uniform B-Splines. */ @Override public double compare(NGram g1, NGram g2) { if (g1 == null) g1 = g2.getNullSpan(); if (g2 == null) g2 = g1.getNullSpan(); if (g1.size() < 2 || g1.size() > UniformBSpline.BASIS_FUNCTIONS.length) throw new IllegalArgumentException(this.getName() + " only supports n-grams with 2 to " + UniformBSpline.BASIS_FUNCTIONS.length + " notes."); if (this.getNGramId(g1).equals(this.getNGramId(g2))) return 0; PolynomialFunction p1t = new PolynomialFunction(new double[] { 0 }); PolynomialFunction p2t = new PolynomialFunction(new double[] { 0 }); for (int i = 0; i < g1.size(); i++) { PolynomialFunction basis = UniformBSpline.BASIS_FUNCTIONS[g1.size() - 1][i]; p1t = p1t.add(basis.multiply(new PolynomialFunction( new double[] { g1.get(g1.size() - i - 1).getDuration() / (double) g1.get(0).getDuration() }))); p2t = p2t.add(basis.multiply(new PolynomialFunction( new double[] { g2.get(g2.size() - i - 1).getDuration() / (double) g2.get(0).getDuration() }))); } PolynomialFunction pt = p1t.polynomialDerivative().subtract(p2t.polynomialDerivative()); Laguerre laguerre = new Laguerre(); ArrayList<Double> realRoots = laguerre.findRoots(pt); return -laguerre.computeAreaBetweenDerivatives(p1t, p2t, realRoots); }
From source file:jurbano.melodyshape.comparison.bspline.BSplineShapeNGramComparer.java
/** * {@inheritDoc}/* w w w .ja va 2 s . c om*/ */ @Override public double compare(NGram g1, NGram g2) { if (g1 == null) g1 = g2.getNullSpan(); if (g2 == null) g2 = g1.getNullSpan(); if (g1.size() != 3) throw new IllegalArgumentException(this.getName() + " only supports n-grams with 3 notes."); if (this.getNGramId(g1).equals(this.getNGramId(g2))) return 0; PolynomialFunction p1 = new PolynomialFunction(new double[] { 0 }); PolynomialFunction p2 = new PolynomialFunction(new double[] { 0 }); for (int i = 1; i < g1.size(); i++) { PolynomialFunction basis = UniformBSpline.BASIS_FUNCTIONS[g1.size() - 1][i - 1]; p1 = p1.add(basis.multiply(new PolynomialFunction( new double[] { g1.get(g1.size() - i).getPitch() - g1.get(0).getPitch() }))); p2 = p2.add(basis.multiply(new PolynomialFunction( new double[] { g2.get(g2.size() - i).getPitch() - g2.get(0).getPitch() }))); } PolynomialFunction p1_ = p1.polynomialDerivative(); PolynomialFunction p2_ = p2.polynomialDerivative(); /* double p1_0 = Math.signum(p1_.value(0)); double p1_1 = Math.signum(p1_.value(1)); double p2_0 = Math.signum(p2_.value(0)); double p2_1 = Math.signum(p2_.value(1)); if(p1_0 == p2_0){ // same at 0 if(p1_1 == p2_1) // same at 1 return -this.dMin; else if(p1_1*p2_1<0) // opposite at 1 return -this.dMed; else // some flat at 1 return -this.dMed; }else if(p1_0*p2_0 < 0) { // opposite at 0 if(p1_1 == p2_1) // same at 1 return -this.dMed; else if(p1_1*p2_1<0) // opposite at 1 return -this.dMax; else // some flat at 1 return -this.dMax; }else { // some flat at 0 if(p1_1 == p2_1) // same at 1 return -this.dMed; else if(p1_1*p2_1<0) // opposite at 1 return -this.dMax; else // some flat at 1 return -this.dMax; }*/ double p1_0 = p1_.value(0); double p1_1 = p1_.value(1); double p2_0 = p2_.value(0); double p2_1 = p2_.value(1); // TODO: this similarity function is not symmetric if (p1_0 <= 0 && p1_1 >= 0) { // p1 is \/ if (p2_0 <= 0 && p2_1 >= 0) // p2 is \/ return -this.dMin; else if (p2_0 >= 0 && p2_1 <= 0) // p2 is /\ return -this.dMax; else return -this.dMed; } if (p1_0 >= 0 && p1_1 <= 0) { // p1 is /\ if (p2_0 >= 0 && p2_1 <= 0) // p2 is /\ return -this.dMin; else if (p2_0 <= 0 && p2_1 >= 0) // p2 is \/ return -this.dMax; else return -this.dMed; } if (p1_0 >= 0 && p1_1 >= 0) { // p1 is / if (p2_0 >= 0 && p2_1 >= 0) // p2 is / return -this.dMin; else if (p2_0 <= 0 && p2_1 <= 0) // p2 is \ return -this.dMax; else return -this.dMed; } if (p1_0 <= 0 && p1_1 <= 0) { // p1 is \ if (p2_0 <= 0 && p2_1 <= 0) // p2 is \ return -this.dMin; else if (p2_0 >= 0 && p2_1 >= 0) // p2 is / return -this.dMax; else return -this.dMed; } return -this.dMin; }
From source file:org.orekit.utils.FieldPVCoordinatesTest.java
@Test @Deprecated // to be removed when FieldPVCoordinates.interpolate is removed public void testInterpolatePolynomialPV() { Random random = new Random(0xae7771c9933407bdl); AbsoluteDate t0 = AbsoluteDate.J2000_EPOCH; for (int i = 0; i < 20; ++i) { PolynomialFunction px = randomPolynomial(5, random); PolynomialFunction py = randomPolynomial(5, random); PolynomialFunction pz = randomPolynomial(5, random); PolynomialFunction pxDot = px.polynomialDerivative(); PolynomialFunction pyDot = py.polynomialDerivative(); PolynomialFunction pzDot = pz.polynomialDerivative(); List<Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>> sample = new ArrayList<Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>>(); for (double dt : new double[] { 0.0, 0.5, 1.0 }) { FieldVector3D<DerivativeStructure> position = new FieldVector3D<DerivativeStructure>( new DerivativeStructure(3, 1, 0, px.value(dt)), new DerivativeStructure(3, 1, 1, py.value(dt)), new DerivativeStructure(3, 1, 2, pz.value(dt))); FieldVector3D<DerivativeStructure> velocity = new FieldVector3D<DerivativeStructure>( new DerivativeStructure(3, 1, pxDot.value(dt)), new DerivativeStructure(3, 1, pyDot.value(dt)), new DerivativeStructure(3, 1, pzDot.value(dt))); sample.add(new Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>(t0.shiftedBy(dt), new FieldPVCoordinates<DerivativeStructure>(position, velocity))); }//from www .j a v a 2 s .c om for (double dt = 0; dt < 1.0; dt += 0.01) { FieldPVCoordinates<DerivativeStructure> interpolated = FieldPVCoordinates .interpolate(t0.shiftedBy(dt), true, sample); FieldVector3D<DerivativeStructure> p = interpolated.getPosition(); FieldVector3D<DerivativeStructure> v = interpolated.getVelocity(); Assert.assertEquals(px.value(dt), p.getX().getValue(), 1.0e-15 * p.getNorm().getValue()); Assert.assertEquals(1, p.getX().getPartialDerivative(1, 0, 0), 1.0e-15); Assert.assertEquals(0, p.getX().getPartialDerivative(0, 1, 0), 1.0e-15); Assert.assertEquals(0, p.getX().getPartialDerivative(0, 0, 1), 1.0e-15); Assert.assertEquals(py.value(dt), p.getY().getValue(), 1.0e-15 * p.getNorm().getValue()); Assert.assertEquals(0, p.getY().getPartialDerivative(1, 0, 0), 1.0e-15); Assert.assertEquals(1, p.getY().getPartialDerivative(0, 1, 0), 1.0e-15); Assert.assertEquals(0, p.getY().getPartialDerivative(0, 0, 1), 1.0e-15); Assert.assertEquals(pz.value(dt), p.getZ().getValue(), 1.0e-15 * p.getNorm().getValue()); Assert.assertEquals(0, p.getZ().getPartialDerivative(1, 0, 0), 1.0e-15); Assert.assertEquals(0, p.getZ().getPartialDerivative(0, 1, 0), 1.0e-15); Assert.assertEquals(1, p.getZ().getPartialDerivative(0, 0, 1), 1.0e-15); Assert.assertEquals(pxDot.value(dt), v.getX().getValue(), 1.0e-15 * v.getNorm().getValue()); Assert.assertEquals(pyDot.value(dt), v.getY().getValue(), 1.0e-15 * v.getNorm().getValue()); Assert.assertEquals(pzDot.value(dt), v.getZ().getValue(), 1.0e-15 * v.getNorm().getValue()); } } }
From source file:org.orekit.utils.PVCoordinatesDSTest.java
@Test public void testInterpolatePolynomialPV() { Random random = new Random(0xae7771c9933407bdl); AbsoluteDate t0 = AbsoluteDate.J2000_EPOCH; for (int i = 0; i < 20; ++i) { PolynomialFunction px = randomPolynomial(5, random); PolynomialFunction py = randomPolynomial(5, random); PolynomialFunction pz = randomPolynomial(5, random); PolynomialFunction pxDot = px.polynomialDerivative(); PolynomialFunction pyDot = py.polynomialDerivative(); PolynomialFunction pzDot = pz.polynomialDerivative(); List<Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>> sample = new ArrayList<Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>>(); for (double dt : new double[] { 0.0, 0.5, 1.0 }) { FieldVector3D<DerivativeStructure> position = new FieldVector3D<DerivativeStructure>( new DerivativeStructure(3, 1, 0, px.value(dt)), new DerivativeStructure(3, 1, 1, py.value(dt)), new DerivativeStructure(3, 1, 2, pz.value(dt))); FieldVector3D<DerivativeStructure> velocity = new FieldVector3D<DerivativeStructure>( new DerivativeStructure(3, 1, pxDot.value(dt)), new DerivativeStructure(3, 1, pyDot.value(dt)), new DerivativeStructure(3, 1, pzDot.value(dt))); sample.add(new Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>(t0.shiftedBy(dt), new FieldPVCoordinates<DerivativeStructure>(position, velocity))); }/*from w ww. j a va2s . c o m*/ for (double dt = 0; dt < 1.0; dt += 0.01) { FieldPVCoordinates<DerivativeStructure> interpolated = FieldPVCoordinates .interpolate(t0.shiftedBy(dt), true, sample); FieldVector3D<DerivativeStructure> p = interpolated.getPosition(); FieldVector3D<DerivativeStructure> v = interpolated.getVelocity(); Assert.assertEquals(px.value(dt), p.getX().getValue(), 1.0e-15 * p.getNorm().getValue()); Assert.assertEquals(1, p.getX().getPartialDerivative(1, 0, 0), 1.0e-15); Assert.assertEquals(0, p.getX().getPartialDerivative(0, 1, 0), 1.0e-15); Assert.assertEquals(0, p.getX().getPartialDerivative(0, 0, 1), 1.0e-15); Assert.assertEquals(py.value(dt), p.getY().getValue(), 1.0e-15 * p.getNorm().getValue()); Assert.assertEquals(0, p.getY().getPartialDerivative(1, 0, 0), 1.0e-15); Assert.assertEquals(1, p.getY().getPartialDerivative(0, 1, 0), 1.0e-15); Assert.assertEquals(0, p.getY().getPartialDerivative(0, 0, 1), 1.0e-15); Assert.assertEquals(pz.value(dt), p.getZ().getValue(), 1.0e-15 * p.getNorm().getValue()); Assert.assertEquals(0, p.getZ().getPartialDerivative(1, 0, 0), 1.0e-15); Assert.assertEquals(0, p.getZ().getPartialDerivative(0, 1, 0), 1.0e-15); Assert.assertEquals(1, p.getZ().getPartialDerivative(0, 0, 1), 1.0e-15); Assert.assertEquals(pxDot.value(dt), v.getX().getValue(), 1.0e-15 * v.getNorm().getValue()); Assert.assertEquals(pyDot.value(dt), v.getY().getValue(), 1.0e-15 * v.getNorm().getValue()); Assert.assertEquals(pzDot.value(dt), v.getZ().getValue(), 1.0e-15 * v.getNorm().getValue()); } } }
From source file:org.orekit.utils.PVCoordinatesDSTest.java
@Test public void testInterpolatePolynomialPositionOnly() { Random random = new Random(0x88740a12e4299003l); AbsoluteDate t0 = AbsoluteDate.J2000_EPOCH; for (int i = 0; i < 20; ++i) { PolynomialFunction px = randomPolynomial(5, random); PolynomialFunction py = randomPolynomial(5, random); PolynomialFunction pz = randomPolynomial(5, random); PolynomialFunction pxDot = px.polynomialDerivative(); PolynomialFunction pyDot = py.polynomialDerivative(); PolynomialFunction pzDot = pz.polynomialDerivative(); List<Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>> sample = new ArrayList<Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>>(); for (double dt : new double[] { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 }) { FieldVector3D<DerivativeStructure> position = createVector(px.value(dt), py.value(dt), pz.value(dt), 6);//w w w .j a va 2s . co m sample.add(new Pair<AbsoluteDate, FieldPVCoordinates<DerivativeStructure>>(t0.shiftedBy(dt), new FieldPVCoordinates<DerivativeStructure>(position, createVector(0, 0, 0, 6)))); } for (double dt = 0; dt < 1.0; dt += 0.01) { FieldPVCoordinates<DerivativeStructure> interpolated = FieldPVCoordinates .interpolate(t0.shiftedBy(dt), false, sample); FieldVector3D<DerivativeStructure> p = interpolated.getPosition(); FieldVector3D<DerivativeStructure> v = interpolated.getVelocity(); Assert.assertEquals(px.value(dt), p.getX().getValue(), 1.0e-14 * p.getNorm().getValue()); Assert.assertEquals(py.value(dt), p.getY().getValue(), 1.0e-14 * p.getNorm().getValue()); Assert.assertEquals(pz.value(dt), p.getZ().getValue(), 1.0e-14 * p.getNorm().getValue()); Assert.assertEquals(pxDot.value(dt), v.getX().getValue(), 1.0e-14 * v.getNorm().getValue()); Assert.assertEquals(pyDot.value(dt), v.getY().getValue(), 1.0e-14 * v.getNorm().getValue()); Assert.assertEquals(pzDot.value(dt), v.getZ().getValue(), 1.0e-14 * v.getNorm().getValue()); } } }
From source file:org.orekit.utils.PVCoordinatesTest.java
@Test @Deprecated // to be removed when PVCoordinates.interpolate is removed public void testInterpolatePolynomialPV() { Random random = new Random(0xae7771c9933407bdl); AbsoluteDate t0 = AbsoluteDate.J2000_EPOCH; for (int i = 0; i < 20; ++i) { PolynomialFunction px = randomPolynomial(5, random); PolynomialFunction py = randomPolynomial(5, random); PolynomialFunction pz = randomPolynomial(5, random); PolynomialFunction pxDot = px.polynomialDerivative(); PolynomialFunction pyDot = py.polynomialDerivative(); PolynomialFunction pzDot = pz.polynomialDerivative(); PolynomialFunction pxDotDot = pxDot.polynomialDerivative(); PolynomialFunction pyDotDot = pyDot.polynomialDerivative(); PolynomialFunction pzDotDot = pzDot.polynomialDerivative(); List<Pair<AbsoluteDate, PVCoordinates>> sample = new ArrayList<Pair<AbsoluteDate, PVCoordinates>>(); for (double dt : new double[] { 0.0, 0.5, 1.0 }) { Vector3D position = new Vector3D(px.value(dt), py.value(dt), pz.value(dt)); Vector3D velocity = new Vector3D(pxDot.value(dt), pyDot.value(dt), pzDot.value(dt)); sample.add(new Pair<AbsoluteDate, PVCoordinates>(t0.shiftedBy(dt), new PVCoordinates(position, velocity, Vector3D.ZERO))); }//from ww w . j av a 2 s .c o m for (double dt = 0; dt < 1.0; dt += 0.01) { PVCoordinates interpolated = PVCoordinates.interpolate(t0.shiftedBy(dt), true, sample); Vector3D p = interpolated.getPosition(); Vector3D v = interpolated.getVelocity(); Vector3D a = interpolated.getAcceleration(); Assert.assertEquals(px.value(dt), p.getX(), 1.0e-15 * p.getNorm()); Assert.assertEquals(py.value(dt), p.getY(), 1.0e-15 * p.getNorm()); Assert.assertEquals(pz.value(dt), p.getZ(), 1.0e-15 * p.getNorm()); Assert.assertEquals(pxDot.value(dt), v.getX(), 1.0e-15 * v.getNorm()); Assert.assertEquals(pyDot.value(dt), v.getY(), 1.0e-15 * v.getNorm()); Assert.assertEquals(pzDot.value(dt), v.getZ(), 1.0e-15 * v.getNorm()); Assert.assertEquals(pxDotDot.value(dt), a.getX(), 1.0e-14 * a.getNorm()); Assert.assertEquals(pyDotDot.value(dt), a.getY(), 1.0e-14 * a.getNorm()); Assert.assertEquals(pzDotDot.value(dt), a.getZ(), 1.0e-14 * a.getNorm()); } } }
From source file:org.orekit.utils.TimeStampedFieldPVCoordinatesTest.java
@Test public void testInterpolatePolynomialPVA() { Random random = new Random(0xfe3945fcb8bf47cel); AbsoluteDate t0 = AbsoluteDate.J2000_EPOCH; for (int i = 0; i < 20; ++i) { PolynomialFunction px = randomPolynomial(5, random); PolynomialFunction py = randomPolynomial(5, random); PolynomialFunction pz = randomPolynomial(5, random); PolynomialFunction pxDot = px.polynomialDerivative(); PolynomialFunction pyDot = py.polynomialDerivative(); PolynomialFunction pzDot = pz.polynomialDerivative(); PolynomialFunction pxDotDot = pxDot.polynomialDerivative(); PolynomialFunction pyDotDot = pyDot.polynomialDerivative(); PolynomialFunction pzDotDot = pzDot.polynomialDerivative(); List<TimeStampedFieldPVCoordinates<DerivativeStructure>> sample = new ArrayList<TimeStampedFieldPVCoordinates<DerivativeStructure>>(); for (double dt : new double[] { 0.0, 0.5, 1.0 }) { FieldVector3D<DerivativeStructure> position = createVector(px.value(dt), py.value(dt), pz.value(dt), 4);// w w w . ja v a 2 s .c o m FieldVector3D<DerivativeStructure> velocity = createVector(pxDot.value(dt), pyDot.value(dt), pzDot.value(dt), 4); FieldVector3D<DerivativeStructure> acceleration = createVector(pxDotDot.value(dt), pyDotDot.value(dt), pzDotDot.value(dt), 4); sample.add(new TimeStampedFieldPVCoordinates<DerivativeStructure>(t0.shiftedBy(dt), position, velocity, acceleration)); } for (double dt = 0; dt < 1.0; dt += 0.01) { TimeStampedFieldPVCoordinates<DerivativeStructure> interpolated = TimeStampedFieldPVCoordinates .interpolate(t0.shiftedBy(dt), CartesianDerivativesFilter.USE_PVA, sample); FieldVector3D<DerivativeStructure> p = interpolated.getPosition(); FieldVector3D<DerivativeStructure> v = interpolated.getVelocity(); FieldVector3D<DerivativeStructure> a = interpolated.getAcceleration(); Assert.assertEquals(px.value(dt), p.getX().getReal(), 4.0e-16 * p.getNorm().getReal()); Assert.assertEquals(py.value(dt), p.getY().getReal(), 4.0e-16 * p.getNorm().getReal()); Assert.assertEquals(pz.value(dt), p.getZ().getReal(), 4.0e-16 * p.getNorm().getReal()); Assert.assertEquals(pxDot.value(dt), v.getX().getReal(), 9.0e-16 * v.getNorm().getReal()); Assert.assertEquals(pyDot.value(dt), v.getY().getReal(), 9.0e-16 * v.getNorm().getReal()); Assert.assertEquals(pzDot.value(dt), v.getZ().getReal(), 9.0e-16 * v.getNorm().getReal()); Assert.assertEquals(pxDotDot.value(dt), a.getX().getReal(), 6.0e-15 * a.getNorm().getReal()); Assert.assertEquals(pyDotDot.value(dt), a.getY().getReal(), 6.0e-15 * a.getNorm().getReal()); Assert.assertEquals(pzDotDot.value(dt), a.getZ().getReal(), 6.0e-15 * a.getNorm().getReal()); } } }
From source file:org.orekit.utils.TimeStampedFieldPVCoordinatesTest.java
@Test public void testInterpolatePolynomialPV() { Random random = new Random(0xae7771c9933407bdl); AbsoluteDate t0 = AbsoluteDate.J2000_EPOCH; for (int i = 0; i < 20; ++i) { PolynomialFunction px = randomPolynomial(5, random); PolynomialFunction py = randomPolynomial(5, random); PolynomialFunction pz = randomPolynomial(5, random); PolynomialFunction pxDot = px.polynomialDerivative(); PolynomialFunction pyDot = py.polynomialDerivative(); PolynomialFunction pzDot = pz.polynomialDerivative(); PolynomialFunction pxDotDot = pxDot.polynomialDerivative(); PolynomialFunction pyDotDot = pyDot.polynomialDerivative(); PolynomialFunction pzDotDot = pzDot.polynomialDerivative(); List<TimeStampedFieldPVCoordinates<DerivativeStructure>> sample = new ArrayList<TimeStampedFieldPVCoordinates<DerivativeStructure>>(); for (double dt : new double[] { 0.0, 0.5, 1.0 }) { FieldVector3D<DerivativeStructure> position = createVector(px.value(dt), py.value(dt), pz.value(dt), 4);/*from www . j a va2 s . c om*/ FieldVector3D<DerivativeStructure> velocity = createVector(pxDot.value(dt), pyDot.value(dt), pzDot.value(dt), 4); sample.add(new TimeStampedFieldPVCoordinates<DerivativeStructure>(t0.shiftedBy(dt), position, velocity, createVector(0, 0, 0, 4))); } for (double dt = 0; dt < 1.0; dt += 0.01) { TimeStampedFieldPVCoordinates<DerivativeStructure> interpolated = TimeStampedFieldPVCoordinates .interpolate(t0.shiftedBy(dt), CartesianDerivativesFilter.USE_PV, sample); FieldVector3D<DerivativeStructure> p = interpolated.getPosition(); FieldVector3D<DerivativeStructure> v = interpolated.getVelocity(); FieldVector3D<DerivativeStructure> a = interpolated.getAcceleration(); Assert.assertEquals(px.value(dt), p.getX().getReal(), 4.0e-16 * p.getNorm().getReal()); Assert.assertEquals(py.value(dt), p.getY().getReal(), 4.0e-16 * p.getNorm().getReal()); Assert.assertEquals(pz.value(dt), p.getZ().getReal(), 4.0e-16 * p.getNorm().getReal()); Assert.assertEquals(pxDot.value(dt), v.getX().getReal(), 9.0e-16 * v.getNorm().getReal()); Assert.assertEquals(pyDot.value(dt), v.getY().getReal(), 9.0e-16 * v.getNorm().getReal()); Assert.assertEquals(pzDot.value(dt), v.getZ().getReal(), 9.0e-16 * v.getNorm().getReal()); Assert.assertEquals(pxDotDot.value(dt), a.getX().getReal(), 1.0e-14 * a.getNorm().getReal()); Assert.assertEquals(pyDotDot.value(dt), a.getY().getReal(), 1.0e-14 * a.getNorm().getReal()); Assert.assertEquals(pzDotDot.value(dt), a.getZ().getReal(), 1.0e-14 * a.getNorm().getReal()); } } }
From source file:org.orekit.utils.TimeStampedFieldPVCoordinatesTest.java
@Test public void testInterpolatePolynomialPositionOnly() { Random random = new Random(0x88740a12e4299003l); AbsoluteDate t0 = AbsoluteDate.J2000_EPOCH; for (int i = 0; i < 20; ++i) { PolynomialFunction px = randomPolynomial(5, random); PolynomialFunction py = randomPolynomial(5, random); PolynomialFunction pz = randomPolynomial(5, random); PolynomialFunction pxDot = px.polynomialDerivative(); PolynomialFunction pyDot = py.polynomialDerivative(); PolynomialFunction pzDot = pz.polynomialDerivative(); PolynomialFunction pxDotDot = pxDot.polynomialDerivative(); PolynomialFunction pyDotDot = pyDot.polynomialDerivative(); PolynomialFunction pzDotDot = pzDot.polynomialDerivative(); List<TimeStampedFieldPVCoordinates<DerivativeStructure>> sample = new ArrayList<TimeStampedFieldPVCoordinates<DerivativeStructure>>(); for (double dt : new double[] { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 }) { FieldVector3D<DerivativeStructure> position = createVector(px.value(dt), py.value(dt), pz.value(dt), 4);//from w w w.j a va2 s . co m sample.add(new TimeStampedFieldPVCoordinates<DerivativeStructure>(t0.shiftedBy(dt), position, createVector(0, 0, 0, 4), createVector(0, 0, 0, 4))); } for (double dt = 0; dt < 1.0; dt += 0.01) { TimeStampedFieldPVCoordinates<DerivativeStructure> interpolated = TimeStampedFieldPVCoordinates .interpolate(t0.shiftedBy(dt), CartesianDerivativesFilter.USE_P, sample); FieldVector3D<DerivativeStructure> p = interpolated.getPosition(); FieldVector3D<DerivativeStructure> v = interpolated.getVelocity(); FieldVector3D<DerivativeStructure> a = interpolated.getAcceleration(); Assert.assertEquals(px.value(dt), p.getX().getReal(), 5.0e-16 * p.getNorm().getReal()); Assert.assertEquals(py.value(dt), p.getY().getReal(), 5.0e-16 * p.getNorm().getReal()); Assert.assertEquals(pz.value(dt), p.getZ().getReal(), 5.0e-16 * p.getNorm().getReal()); Assert.assertEquals(pxDot.value(dt), v.getX().getReal(), 7.0e-15 * v.getNorm().getReal()); Assert.assertEquals(pyDot.value(dt), v.getY().getReal(), 7.0e-15 * v.getNorm().getReal()); Assert.assertEquals(pzDot.value(dt), v.getZ().getReal(), 7.0e-15 * v.getNorm().getReal()); Assert.assertEquals(pxDotDot.value(dt), a.getX().getReal(), 2.0e-13 * a.getNorm().getReal()); Assert.assertEquals(pyDotDot.value(dt), a.getY().getReal(), 2.0e-13 * a.getNorm().getReal()); Assert.assertEquals(pzDotDot.value(dt), a.getZ().getReal(), 2.0e-13 * a.getNorm().getReal()); } } }