use of org.hipparchus.random.RandomGenerator 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);
}
use of org.hipparchus.random.RandomGenerator 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);
}
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class TransformTest method testRotPV.
@Test
public void testRotPV() {
RandomGenerator rnd = new Well19937a(0x73d5554d99427af0l);
for (int i = 0; i < 10; ++i) {
// Random instant rotation
Rotation instantRot = randomRotation(rnd);
Vector3D normAxis = instantRot.getAxis(RotationConvention.VECTOR_OPERATOR);
double w = FastMath.abs(instantRot.getAngle()) / Constants.JULIAN_DAY;
// random rotation
Rotation rot = randomRotation(rnd);
// so we have a transform
Transform tr = new Transform(AbsoluteDate.J2000_EPOCH, rot, new Vector3D(w, normAxis));
// random position, velocity, acceleration
Vector3D pos = randomVector(1.0e3, rnd);
Vector3D vel = randomVector(1.0, rnd);
Vector3D acc = randomVector(1.0e-3, rnd);
PVCoordinates pvOne = new PVCoordinates(pos, vel, acc);
// we obtain
PVCoordinates pvTwo = tr.transformPVCoordinates(pvOne);
// test inverse
Vector3D resultvel = tr.getInverse().transformPVCoordinates(pvTwo).getVelocity();
checkVector(resultvel, vel, 1.0e-15);
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class TransformTest method testJacobianP.
@Test
public void testJacobianP() {
// base directions for finite differences
PVCoordinates[] directions = new PVCoordinates[] { new PVCoordinates(Vector3D.PLUS_I, Vector3D.ZERO, Vector3D.ZERO), new PVCoordinates(Vector3D.PLUS_J, Vector3D.ZERO, Vector3D.ZERO), new PVCoordinates(Vector3D.PLUS_K, Vector3D.ZERO, Vector3D.ZERO) };
double h = 0.01;
RandomGenerator random = new Well19937a(0x47fd0d6809f4b173l);
for (int i = 0; i < 20; ++i) {
// generate a random transform
Transform combined = randomTransform(random);
// compute Jacobian
double[][] jacobian = new double[9][9];
for (int l = 0; l < jacobian.length; ++l) {
for (int c = 0; c < jacobian[l].length; ++c) {
jacobian[l][c] = l + 0.1 * c;
}
}
combined.getJacobian(CartesianDerivativesFilter.USE_P, jacobian);
for (int j = 0; j < 100; ++j) {
PVCoordinates pv0 = new PVCoordinates(randomVector(1e3, random), randomVector(1.0, random), randomVector(1.0e-3, random));
double epsilonP = 2.0e-12 * pv0.getPosition().getNorm();
for (int c = 0; c < directions.length; ++c) {
// eight points finite differences estimation of a Jacobian column
PVCoordinates pvm4h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, -4 * h, directions[c]));
PVCoordinates pvm3h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, -3 * h, directions[c]));
PVCoordinates pvm2h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, -2 * h, directions[c]));
PVCoordinates pvm1h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, -1 * h, directions[c]));
PVCoordinates pvp1h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, +1 * h, directions[c]));
PVCoordinates pvp2h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, +2 * h, directions[c]));
PVCoordinates pvp3h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, +3 * h, directions[c]));
PVCoordinates pvp4h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, +4 * h, directions[c]));
PVCoordinates d4 = new PVCoordinates(pvm4h, pvp4h);
PVCoordinates d3 = new PVCoordinates(pvm3h, pvp3h);
PVCoordinates d2 = new PVCoordinates(pvm2h, pvp2h);
PVCoordinates d1 = new PVCoordinates(pvm1h, pvp1h);
double d = 1.0 / (840 * h);
PVCoordinates estimatedColumn = new PVCoordinates(-3 * d, d4, 32 * d, d3, -168 * d, d2, 672 * d, d1);
// check analytical Jacobian against finite difference reference
Assert.assertEquals(estimatedColumn.getPosition().getX(), jacobian[0][c], epsilonP);
Assert.assertEquals(estimatedColumn.getPosition().getY(), jacobian[1][c], epsilonP);
Assert.assertEquals(estimatedColumn.getPosition().getZ(), jacobian[2][c], epsilonP);
// check the rest of the matrix remains untouched
for (int l = 3; l < jacobian.length; ++l) {
Assert.assertEquals(l + 0.1 * c, jacobian[l][c], 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], 1.0e-15);
}
}
}
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class TransformTest method testJacobianPV.
@Test
public void testJacobianPV() {
// base directions for finite differences
PVCoordinates[] directions = new PVCoordinates[] { new PVCoordinates(Vector3D.PLUS_I, Vector3D.ZERO, Vector3D.ZERO), new PVCoordinates(Vector3D.PLUS_J, Vector3D.ZERO, Vector3D.ZERO), new PVCoordinates(Vector3D.PLUS_K, Vector3D.ZERO, Vector3D.ZERO), new PVCoordinates(Vector3D.ZERO, Vector3D.PLUS_I, Vector3D.ZERO), new PVCoordinates(Vector3D.ZERO, Vector3D.PLUS_J, Vector3D.ZERO), new PVCoordinates(Vector3D.ZERO, Vector3D.PLUS_K, Vector3D.ZERO) };
double h = 0.01;
RandomGenerator random = new Well19937a(0xce2bfddfbb9796bel);
for (int i = 0; i < 20; ++i) {
// generate a random transform
Transform combined = randomTransform(random);
// compute Jacobian
double[][] jacobian = new double[9][9];
for (int l = 0; l < jacobian.length; ++l) {
for (int c = 0; c < jacobian[l].length; ++c) {
jacobian[l][c] = l + 0.1 * c;
}
}
combined.getJacobian(CartesianDerivativesFilter.USE_PV, jacobian);
for (int j = 0; j < 100; ++j) {
PVCoordinates pv0 = new PVCoordinates(randomVector(1e3, random), randomVector(1.0, random), randomVector(1.0e-3, random));
double epsilonP = 2.0e-12 * pv0.getPosition().getNorm();
double epsilonV = 6.0e-11 * pv0.getVelocity().getNorm();
for (int c = 0; c < directions.length; ++c) {
// eight points finite differences estimation of a Jacobian column
PVCoordinates pvm4h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, -4 * h, directions[c]));
PVCoordinates pvm3h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, -3 * h, directions[c]));
PVCoordinates pvm2h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, -2 * h, directions[c]));
PVCoordinates pvm1h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, -1 * h, directions[c]));
PVCoordinates pvp1h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, +1 * h, directions[c]));
PVCoordinates pvp2h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, +2 * h, directions[c]));
PVCoordinates pvp3h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, +3 * h, directions[c]));
PVCoordinates pvp4h = combined.transformPVCoordinates(new PVCoordinates(1.0, pv0, +4 * h, directions[c]));
PVCoordinates d4 = new PVCoordinates(pvm4h, pvp4h);
PVCoordinates d3 = new PVCoordinates(pvm3h, pvp3h);
PVCoordinates d2 = new PVCoordinates(pvm2h, pvp2h);
PVCoordinates d1 = new PVCoordinates(pvm1h, pvp1h);
double d = 1.0 / (840 * h);
PVCoordinates estimatedColumn = new PVCoordinates(-3 * d, d4, 32 * d, d3, -168 * d, d2, 672 * d, d1);
// check analytical Jacobian against finite difference reference
Assert.assertEquals(estimatedColumn.getPosition().getX(), jacobian[0][c], epsilonP);
Assert.assertEquals(estimatedColumn.getPosition().getY(), jacobian[1][c], epsilonP);
Assert.assertEquals(estimatedColumn.getPosition().getZ(), jacobian[2][c], epsilonP);
Assert.assertEquals(estimatedColumn.getVelocity().getX(), jacobian[3][c], epsilonV);
Assert.assertEquals(estimatedColumn.getVelocity().getY(), jacobian[4][c], epsilonV);
Assert.assertEquals(estimatedColumn.getVelocity().getZ(), jacobian[5][c], 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], 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], 1.0e-15);
}
}
}
}
}
Aggregations