Search in sources :

Example 51 with Well19937a

use of org.hipparchus.random.Well19937a in project Orekit by CS-SI.

the class TabulatedLofOffsetTest method testConstantOffset.

@Test
public void testConstantOffset() throws OrekitException {
    RandomGenerator random = new Well19937a(0x1199d4bb8f53d2b6l);
    for (LOFType type : LOFType.values()) {
        for (int i = 0; i < 100; ++i) {
            double a1 = random.nextDouble() * MathUtils.TWO_PI;
            double a2 = random.nextDouble() * MathUtils.TWO_PI;
            double a3 = random.nextDouble() * MathUtils.TWO_PI;
            LofOffset law = new LofOffset(orbit.getFrame(), type, RotationOrder.XYZ, a1, a2, a3);
            Rotation offsetAtt = law.getAttitude(orbit, orbit.getDate(), orbit.getFrame()).getRotation();
            LofOffset aligned = new LofOffset(orbit.getFrame(), type);
            Rotation alignedAtt = aligned.getAttitude(orbit, orbit.getDate(), orbit.getFrame()).getRotation();
            Rotation offsetProper = offsetAtt.compose(alignedAtt.revert(), RotationConvention.VECTOR_OPERATOR);
            TabulatedLofOffset tabulated = new TabulatedLofOffset(orbit.getFrame(), type, Arrays.asList(new TimeStampedAngularCoordinates(orbit.getDate().shiftedBy(-10), offsetProper, Vector3D.ZERO, Vector3D.ZERO), new TimeStampedAngularCoordinates(orbit.getDate().shiftedBy(0), offsetProper, Vector3D.ZERO, Vector3D.ZERO), new TimeStampedAngularCoordinates(orbit.getDate().shiftedBy(+10), offsetProper, Vector3D.ZERO, Vector3D.ZERO)), 2, AngularDerivativesFilter.USE_R);
            Rotation rebuilt = tabulated.getAttitude(orbit, orbit.getDate(), orbit.getFrame()).getRotation();
            Assert.assertEquals(0.0, Rotation.distance(offsetAtt, rebuilt), 1.2e-15);
        }
    }
}
Also used : LOFType(org.orekit.frames.LOFType) Well19937a(org.hipparchus.random.Well19937a) Rotation(org.hipparchus.geometry.euclidean.threed.Rotation) RandomGenerator(org.hipparchus.random.RandomGenerator) TimeStampedAngularCoordinates(org.orekit.utils.TimeStampedAngularCoordinates) Test(org.junit.Test)

Example 52 with Well19937a

use of org.hipparchus.random.Well19937a in project Orekit by CS-SI.

the class EllipsoidTest method testRandomNormalSections.

