use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class PVCoordinatesTest method testCrossProduct.
@Test
public void testCrossProduct() {
DSFactory factory = new DSFactory(1, 2);
RandomGenerator generator = new Well19937a(0x85c592b3be733d23l);
FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 1.0e-3);
for (int i = 0; i < 200; ++i) {
final PVCoordinates pv1 = randomPVCoordinates(generator, 1.0, 1.0, 1.0);
final PVCoordinates pv2 = randomPVCoordinates(generator, 1.0, 1.0, 1.0);
DerivativeStructure x = differentiator.differentiate(new UnivariateFunction() {
public double value(double t) {
return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getX();
}
}).value(factory.variable(0, 0.0));
DerivativeStructure y = differentiator.differentiate(new UnivariateFunction() {
public double value(double t) {
return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getY();
}
}).value(factory.variable(0, 0.0));
DerivativeStructure z = differentiator.differentiate(new UnivariateFunction() {
public double value(double t) {
return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getZ();
}
}).value(factory.variable(0, 0.0));
PVCoordinates product = PVCoordinates.crossProduct(pv1, pv2);
Assert.assertEquals(x.getValue(), product.getPosition().getX(), 1.0e-16);
Assert.assertEquals(y.getValue(), product.getPosition().getY(), 1.0e-16);
Assert.assertEquals(z.getValue(), product.getPosition().getZ(), 1.0e-16);
Assert.assertEquals(x.getPartialDerivative(1), product.getVelocity().getX(), 9.0e-10);
Assert.assertEquals(y.getPartialDerivative(1), product.getVelocity().getY(), 9.0e-10);
Assert.assertEquals(z.getPartialDerivative(1), product.getVelocity().getZ(), 9.0e-10);
Assert.assertEquals(x.getPartialDerivative(2), product.getAcceleration().getX(), 3.0e-9);
Assert.assertEquals(y.getPartialDerivative(2), product.getAcceleration().getY(), 3.0e-9);
Assert.assertEquals(z.getPartialDerivative(2), product.getAcceleration().getZ(), 3.0e-9);
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class TimeStampedAngularCoordinatesTest method testOnePair.
@Test
public void testOnePair() throws OrekitException, java.io.IOException {
RandomGenerator random = new Well1024a(0xed7dd911a44c5197l);
for (int i = 0; i < 20; ++i) {
Rotation r = randomRotation(random);
Vector3D o = randomVector(random, 1.0e-2);
Vector3D a = randomVector(random, 1.0e-2);
TimeStampedAngularCoordinates reference = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, r, o, a);
PVCoordinates u = randomPVCoordinates(random, 1000, 1.0, 0.001);
PVCoordinates v = reference.applyTo(u);
TimeStampedAngularCoordinates ac = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, u, v);
Assert.assertEquals(0, Vector3D.distance(v.getPosition().normalize(), ac.applyTo(u).getPosition().normalize()), 1.0e-14);
Assert.assertEquals(0, Vector3D.distance(v.getVelocity().normalize(), ac.applyTo(u).getVelocity().normalize()), 4.0e-14);
Assert.assertEquals(0, Vector3D.distance(v.getAcceleration().normalize(), ac.applyTo(u).getAcceleration().normalize()), 1.0e-14);
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class TimeStampedAngularCoordinatesTest method testTwoPairs.
@Test
public void testTwoPairs() throws OrekitException, java.io.IOException {
RandomGenerator random = new Well1024a(0x976ad943966c9f00l);
for (int i = 0; i < 20; ++i) {
Rotation r = randomRotation(random);
Vector3D o = randomVector(random, 1.0e-2);
Vector3D a = randomVector(random, 1.0e-2);
TimeStampedAngularCoordinates reference = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, r, o, a);
PVCoordinates u1 = randomPVCoordinates(random, 1000, 1.0, 0.001);
PVCoordinates u2 = randomPVCoordinates(random, 1000, 1.0, 0.001);
PVCoordinates v1 = reference.applyTo(u1);
PVCoordinates v2 = reference.applyTo(u2);
TimeStampedAngularCoordinates ac = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, u1, u2, v1, v2, 1.0e-9);
Assert.assertEquals(0, Vector3D.distance(v1.getPosition().normalize(), ac.applyTo(u1).getPosition().normalize()), 1.0e-14);
Assert.assertEquals(0, Vector3D.distance(v1.getVelocity().normalize(), ac.applyTo(u1).getVelocity().normalize()), 1.0e-14);
Assert.assertEquals(0, Vector3D.distance(v1.getAcceleration().normalize(), ac.applyTo(u1).getAcceleration().normalize()), 1.0e-14);
Assert.assertEquals(0, Vector3D.distance(v2.getPosition().normalize(), ac.applyTo(u2).getPosition().normalize()), 1.0e-14);
Assert.assertEquals(0, Vector3D.distance(v2.getVelocity().normalize(), ac.applyTo(u2).getVelocity().normalize()), 1.0e-14);
Assert.assertEquals(0, Vector3D.distance(v2.getAcceleration().normalize(), ac.applyTo(u2).getAcceleration().normalize()), 1.0e-14);
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class TimeStampedAngularCoordinatesTest method testReverseOffset.
@Test
public void testReverseOffset() {
RandomGenerator random = new Well1024a(0x4ecca9d57a8f1611l);
for (int i = 0; i < 100; ++i) {
Rotation r = randomRotation(random);
Vector3D o = randomVector(random, 1.0e-3);
Vector3D a = randomVector(random, 1.0e-3);
TimeStampedAngularCoordinates ac = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, r, o, a);
TimeStampedAngularCoordinates sum = ac.addOffset(ac.revert());
Assert.assertEquals(0.0, sum.getRotation().getAngle(), 1.0e-15);
Assert.assertEquals(0.0, sum.getRotationRate().getNorm(), 1.0e-15);
Assert.assertEquals(0.0, sum.getRotationAcceleration().getNorm(), 1.0e-15);
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class UTCScaleTest method testMultithreading.
@Test
public void testMultithreading() {
// generate reference offsets using a single thread
RandomGenerator random = new Well1024a(6392073424l);
List<AbsoluteDate> datesList = new ArrayList<AbsoluteDate>();
List<Double> offsetsList = new ArrayList<Double>();
AbsoluteDate reference = utc.getFirstKnownLeapSecond().shiftedBy(-Constants.JULIAN_YEAR);
double testRange = utc.getLastKnownLeapSecond().durationFrom(reference) + Constants.JULIAN_YEAR;
for (int i = 0; i < 10000; ++i) {
AbsoluteDate randomDate = reference.shiftedBy(random.nextDouble() * testRange);
datesList.add(randomDate);
offsetsList.add(utc.offsetFromTAI(randomDate));
}
// check the offsets in multi-threaded mode
ExecutorService executorService = Executors.newFixedThreadPool(100);
for (int i = 0; i < datesList.size(); ++i) {
final AbsoluteDate date = datesList.get(i);
final double offset = offsetsList.get(i);
executorService.execute(new Runnable() {
public void run() {
Assert.assertEquals(offset, utc.offsetFromTAI(date), 1.0e-12);
}
});
}
try {
executorService.shutdown();
executorService.awaitTermination(3, TimeUnit.SECONDS);
} catch (InterruptedException ie) {
Assert.fail(ie.getLocalizedMessage());
}
}
Aggregations