use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.
the class FieldAngularCoordinatesTest method testRandomPVCoordinates.
@Test
public void testRandomPVCoordinates() throws OrekitException {
RandomGenerator generator = new Well1024a(0xf978035a328a565bl);
for (int i = 0; i < 100; ++i) {
FieldRotation<DerivativeStructure> r = randomRotation(generator);
FieldVector3D<DerivativeStructure> omega = randomVector(generator, 10 * generator.nextDouble() + 1.0);
FieldVector3D<DerivativeStructure> omegaDot = randomVector(generator, 0.1 * generator.nextDouble() + 0.01);
FieldAngularCoordinates<DerivativeStructure> ref = new FieldAngularCoordinates<>(r, omega, omegaDot);
FieldAngularCoordinates<DerivativeStructure> inv = ref.revert();
for (int j = 0; j < 100; ++j) {
FieldPVCoordinates<DerivativeStructure> v1 = randomPVCoordinates(generator, 1000, 1.0, 0.001);
FieldPVCoordinates<DerivativeStructure> v2 = randomPVCoordinates(generator, 1000, 1.0, 0.0010);
FieldPVCoordinates<DerivativeStructure> u1 = inv.applyTo(v1);
FieldPVCoordinates<DerivativeStructure> u2 = inv.applyTo(v2);
FieldAngularCoordinates<DerivativeStructure> rebuilt = new FieldAngularCoordinates<>(u1, u2, v1, v2, 1.0e-9);
Assert.assertEquals(0.0, FieldRotation.distance(r, rebuilt.getRotation()).getReal(), 6.0e-14);
Assert.assertEquals(0.0, FieldVector3D.distance(omega, rebuilt.getRotationRate()).getReal(), 3.0e-12 * omega.getNorm().getReal());
Assert.assertEquals(0.0, FieldVector3D.distance(omegaDot, rebuilt.getRotationAcceleration()).getReal(), 2.0e-6 * omegaDot.getNorm().getReal());
}
}
}
use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.
the class PVCoordinatesTest method testMomentumDerivative.
@Test
public void testMomentumDerivative() throws OrekitException {
final PVCoordinates pva = new PVCoordinates(new Vector3D(-4947831., -3765382., -3708221.), new Vector3D(-2079., 5291., -7842.));
final Vector3D p = pva.getPosition();
final Vector3D v = pva.getVelocity();
final Vector3D a = pva.getAcceleration();
final double r2 = p.getNormSq();
final double r = FastMath.sqrt(r2);
final Vector3D keplerianJerk = new Vector3D(-3 * Vector3D.dotProduct(p, v) / r2, a, -a.getNorm() / r, v);
final PVCoordinates velocity = new PVCoordinates(v, a, keplerianJerk);
final Vector3D momentumRef = pva.getMomentum();
final Vector3D momentumDotRef = PVCoordinates.crossProduct(pva, velocity).getVelocity();
final FieldVector3D<DerivativeStructure> momentumDot = pva.toDerivativeStructurePV(1).getMomentum();
Assert.assertEquals(momentumRef.getX(), momentumDot.getX().getReal(), 1.0e-15);
Assert.assertEquals(momentumRef.getY(), momentumDot.getY().getReal(), 1.0e-15);
Assert.assertEquals(momentumRef.getZ(), momentumDot.getZ().getReal(), 1.0e-15);
Assert.assertEquals(momentumDotRef.getX(), momentumDot.getX().getPartialDerivative(1), 1.0e-15);
Assert.assertEquals(momentumDotRef.getY(), momentumDot.getY().getPartialDerivative(1), 1.0e-15);
Assert.assertEquals(momentumDotRef.getZ(), momentumDot.getZ().getPartialDerivative(1), 1.0e-15);
}
use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.
the class PVCoordinatesTest method testToDerivativeStructurePV2.
@Test
public void testToDerivativeStructurePV2() throws OrekitException {
FieldPVCoordinates<DerivativeStructure> fv = new PVCoordinates(new Vector3D(1, 0.1, 10), new Vector3D(-1, -0.1, -10), new Vector3D(10, -1.0, -100)).toDerivativeStructurePV(2);
Assert.assertEquals(1, fv.getPosition().getX().getFreeParameters());
Assert.assertEquals(2, fv.getPosition().getX().getOrder());
Assert.assertEquals(1.0, fv.getPosition().getX().getReal(), 1.0e-10);
Assert.assertEquals(0.1, fv.getPosition().getY().getReal(), 1.0e-10);
Assert.assertEquals(10.0, fv.getPosition().getZ().getReal(), 1.0e-10);
Assert.assertEquals(-1.0, fv.getVelocity().getX().getReal(), 1.0e-10);
Assert.assertEquals(-0.1, fv.getVelocity().getY().getReal(), 1.0e-10);
Assert.assertEquals(-10.0, fv.getVelocity().getZ().getReal(), 1.0e-10);
Assert.assertEquals(10.0, fv.getAcceleration().getX().getReal(), 1.0e-10);
Assert.assertEquals(-1.0, fv.getAcceleration().getY().getReal(), 1.0e-10);
Assert.assertEquals(-100.0, fv.getAcceleration().getZ().getReal(), 1.0e-10);
Assert.assertEquals(fv.getVelocity().getX().getReal(), fv.getPosition().getX().getPartialDerivative(1), 1.0e-10);
Assert.assertEquals(fv.getVelocity().getY().getReal(), fv.getPosition().getY().getPartialDerivative(1), 1.0e-10);
Assert.assertEquals(fv.getVelocity().getZ().getReal(), fv.getPosition().getZ().getPartialDerivative(1), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getX().getReal(), fv.getPosition().getX().getPartialDerivative(2), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getY().getReal(), fv.getPosition().getY().getPartialDerivative(2), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getZ().getReal(), fv.getPosition().getZ().getPartialDerivative(2), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getX().getReal(), fv.getVelocity().getX().getPartialDerivative(1), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getY().getReal(), fv.getVelocity().getY().getPartialDerivative(1), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getZ().getReal(), fv.getVelocity().getZ().getPartialDerivative(1), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getX().getPartialDerivative(1), fv.getVelocity().getX().getPartialDerivative(2), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getY().getPartialDerivative(1), fv.getVelocity().getY().getPartialDerivative(2), 1.0e-10);
Assert.assertEquals(fv.getAcceleration().getZ().getPartialDerivative(1), fv.getVelocity().getZ().getPartialDerivative(2), 1.0e-10);
for (double dt = 0; dt < 10; dt += 0.125) {
Vector3D p = new PVCoordinates(new Vector3D(1, 0.1, 10), new Vector3D(-1, -0.1, -10), new Vector3D(10, -1.0, -100)).shiftedBy(dt).getPosition();
Assert.assertEquals(p.getX(), fv.getPosition().getX().taylor(dt), 1.0e-14);
Assert.assertEquals(p.getY(), fv.getPosition().getY().taylor(dt), 1.0e-14);
Assert.assertEquals(p.getZ(), fv.getPosition().getZ().taylor(dt), 1.0e-14);
}
}
use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.
the class PVCoordinatesTest method testNormalize.
@Test
public void testNormalize() {
DSFactory factory = new DSFactory(1, 2);
RandomGenerator generator = new Well19937a(0xb2011ffd25412067l);
FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 1.0e-3);
for (int i = 0; i < 200; ++i) {
final PVCoordinates pv = randomPVCoordinates(generator, 1e6, 1e3, 1.0);
DerivativeStructure x = differentiator.differentiate(new UnivariateFunction() {
public double value(double t) {
return pv.shiftedBy(t).getPosition().normalize().getX();
}
}).value(factory.variable(0, 0.0));
DerivativeStructure y = differentiator.differentiate(new UnivariateFunction() {
public double value(double t) {
return pv.shiftedBy(t).getPosition().normalize().getY();
}
}).value(factory.variable(0, 0.0));
DerivativeStructure z = differentiator.differentiate(new UnivariateFunction() {
public double value(double t) {
return pv.shiftedBy(t).getPosition().normalize().getZ();
}
}).value(factory.variable(0, 0.0));
PVCoordinates normalized = pv.normalize();
Assert.assertEquals(x.getValue(), normalized.getPosition().getX(), 1.0e-16);
Assert.assertEquals(y.getValue(), normalized.getPosition().getY(), 1.0e-16);
Assert.assertEquals(z.getValue(), normalized.getPosition().getZ(), 1.0e-16);
Assert.assertEquals(x.getPartialDerivative(1), normalized.getVelocity().getX(), 3.0e-13);
Assert.assertEquals(y.getPartialDerivative(1), normalized.getVelocity().getY(), 3.0e-13);
Assert.assertEquals(z.getPartialDerivative(1), normalized.getVelocity().getZ(), 3.0e-13);
Assert.assertEquals(x.getPartialDerivative(2), normalized.getAcceleration().getX(), 6.0e-10);
Assert.assertEquals(y.getPartialDerivative(2), normalized.getAcceleration().getY(), 6.0e-10);
Assert.assertEquals(z.getPartialDerivative(2), normalized.getAcceleration().getZ(), 6.0e-10);
}
}
use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.
the class PVCoordinatesTest method testToDerivativeStructureVector2.
@Test
public void testToDerivativeStructureVector2() throws OrekitException {
FieldVector3D<DerivativeStructure> fv = new PVCoordinates(new Vector3D(1, 0.1, 10), new Vector3D(-1, -0.1, -10), new Vector3D(10, -1.0, -100)).toDerivativeStructureVector(2);
Assert.assertEquals(1, fv.getX().getFreeParameters());
Assert.assertEquals(2, fv.getX().getOrder());
Assert.assertEquals(1.0, fv.getX().getReal(), 1.0e-10);
Assert.assertEquals(0.1, fv.getY().getReal(), 1.0e-10);
Assert.assertEquals(10.0, fv.getZ().getReal(), 1.0e-10);
Assert.assertEquals(-1.0, fv.getX().getPartialDerivative(1), 1.0e-15);
Assert.assertEquals(-0.1, fv.getY().getPartialDerivative(1), 1.0e-15);
Assert.assertEquals(-10.0, fv.getZ().getPartialDerivative(1), 1.0e-15);
Assert.assertEquals(10.0, fv.getX().getPartialDerivative(2), 1.0e-15);
Assert.assertEquals(-1.0, fv.getY().getPartialDerivative(2), 1.0e-15);
Assert.assertEquals(-100.0, fv.getZ().getPartialDerivative(2), 1.0e-15);
checkPV(new PVCoordinates(new Vector3D(1, 0.1, 10), new Vector3D(-1, -0.1, -10), new Vector3D(10, -1.0, -100)), new PVCoordinates(fv), 1.0e-15);
for (double dt = 0; dt < 10; dt += 0.125) {
Vector3D p = new PVCoordinates(new Vector3D(1, 0.1, 10), new Vector3D(-1, -0.1, -10), new Vector3D(10, -1.0, -100)).shiftedBy(dt).getPosition();
Assert.assertEquals(p.getX(), fv.getX().taylor(dt), 1.0e-14);
Assert.assertEquals(p.getY(), fv.getY().taylor(dt), 1.0e-14);
Assert.assertEquals(p.getZ(), fv.getZ().taylor(dt), 1.0e-14);
}
}
Aggregations