@Test
public void testRandomNormalSections() throws IOException {
    RandomGenerator random = new Well19937a(0x573c54d152aeafe4l);
    for (int i = 0; i < 100; ++i) {
        double a = 10 * random.nextDouble();
        double b = 10 * random.nextDouble();
        double c = 10 * random.nextDouble();
        double size = FastMath.max(FastMath.max(a, b), c);
        final Ellipsoid ellipsoid = new Ellipsoid(FramesFactory.getEME2000(), a, b, c);
        for (int j = 0; j < 50; ++j) {
            double phi = FastMath.PI * (random.nextDouble() - 0.5);
            double lambda = 2 * FastMath.PI * random.nextDouble();
            double cPhi = FastMath.cos(phi);
            double sPhi = FastMath.sin(phi);
            double cLambda = FastMath.cos(lambda);
            double sLambda = FastMath.sin(lambda);
            Vector3D surfacePoint = new Vector3D(ellipsoid.getA() * cPhi * cLambda, ellipsoid.getB() * cPhi * sLambda, ellipsoid.getC() * sPhi);
            Vector3D t1 = new Vector3D(-ellipsoid.getA() * cPhi * sLambda, ellipsoid.getB() * cPhi * cLambda, 0).normalize();
            Vector3D t2 = new Vector3D(-ellipsoid.getA() * sPhi * cLambda, -ellipsoid.getB() * sPhi * sLambda, ellipsoid.getC() * cPhi).normalize();
            final double azimuth = 2 * FastMath.PI * random.nextDouble();
            double cAzimuth = FastMath.cos(azimuth);
            double sAzimuth = FastMath.sin(azimuth);
            Vector3D tAz = new Vector3D(cAzimuth, t1, sAzimuth, t2);
            final Ellipse ps = ellipsoid.getPlaneSection(surfacePoint, tAz);
            Assert.assertEquals(0.0, errorOnEllipsoid(ps, ellipsoid), 1.0e-12 * size);
            Assert.assertEquals(0.0, errorOnPlane(ps, surfacePoint, tAz), 1.0e-10 * size);
            double cos = Vector3D.dotProduct(surfacePoint.subtract(ps.getCenter()), ps.getU()) / ps.getA();
            double sin = Vector3D.dotProduct(surfacePoint.subtract(ps.getCenter()), ps.getV()) / ps.getB();
            final Vector3D rebuilt = ps.pointAt(FastMath.atan2(sin, cos));
            Assert.assertEquals(0, Vector3D.distance(surfacePoint, rebuilt), 1.0e-11 * size);
        }
    }
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Well19937a(org.hipparchus.random.Well19937a) RandomGenerator(org.hipparchus.random.RandomGenerator) Test(org.junit.Test)

Example 53 with Well19937a

use of org.hipparchus.random.Well19937a in project Orekit by CS-SI.

the class FieldTransformTest method doTestJacobianPV.

private <T extends RealFieldElement<T>> void doTestJacobianPV(Field<T> field) {
    // base directions for finite differences
    @SuppressWarnings("unchecked") FieldPVCoordinates<T>[] directions = (FieldPVCoordinates<T>[]) Array.newInstance(FieldPVCoordinates.class, 6);
    directions[0] = new FieldPVCoordinates<>(FieldVector3D.getPlusI(field), FieldVector3D.getZero(field), FieldVector3D.getZero(field));
    directions[1] = new FieldPVCoordinates<>(FieldVector3D.getPlusJ(field), FieldVector3D.getZero(field), FieldVector3D.getZero(field));
    directions[2] = new FieldPVCoordinates<>(FieldVector3D.getPlusK(field), FieldVector3D.getZero(field), FieldVector3D.getZero(field));
    directions[3] = new FieldPVCoordinates<>(FieldVector3D.getZero(field), FieldVector3D.getPlusI(field), FieldVector3D.getZero(field));
    directions[4] = new FieldPVCoordinates<>(FieldVector3D.getZero(field), FieldVector3D.getPlusJ(field), FieldVector3D.getZero(field));
    directions[5] = new FieldPVCoordinates<>(FieldVector3D.getZero(field), FieldVector3D.getPlusK(field), FieldVector3D.getZero(field));
    double h = 0.01;
    RandomGenerator random = new Well19937a(0xce2bfddfbb9796bel);
    for (int i = 0; i < 20; ++i) {
        // generate a random transform
        FieldTransform<T> combined = randomTransform(field, random);
        // compute Jacobian
        T[][] jacobian = MathArrays.buildArray(field, 9, 9);
        for (int l = 0; l < jacobian.length; ++l) {
            for (int c = 0; c < jacobian[l].length; ++c) {
                jacobian[l][c] = field.getZero().add(l + 0.1 * c);
            }
        }
        combined.getJacobian(CartesianDerivativesFilter.USE_PV, jacobian);
        for (int j = 0; j < 100; ++j) {
            FieldPVCoordinates<T> pv0 = new FieldPVCoordinates<>(randomVector(field, 1e3, random), randomVector(field, 1.0, random), randomVector(field, 1.0e-3, random));
            double epsilonP = 2.0e-12 * pv0.getPosition().getNorm().getReal();
            double epsilonV = 6.0e-11 * pv0.getVelocity().getNorm().getReal();
            for (int c = 0; c < directions.length; ++c) {
                // eight points finite differences estimation of a Jacobian column
                FieldPVCoordinates<T> pvm4h = combined.transformPVCoordinates(new FieldPVCoordinates<>(1.0, pv0, -4 * h, directions[c]));
                FieldPVCoordinates<T> pvm3h = combined.transformPVCoordinates(new FieldPVCoordinates<>(1.0, pv0, -3 * h, directions[c]));
                FieldPVCoordinates<T> pvm2h = combined.transformPVCoordinates(new FieldPVCoordinates<>(1.0, pv0, -2 * h, directions[c]));
                FieldPVCoordinates<T> pvm1h = combined.transformPVCoordinates(new FieldPVCoordinates<>(1.0, pv0, -1 * h, directions[c]));
                FieldPVCoordinates<T> pvp1h = combined.transformPVCoordinates(new FieldPVCoordinates<>(1.0, pv0, +1 * h, directions[c]));
                FieldPVCoordinates<T> pvp2h = combined.transformPVCoordinates(new FieldPVCoordinates<>(1.0, pv0, +2 * h, directions[c]));
                FieldPVCoordinates<T> pvp3h = combined.transformPVCoordinates(new FieldPVCoordinates<>(1.0, pv0, +3 * h, directions[c]));
                FieldPVCoordinates<T> pvp4h = combined.transformPVCoordinates(new FieldPVCoordinates<>(1.0, pv0, +4 * h, directions[c]));
                FieldPVCoordinates<T> d4 = new FieldPVCoordinates<>(pvm4h, pvp4h);
                FieldPVCoordinates<T> d3 = new FieldPVCoordinates<>(pvm3h, pvp3h);
                FieldPVCoordinates<T> d2 = new FieldPVCoordinates<>(pvm2h, pvp2h);
                FieldPVCoordinates<T> d1 = new FieldPVCoordinates<>(pvm1h, pvp1h);
                double d = 1.0 / (840 * h);
                FieldPVCoordinates<T> estimatedColumn = new FieldPVCoordinates<>(-3 * d, d4, 32 * d, d3, -168 * d, d2, 672 * d, d1);
                // check analytical Jacobian against finite difference reference
                Assert.assertEquals(estimatedColumn.getPosition().getX().getReal(), jacobian[0][c].getReal(), epsilonP);
                Assert.assertEquals(estimatedColumn.getPosition().getY().getReal(), jacobian[1][c].getReal(), epsilonP);
                Assert.assertEquals(estimatedColumn.getPosition().getZ().getReal(), jacobian[2][c].getReal(), epsilonP);
                Assert.assertEquals(estimatedColumn.getVelocity().getX().getReal(), jacobian[3][c].getReal(), epsilonV);
                Assert.assertEquals(estimatedColumn.getVelocity().getY().getReal(), jacobian[4][c].getReal(), epsilonV);
                Assert.assertEquals(estimatedColumn.getVelocity().getZ().getReal(), jacobian[5][c].getReal(), epsilonV);
                // check the rest of the matrix remains untouched
                for (int l = 6; l < jacobian.length; ++l) {
                    Assert.assertEquals(l + 0.1 * c, jacobian[l][c].getReal(), 1.0e-15);
                }
            }
            // check the rest of the matrix remains untouched
            for (int c = directions.length; c < jacobian[0].length; ++c) {
                for (int l = 0; l < jacobian.length; ++l) {
                    Assert.assertEquals(l + 0.1 * c, jacobian[l][c].getReal(), 1.0e-15);
                }
            }
        }
    }
}
Also used : FieldPVCoordinates(org.orekit.utils.FieldPVCoordinates) TimeStampedFieldPVCoordinates(org.orekit.utils.TimeStampedFieldPVCoordinates) Well19937a(org.hipparchus.random.Well19937a) RandomGenerator(org.hipparchus.random.RandomGenerator)

Example 54 with Well19937a

use of org.hipparchus.random.Well19937a in project Orekit by CS-SI.

the class TransformTest method testIdentityLine.

@Test
public void testIdentityLine() {
    RandomGenerator random = new Well19937a(0x98603025df70db7cl);
    Vector3D p1 = randomVector(100.0, random);
    Vector3D p2 = randomVector(100.0, random);
    Line line = new Line(p1, p2, 1.0e-6);
    Line transformed = Transform.IDENTITY.transformLine(line);
    Assert.assertSame(line, transformed);
}
Also used : Line(org.hipparchus.geometry.euclidean.threed.Line) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Well19937a(org.hipparchus.random.Well19937a) RandomGenerator(org.hipparchus.random.RandomGenerator) Test(org.junit.Test)

Example 55 with Well19937a

use of org.hipparchus.random.Well19937a in project Orekit by CS-SI.

the class TransformTest method testRandomComposition.

@Test
public void testRandomComposition() {
    RandomGenerator random = new Well19937a(0x171c79e323a1123l);
    for (int i = 0; i < 20; ++i) {
        // build a complex transform by composing primitive ones
        int n = random.nextInt(20);
        Transform[] transforms = new Transform[n];
        Transform combined = Transform.IDENTITY;
        for (int k = 0; k < n; ++k) {
            transforms[k] = random.nextBoolean() ? new Transform(AbsoluteDate.J2000_EPOCH, randomVector(1.0e3, random), randomVector(1.0, random), randomVector(1.0e-3, random)) : new Transform(AbsoluteDate.J2000_EPOCH, randomRotation(random), randomVector(0.01, random), randomVector(1.0e-4, random));
            combined = new Transform(AbsoluteDate.J2000_EPOCH, combined, transforms[k]);
        }
        // check the composition
        for (int j = 0; j < 10; ++j) {
            Vector3D a = randomVector(1.0, random);
            FieldVector3D<Decimal64> aF = new FieldVector3D<>(Decimal64Field.getInstance(), a);
            Vector3D b = randomVector(1.0e3, random);
            PVCoordinates c = new PVCoordinates(randomVector(1.0e3, random), randomVector(1.0, random), randomVector(1.0e-3, random));
            Vector3D aRef = a;
            FieldVector3D<Decimal64> aFRef = aF;
            Vector3D bRef = b;
            PVCoordinates cRef = c;
            for (int k = 0; k < n; ++k) {
                aRef = transforms[k].transformVector(aRef);
                aFRef = transforms[k].transformVector(aFRef);
                bRef = transforms[k].transformPosition(bRef);
                cRef = transforms[k].transformPVCoordinates(cRef);
            }
            Vector3D aCombined = combined.transformVector(a);
            FieldVector3D<Decimal64> aFCombined = combined.transformVector(aF);
            Vector3D bCombined = combined.transformPosition(b);
            PVCoordinates cCombined = combined.transformPVCoordinates(c);
            checkVector(aRef, aCombined, 3.0e-15);
            checkVector(aFRef.toVector3D(), aFCombined.toVector3D(), 3.0e-15);
            checkVector(bRef, bCombined, 5.0e-15);
            checkVector(cRef.getPosition(), cCombined.getPosition(), 1.0e-14);
            checkVector(cRef.getVelocity(), cCombined.getVelocity(), 1.0e-14);
            checkVector(cRef.getAcceleration(), cCombined.getAcceleration(), 1.0e-14);
        }
    }
}
Also used : FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Decimal64(org.hipparchus.util.Decimal64) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) FieldPVCoordinates(org.orekit.utils.FieldPVCoordinates) PVCoordinates(org.orekit.utils.PVCoordinates) TimeStampedFieldPVCoordinates(org.orekit.utils.TimeStampedFieldPVCoordinates) Well19937a(org.hipparchus.random.Well19937a) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) RandomGenerator(org.hipparchus.random.RandomGenerator) Test(org.junit.Test)

Aggregations

RandomGenerator (org.hipparchus.random.RandomGenerator)73 Well19937a (org.hipparchus.random.Well19937a)73 Test (org.junit.Test)51 FieldPVCoordinates (org.orekit.utils.FieldPVCoordinates)22 GeodeticPoint (org.orekit.bodies.GeodeticPoint)19 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)17 PVCoordinates (org.orekit.utils.PVCoordinates)15 TimeStampedFieldPVCoordinates (org.orekit.utils.TimeStampedFieldPVCoordinates)15 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)14 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)14 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)13 DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)13 Frame (org.orekit.frames.Frame)10 GaussianRandomGenerator (org.hipparchus.random.GaussianRandomGenerator)8 UncorrelatedRandomVectorGenerator (org.hipparchus.random.UncorrelatedRandomVectorGenerator)8 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)8 OrbitType (org.orekit.orbits.OrbitType)8 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)8 SpacecraftState (org.orekit.propagation.SpacecraftState)8 FieldNumericalPropagator (org.orekit.propagation.numerical.FieldNumericalPropagator)8