Search in sources :

Example 21 with DerivativeStructure

use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.

the class FieldAngularCoordinatesTest method testRodriguesSpecialCases.

@Test
public void testRodriguesSpecialCases() {
    // identity
    DerivativeStructure[][] identity = FieldAngularCoordinates.getIdentity(new DSFactory(2, 2).getDerivativeField()).getModifiedRodrigues(1.0);
    for (DerivativeStructure[] row : identity) {
        for (DerivativeStructure element : row) {
            Assert.assertEquals(0.0, element.getReal(), Precision.SAFE_MIN);
        }
    }
    FieldAngularCoordinates<DerivativeStructure> acId = FieldAngularCoordinates.createFromModifiedRodrigues(identity);
    Assert.assertEquals(0.0, acId.getRotation().getAngle().getReal(), Precision.SAFE_MIN);
    Assert.assertEquals(0.0, acId.getRotationRate().getNorm().getReal(), Precision.SAFE_MIN);
    // PI angle rotation (which is singular for non-modified Rodrigues vector)
    RandomGenerator random = new Well1024a(0x4923ec495bca9fb4l);
    for (int i = 0; i < 100; ++i) {
        FieldVector3D<DerivativeStructure> axis = randomVector(random, 1.0);
        final Field<DerivativeStructure> field = axis.getX().getField();
        FieldAngularCoordinates<DerivativeStructure> original = new FieldAngularCoordinates<>(new FieldRotation<>(axis, field.getZero().add(FastMath.PI), RotationConvention.VECTOR_OPERATOR), FieldVector3D.getZero(field), FieldVector3D.getZero(field));
        FieldAngularCoordinates<DerivativeStructure> rebuilt = FieldAngularCoordinates.createFromModifiedRodrigues(original.getModifiedRodrigues(1.0));
        Assert.assertEquals(FastMath.PI, rebuilt.getRotation().getAngle().getReal(), 1.0e-15);
        Assert.assertEquals(0.0, FieldVector3D.angle(axis, rebuilt.getRotation().getAxis(RotationConvention.VECTOR_OPERATOR)).sin().getReal(), 1.0e-15);
        Assert.assertEquals(0.0, rebuilt.getRotationRate().getNorm().getReal(), 1.0e-16);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Example 22 with DerivativeStructure

use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.

the class FieldAngularCoordinatesTest method testToAC.

@Test
public void testToAC() {
    RandomGenerator random = new Well1024a(0xc9b4cf6c371108e0l);
    for (int i = 0; i < 100; ++i) {
        FieldRotation<DerivativeStructure> r = randomRotation(random);
        FieldVector3D<DerivativeStructure> o = randomVector(random, 1.0e-3);
        FieldVector3D<DerivativeStructure> a = randomVector(random, 1.0e-3);
        FieldAngularCoordinates<DerivativeStructure> acds = new FieldAngularCoordinates<>(r, o, a);
        AngularCoordinates ac = acds.toAngularCoordinates();
        Assert.assertEquals(0, Rotation.distance(r.toRotation(), ac.getRotation()), 1.0e-15);
        Assert.assertEquals(0, FieldVector3D.distance(o, ac.getRotationRate()).getReal(), 1.0e-15);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Example 23 with DerivativeStructure

use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.

the class FieldAngularCoordinatesTest method testApplyTo.

@Test
public void testApplyTo() {
    RandomGenerator random = new Well1024a(0xbad5894f4c475905l);
    for (int i = 0; i < 1000; ++i) {
        FieldRotation<DerivativeStructure> rotation = randomRotation(random);
        FieldVector3D<DerivativeStructure> rotationRate = randomVector(random, 0.01);
        FieldVector3D<DerivativeStructure> rotationAcceleration = randomVector(random, 0.01);
        FieldAngularCoordinates<DerivativeStructure> ac = new FieldAngularCoordinates<>(rotation, rotationRate, rotationAcceleration);
        FieldVector3D<DerivativeStructure> p = randomVector(random, 10.0);
        FieldVector3D<DerivativeStructure> v = randomVector(random, 10.0);
        FieldVector3D<DerivativeStructure> a = randomVector(random, 10.0);
        FieldPVCoordinates<DerivativeStructure> pv = new FieldPVCoordinates<>(p, v, a);
        PVCoordinates reference = ac.toAngularCoordinates().applyTo(pv.toPVCoordinates());
        FieldPVCoordinates<DerivativeStructure> res1 = ac.applyTo(pv.toPVCoordinates());
        Assert.assertEquals(0.0, Vector3D.distance(reference.getPosition(), res1.getPosition().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getVelocity(), res1.getVelocity().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getAcceleration(), res1.getAcceleration().toVector3D()), 1.0e-15);
        FieldPVCoordinates<DerivativeStructure> res2 = ac.applyTo(pv);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getPosition(), res2.getPosition().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getVelocity(), res2.getVelocity().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getAcceleration(), res2.getAcceleration().toVector3D()), 1.0e-15);
        TimeStampedFieldPVCoordinates<DerivativeStructure> res3 = ac.applyTo(new TimeStampedFieldPVCoordinates<>(AbsoluteDate.J2000_EPOCH, pv));
        Assert.assertEquals(0.0, AbsoluteDate.J2000_EPOCH.durationFrom(res3.getDate().toAbsoluteDate()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getPosition(), res3.getPosition().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getVelocity(), res3.getVelocity().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getAcceleration(), res3.getAcceleration().toVector3D()), 1.0e-15);
        TimeStampedFieldPVCoordinates<DerivativeStructure> res4 = ac.applyTo(new TimeStampedPVCoordinates(AbsoluteDate.J2000_EPOCH, pv.toPVCoordinates()));
        Assert.assertEquals(0.0, AbsoluteDate.J2000_EPOCH.durationFrom(res4.getDate().toAbsoluteDate()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getPosition(), res4.getPosition().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getVelocity(), res4.getVelocity().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(reference.getAcceleration(), res4.getAcceleration().toVector3D()), 1.0e-15);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Example 24 with DerivativeStructure

use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.

the class FieldAngularCoordinatesTest method testRodriguesVsDouble.

@Test
public void testRodriguesVsDouble() {
    RandomGenerator random = new Well1024a(0x4beeee3d8d2abacal);
    for (int i = 0; i < 1000; ++i) {
        FieldRotation<DerivativeStructure> rotation = randomRotation(random);
        FieldVector3D<DerivativeStructure> rotationRate = randomVector(random, 0.01);
        FieldVector3D<DerivativeStructure> rotationAcceleration = randomVector(random, 0.01);
        FieldAngularCoordinates<DerivativeStructure> ac = new FieldAngularCoordinates<>(rotation, rotationRate, rotationAcceleration);
        DerivativeStructure[][] rod = ac.getModifiedRodrigues(1.0);
        double[][] rodRef = ac.toAngularCoordinates().getModifiedRodrigues(1.0);
        Assert.assertEquals(rodRef.length, rod.length);
        for (int k = 0; k < rodRef.length; ++k) {
            Assert.assertEquals(rodRef[k].length, rod[k].length);
            for (int l = 0; l < rodRef[k].length; ++l) {
                Assert.assertEquals(rodRef[k][l], rod[k][l].getReal(), 1.0e-15 * FastMath.abs(rodRef[k][l]));
            }
        }
        FieldAngularCoordinates<DerivativeStructure> rebuilt = FieldAngularCoordinates.createFromModifiedRodrigues(rod);
        AngularCoordinates rebuiltRef = AngularCoordinates.createFromModifiedRodrigues(rodRef);
        Assert.assertEquals(0.0, Rotation.distance(rebuiltRef.getRotation(), rebuilt.getRotation().toRotation()), 1.0e-14);
        Assert.assertEquals(0.0, Vector3D.distance(rebuiltRef.getRotationRate(), rebuilt.getRotationRate().toVector3D()), 1.0e-15);
        Assert.assertEquals(0.0, Vector3D.distance(rebuiltRef.getRotationAcceleration(), rebuilt.getRotationAcceleration().toVector3D()), 1.0e-15);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Example 25 with DerivativeStructure

use of org.hipparchus.analysis.differentiation.DerivativeStructure in project Orekit by CS-SI.

the class FieldAngularCoordinatesTest method testRodriguesSymmetry.

@Test
public void testRodriguesSymmetry() {
    // check the two-way conversion result in identity
    RandomGenerator random = new Well1024a(0xb1e615aaa8236b52l);
    for (int i = 0; i < 1000; ++i) {
        FieldRotation<DerivativeStructure> rotation = randomRotation(random);
        FieldVector3D<DerivativeStructure> rotationRate = randomVector(random, 0.01);
        FieldVector3D<DerivativeStructure> rotationAcceleration = randomVector(random, 0.01);
        FieldAngularCoordinates<DerivativeStructure> ac = new FieldAngularCoordinates<>(rotation, rotationRate, rotationAcceleration);
        FieldAngularCoordinates<DerivativeStructure> rebuilt = FieldAngularCoordinates.createFromModifiedRodrigues(ac.getModifiedRodrigues(1.0));
        Assert.assertEquals(0.0, FieldRotation.distance(rotation, rebuilt.getRotation()).getReal(), 1.0e-14);
        Assert.assertEquals(0.0, FieldVector3D.distance(rotationRate, rebuilt.getRotationRate()).getReal(), 1.0e-15);
        Assert.assertEquals(0.0, FieldVector3D.distance(rotationAcceleration, rebuilt.getRotationAcceleration()).getReal(), 1.0e-15);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Aggregations

DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)140 Test (org.junit.Test)69 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)63 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)42 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)40 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)33 SpacecraftState (org.orekit.propagation.SpacecraftState)30 AbsoluteDate (org.orekit.time.AbsoluteDate)25 RandomGenerator (org.hipparchus.random.RandomGenerator)22 Frame (org.orekit.frames.Frame)22 PVCoordinates (org.orekit.utils.PVCoordinates)21 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)20 FieldPVCoordinates (org.orekit.utils.FieldPVCoordinates)18 OrekitException (org.orekit.errors.OrekitException)16 FiniteDifferencesDifferentiator (org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)15 AbstractLegacyForceModelTest (org.orekit.forces.AbstractLegacyForceModelTest)15 OrbitType (org.orekit.orbits.OrbitType)15 ParameterDriver (org.orekit.utils.ParameterDriver)15 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)14 FieldNumericalPropagator (org.orekit.propagation.numerical.FieldNumericalPropagator)14