Java Code Examples for org.apache.commons.math3.random.Well1024a#nextDouble()
The following examples show how to use
org.apache.commons.math3.random.Well1024a#nextDouble() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Vector3DTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testDotProduct() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(553267312521321234l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); double sNaive = ux * vx + uy * vy + uz * vz; double sAccurate = new Vector3D(ux, uy, uz).dotProduct(new Vector3D(vx, vy, vz)); Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate); } }
Example 2
Source File: Vector3DTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testDotProduct() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(553267312521321234l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); double sNaive = ux * vx + uy * vy + uz * vz; double sAccurate = new Vector3D(ux, uy, uz).dotProduct(new Vector3D(vx, vy, vz)); Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate); } }
Example 3
Source File: Vector3DTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCrossProduct() { // we compare accurate versus naive cross product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(885362227452043214l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); Vector3D cNaive = new Vector3D(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx); Vector3D cAccurate = new Vector3D(ux, uy, uz).crossProduct(new Vector3D(vx, vy, vz)); Assert.assertEquals(0.0, cAccurate.distance(cNaive), 6.0e-15 * cAccurate.getNorm()); } }
Example 4
Source File: MathArraysTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testLinearCombination2() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(553267312521321234l); for (int i = 0; i < 10000; ++i) { final double ux = 1e17 * random.nextDouble(); final double uy = 1e17 * random.nextDouble(); final double uz = 1e17 * random.nextDouble(); final double vx = 1e17 * random.nextDouble(); final double vy = 1e17 * random.nextDouble(); final double vz = 1e17 * random.nextDouble(); final double sInline = MathArrays.linearCombination(ux, vx, uy, vy, uz, vz); final double sArray = MathArrays.linearCombination(new double[] {ux, uy, uz}, new double[] {vx, vy, vz}); Assert.assertEquals(sInline, sArray, 0); } }
Example 5
Source File: Vector3DTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCrossProduct() { // we compare accurate versus naive cross product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(885362227452043214l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); Vector3D cNaive = new Vector3D(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx); Vector3D cAccurate = new Vector3D(ux, uy, uz).crossProduct(new Vector3D(vx, vy, vz)); Assert.assertEquals(0.0, cAccurate.distance(cNaive), 6.0e-15 * cAccurate.getNorm()); } }
Example 6
Source File: Vector3DTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCrossProduct() { // we compare accurate versus naive cross product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(885362227452043214l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); Vector3D cNaive = new Vector3D(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx); Vector3D cAccurate = new Vector3D(ux, uy, uz).crossProduct(new Vector3D(vx, vy, vz)); Assert.assertEquals(0.0, cAccurate.distance(cNaive), 6.0e-15 * cAccurate.getNorm()); } }
Example 7
Source File: Vector3DTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testDotProduct() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(553267312521321234l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); double sNaive = ux * vx + uy * vy + uz * vz; double sAccurate = new Vector3D(ux, uy, uz).dotProduct(new Vector3D(vx, vy, vz)); Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate); } }
Example 8
Source File: MathArraysTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testLinearCombination2() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(553267312521321234l); for (int i = 0; i < 10000; ++i) { final double ux = 1e17 * random.nextDouble(); final double uy = 1e17 * random.nextDouble(); final double uz = 1e17 * random.nextDouble(); final double vx = 1e17 * random.nextDouble(); final double vy = 1e17 * random.nextDouble(); final double vz = 1e17 * random.nextDouble(); final double sInline = MathArrays.linearCombination(ux, vx, uy, vy, uz, vz); final double sArray = MathArrays.linearCombination(new double[] {ux, uy, uz}, new double[] {vx, vy, vz}); Assert.assertEquals(sInline, sArray, 0); } }
Example 9
Source File: MathArraysTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testLinearCombination2() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(553267312521321234l); for (int i = 0; i < 10000; ++i) { final double ux = 1e17 * random.nextDouble(); final double uy = 1e17 * random.nextDouble(); final double uz = 1e17 * random.nextDouble(); final double vx = 1e17 * random.nextDouble(); final double vy = 1e17 * random.nextDouble(); final double vz = 1e17 * random.nextDouble(); final double sInline = MathArrays.linearCombination(ux, vx, uy, vy, uz, vz); final double sArray = MathArrays.linearCombination(new double[] {ux, uy, uz}, new double[] {vx, vy, vz}); Assert.assertEquals(sInline, sArray, 0); } }
Example 10
Source File: Vector3DTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCrossProduct() { // we compare accurate versus naive cross product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(885362227452043214l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); Vector3D cNaive = new Vector3D(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx); Vector3D cAccurate = new Vector3D(ux, uy, uz).crossProduct(new Vector3D(vx, vy, vz)); Assert.assertEquals(0.0, cAccurate.distance(cNaive), 6.0e-15 * cAccurate.getNorm()); } }
Example 11
Source File: Vector3DTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCrossProduct() { // we compare accurate versus naive cross product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(885362227452043214l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); Vector3D cNaive = new Vector3D(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx); Vector3D cAccurate = new Vector3D(ux, uy, uz).crossProduct(new Vector3D(vx, vy, vz)); Assert.assertEquals(0.0, cAccurate.distance(cNaive), 6.0e-15 * cAccurate.getNorm()); } }
Example 12
Source File: FieldVector3DTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testDotProduct() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(553267312521321234l); for (int i = 0; i < 10000; ++i) { double ux = 10000 * random.nextDouble(); double uy = 10000 * random.nextDouble(); double uz = 10000 * random.nextDouble(); double vx = 10000 * random.nextDouble(); double vy = 10000 * random.nextDouble(); double vz = 10000 * random.nextDouble(); double sNaive = ux * vx + uy * vy + uz * vz; FieldVector3D<DerivativeStructure> uds = createVector(ux, uy, uz, 3); FieldVector3D<DerivativeStructure> vds = createVector(vx, vy, vz, 3); Vector3D v = new Vector3D(vx, vy, vz); DerivativeStructure sAccurate = FieldVector3D.dotProduct(uds, vds); Assert.assertEquals(sNaive, sAccurate.getReal(), 2.5e-16 * sNaive); Assert.assertEquals(ux + vx, sAccurate.getPartialDerivative(1, 0, 0), 2.5e-16 * sNaive); Assert.assertEquals(uy + vy, sAccurate.getPartialDerivative(0, 1, 0), 2.5e-16 * sNaive); Assert.assertEquals(uz + vz, sAccurate.getPartialDerivative(0, 0, 1), 2.5e-16 * sNaive); sAccurate = FieldVector3D.dotProduct(uds, v); Assert.assertEquals(sNaive, sAccurate.getReal(), 2.5e-16 * sNaive); Assert.assertEquals(vx, sAccurate.getPartialDerivative(1, 0, 0), 2.5e-16 * sNaive); Assert.assertEquals(vy, sAccurate.getPartialDerivative(0, 1, 0), 2.5e-16 * sNaive); Assert.assertEquals(vz, sAccurate.getPartialDerivative(0, 0, 1), 2.5e-16 * sNaive); } }
Example 13
Source File: SparseGradientTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testLinearCombination2DoubleDS() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(0xc6af886975069f11l); for (int i = 0; i < 10000; ++i) { final double[] u = new double[4]; final SparseGradient[] v = new SparseGradient[4]; for (int j = 0; j < u.length; ++j) { u[j] = 1e17 * random.nextDouble(); v[j] = SparseGradient.createVariable(j, 1e17 * random.nextDouble()); } SparseGradient lin = v[0].linearCombination(u[0], v[0], u[1], v[1]); double ref = u[0] * v[0].getValue() + u[1] * v[1].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getDerivative(0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getDerivative(1), 1.0e-15 * FastMath.abs(v[1].getValue())); lin = v[0].linearCombination(u[0], v[0], u[1], v[1], u[2], v[2]); ref = u[0] * v[0].getValue() + u[1] * v[1].getValue() + u[2] * v[2].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getDerivative(0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getDerivative(1), 1.0e-15 * FastMath.abs(v[1].getValue())); Assert.assertEquals(u[2], lin.getDerivative(2), 1.0e-15 * FastMath.abs(v[2].getValue())); lin = v[0].linearCombination(u[0], v[0], u[1], v[1], u[2], v[2], u[3], v[3]); ref = u[0] * v[0].getValue() + u[1] * v[1].getValue() + u[2] * v[2].getValue() + u[3] * v[3].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getDerivative(0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getDerivative(1), 1.0e-15 * FastMath.abs(v[1].getValue())); Assert.assertEquals(u[2], lin.getDerivative(2), 1.0e-15 * FastMath.abs(v[2].getValue())); Assert.assertEquals(u[3], lin.getDerivative(3), 1.0e-15 * FastMath.abs(v[3].getValue())); } }
Example 14
Source File: FieldRotationDfpTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testDoubleRotations() throws MathIllegalArgumentException { DfpField field = new DfpField(20); Well1024a random = new Well1024a(0x180b41cfeeffaf67l); UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random); for (int i = 0; i < 10; ++i) { double[] unit1 = g.nextVector(); Rotation r1 = new Rotation(new Vector3D(unit1[0], unit1[1], unit1[2]), random.nextDouble()); FieldRotation<Dfp> r1Prime = new FieldRotation<Dfp>(field.newDfp(r1.getQ0()), field.newDfp(r1.getQ1()), field.newDfp(r1.getQ2()), field.newDfp(r1.getQ3()), false); double[] unit2 = g.nextVector(); FieldRotation<Dfp> r2 = new FieldRotation<Dfp>(createVector(unit2[0], unit2[1], unit2[2]), createAngle(random.nextDouble())); FieldRotation<Dfp> rA = FieldRotation.applyTo(r1, r2); FieldRotation<Dfp> rB = r1Prime.applyTo(r2); FieldRotation<Dfp> rC = FieldRotation.applyInverseTo(r1, r2); FieldRotation<Dfp> rD = r1Prime.applyInverseTo(r2); for (double x = -0.9; x < 0.9; x += 0.4) { for (double y = -0.9; y < 0.9; y += 0.4) { for (double z = -0.9; z < 0.9; z += 0.4) { FieldVector3D<Dfp> uds = createVector(x, y, z); checkVector(r1Prime.applyTo(uds), FieldRotation.applyTo(r1, uds)); checkVector(r1Prime.applyInverseTo(uds), FieldRotation.applyInverseTo(r1, uds)); checkVector(rA.applyTo(uds), rB.applyTo(uds)); checkVector(rA.applyInverseTo(uds), rB.applyInverseTo(uds)); checkVector(rC.applyTo(uds), rD.applyTo(uds)); checkVector(rC.applyInverseTo(uds), rD.applyInverseTo(uds)); } } } } }
Example 15
Source File: DerivativeStructureTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testLinearCombination2DoubleDS() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(0xc6af886975069f11l); for (int i = 0; i < 10000; ++i) { final double[] u = new double[4]; final DerivativeStructure[] v = new DerivativeStructure[4]; for (int j = 0; j < u.length; ++j) { u[j] = 1e17 * random.nextDouble(); v[j] = new DerivativeStructure(u.length, 1, j, 1e17 * random.nextDouble()); } DerivativeStructure lin = v[0].linearCombination(u[0], v[0], u[1], v[1]); double ref = u[0] * v[0].getValue() + u[1] * v[1].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getPartialDerivative(1, 0, 0, 0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getPartialDerivative(0, 1, 0, 0), 1.0e-15 * FastMath.abs(v[1].getValue())); lin = v[0].linearCombination(u[0], v[0], u[1], v[1], u[2], v[2]); ref = u[0] * v[0].getValue() + u[1] * v[1].getValue() + u[2] * v[2].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getPartialDerivative(1, 0, 0, 0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getPartialDerivative(0, 1, 0, 0), 1.0e-15 * FastMath.abs(v[1].getValue())); Assert.assertEquals(u[2], lin.getPartialDerivative(0, 0, 1, 0), 1.0e-15 * FastMath.abs(v[2].getValue())); lin = v[0].linearCombination(u[0], v[0], u[1], v[1], u[2], v[2], u[3], v[3]); ref = u[0] * v[0].getValue() + u[1] * v[1].getValue() + u[2] * v[2].getValue() + u[3] * v[3].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getPartialDerivative(1, 0, 0, 0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getPartialDerivative(0, 1, 0, 0), 1.0e-15 * FastMath.abs(v[1].getValue())); Assert.assertEquals(u[2], lin.getPartialDerivative(0, 0, 1, 0), 1.0e-15 * FastMath.abs(v[2].getValue())); Assert.assertEquals(u[3], lin.getPartialDerivative(0, 0, 0, 1), 1.0e-15 * FastMath.abs(v[3].getValue())); } }
Example 16
Source File: FieldRotationDfpTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testDoubleRotations() throws MathIllegalArgumentException { DfpField field = new DfpField(20); Well1024a random = new Well1024a(0x180b41cfeeffaf67l); UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random); for (int i = 0; i < 10; ++i) { double[] unit1 = g.nextVector(); Rotation r1 = new Rotation(new Vector3D(unit1[0], unit1[1], unit1[2]), random.nextDouble()); FieldRotation<Dfp> r1Prime = new FieldRotation<Dfp>(field.newDfp(r1.getQ0()), field.newDfp(r1.getQ1()), field.newDfp(r1.getQ2()), field.newDfp(r1.getQ3()), false); double[] unit2 = g.nextVector(); FieldRotation<Dfp> r2 = new FieldRotation<Dfp>(createVector(unit2[0], unit2[1], unit2[2]), createAngle(random.nextDouble())); FieldRotation<Dfp> rA = FieldRotation.applyTo(r1, r2); FieldRotation<Dfp> rB = r1Prime.applyTo(r2); FieldRotation<Dfp> rC = FieldRotation.applyInverseTo(r1, r2); FieldRotation<Dfp> rD = r1Prime.applyInverseTo(r2); for (double x = -0.9; x < 0.9; x += 0.4) { for (double y = -0.9; y < 0.9; y += 0.4) { for (double z = -0.9; z < 0.9; z += 0.4) { FieldVector3D<Dfp> uds = createVector(x, y, z); checkVector(r1Prime.applyTo(uds), FieldRotation.applyTo(r1, uds)); checkVector(r1Prime.applyInverseTo(uds), FieldRotation.applyInverseTo(r1, uds)); checkVector(rA.applyTo(uds), rB.applyTo(uds)); checkVector(rA.applyInverseTo(uds), rB.applyInverseTo(uds)); checkVector(rC.applyTo(uds), rD.applyTo(uds)); checkVector(rC.applyInverseTo(uds), rD.applyInverseTo(uds)); } } } } }
Example 17
Source File: DerivativeStructureTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testLinearCombination2DoubleDS() { // we compare accurate versus naive dot product implementations // on regular vectors (i.e. not extreme cases like in the previous test) Well1024a random = new Well1024a(0xc6af886975069f11l); for (int i = 0; i < 10000; ++i) { final double[] u = new double[4]; final DerivativeStructure[] v = new DerivativeStructure[4]; for (int j = 0; j < u.length; ++j) { u[j] = 1e17 * random.nextDouble(); v[j] = new DerivativeStructure(u.length, 1, j, 1e17 * random.nextDouble()); } DerivativeStructure lin = v[0].linearCombination(u[0], v[0], u[1], v[1]); double ref = u[0] * v[0].getValue() + u[1] * v[1].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getPartialDerivative(1, 0, 0, 0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getPartialDerivative(0, 1, 0, 0), 1.0e-15 * FastMath.abs(v[1].getValue())); lin = v[0].linearCombination(u[0], v[0], u[1], v[1], u[2], v[2]); ref = u[0] * v[0].getValue() + u[1] * v[1].getValue() + u[2] * v[2].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getPartialDerivative(1, 0, 0, 0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getPartialDerivative(0, 1, 0, 0), 1.0e-15 * FastMath.abs(v[1].getValue())); Assert.assertEquals(u[2], lin.getPartialDerivative(0, 0, 1, 0), 1.0e-15 * FastMath.abs(v[2].getValue())); lin = v[0].linearCombination(u[0], v[0], u[1], v[1], u[2], v[2], u[3], v[3]); ref = u[0] * v[0].getValue() + u[1] * v[1].getValue() + u[2] * v[2].getValue() + u[3] * v[3].getValue(); Assert.assertEquals(ref, lin.getValue(), 1.0e-15 * FastMath.abs(ref)); Assert.assertEquals(u[0], lin.getPartialDerivative(1, 0, 0, 0), 1.0e-15 * FastMath.abs(v[0].getValue())); Assert.assertEquals(u[1], lin.getPartialDerivative(0, 1, 0, 0), 1.0e-15 * FastMath.abs(v[1].getValue())); Assert.assertEquals(u[2], lin.getPartialDerivative(0, 0, 1, 0), 1.0e-15 * FastMath.abs(v[2].getValue())); Assert.assertEquals(u[3], lin.getPartialDerivative(0, 0, 0, 1), 1.0e-15 * FastMath.abs(v[3].getValue())); } }
Example 18
Source File: FieldRotationDSTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testDoubleRotations() throws MathIllegalArgumentException { Well1024a random = new Well1024a(0x180b41cfeeffaf67l); UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random); for (int i = 0; i < 10; ++i) { double[] unit1 = g.nextVector(); Rotation r1 = new Rotation(new Vector3D(unit1[0], unit1[1], unit1[2]), random.nextDouble()); FieldRotation<DerivativeStructure> r1Prime = new FieldRotation<DerivativeStructure>(new DerivativeStructure(4, 1, 0, r1.getQ0()), new DerivativeStructure(4, 1, 1, r1.getQ1()), new DerivativeStructure(4, 1, 2, r1.getQ2()), new DerivativeStructure(4, 1, 3, r1.getQ3()), false); double[] unit2 = g.nextVector(); FieldRotation<DerivativeStructure> r2 = new FieldRotation<DerivativeStructure>(createVector(unit2[0], unit2[1], unit2[2]), createAngle(random.nextDouble())); FieldRotation<DerivativeStructure> rA = FieldRotation.applyTo(r1, r2); FieldRotation<DerivativeStructure> rB = r1Prime.applyTo(r2); FieldRotation<DerivativeStructure> rC = FieldRotation.applyInverseTo(r1, r2); FieldRotation<DerivativeStructure> rD = r1Prime.applyInverseTo(r2); for (double x = -0.9; x < 0.9; x += 0.2) { for (double y = -0.9; y < 0.9; y += 0.2) { for (double z = -0.9; z < 0.9; z += 0.2) { FieldVector3D<DerivativeStructure> uds = createVector(x, y, z); checkVector(r1Prime.applyTo(uds), FieldRotation.applyTo(r1, uds)); checkVector(r1Prime.applyInverseTo(uds), FieldRotation.applyInverseTo(r1, uds)); checkVector(rA.applyTo(uds), rB.applyTo(uds)); checkVector(rA.applyInverseTo(uds), rB.applyInverseTo(uds)); checkVector(rC.applyTo(uds), rD.applyTo(uds)); checkVector(rC.applyInverseTo(uds), rD.applyInverseTo(uds)); } } } } }
Example 19
Source File: FieldRotationDSTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testDoubleRotations() throws MathIllegalArgumentException { Well1024a random = new Well1024a(0x180b41cfeeffaf67l); UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random); for (int i = 0; i < 10; ++i) { double[] unit1 = g.nextVector(); Rotation r1 = new Rotation(new Vector3D(unit1[0], unit1[1], unit1[2]), random.nextDouble()); FieldRotation<DerivativeStructure> r1Prime = new FieldRotation<DerivativeStructure>(new DerivativeStructure(4, 1, 0, r1.getQ0()), new DerivativeStructure(4, 1, 1, r1.getQ1()), new DerivativeStructure(4, 1, 2, r1.getQ2()), new DerivativeStructure(4, 1, 3, r1.getQ3()), false); double[] unit2 = g.nextVector(); FieldRotation<DerivativeStructure> r2 = new FieldRotation<DerivativeStructure>(createVector(unit2[0], unit2[1], unit2[2]), createAngle(random.nextDouble())); FieldRotation<DerivativeStructure> rA = FieldRotation.applyTo(r1, r2); FieldRotation<DerivativeStructure> rB = r1Prime.applyTo(r2); FieldRotation<DerivativeStructure> rC = FieldRotation.applyInverseTo(r1, r2); FieldRotation<DerivativeStructure> rD = r1Prime.applyInverseTo(r2); for (double x = -0.9; x < 0.9; x += 0.2) { for (double y = -0.9; y < 0.9; y += 0.2) { for (double z = -0.9; z < 0.9; z += 0.2) { FieldVector3D<DerivativeStructure> uds = createVector(x, y, z); checkVector(r1Prime.applyTo(uds), FieldRotation.applyTo(r1, uds)); checkVector(r1Prime.applyInverseTo(uds), FieldRotation.applyInverseTo(r1, uds)); checkVector(rA.applyTo(uds), rB.applyTo(uds)); checkVector(rA.applyInverseTo(uds), rB.applyInverseTo(uds)); checkVector(rC.applyTo(uds), rD.applyTo(uds)); checkVector(rC.applyInverseTo(uds), rD.applyInverseTo(uds)); } } } } }
Example 20
Source File: FieldRotationDSTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testDoubleRotations() throws MathIllegalArgumentException { Well1024a random = new Well1024a(0x180b41cfeeffaf67l); UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random); for (int i = 0; i < 10; ++i) { double[] unit1 = g.nextVector(); Rotation r1 = new Rotation(new Vector3D(unit1[0], unit1[1], unit1[2]), random.nextDouble()); FieldRotation<DerivativeStructure> r1Prime = new FieldRotation<DerivativeStructure>(new DerivativeStructure(4, 1, 0, r1.getQ0()), new DerivativeStructure(4, 1, 1, r1.getQ1()), new DerivativeStructure(4, 1, 2, r1.getQ2()), new DerivativeStructure(4, 1, 3, r1.getQ3()), false); double[] unit2 = g.nextVector(); FieldRotation<DerivativeStructure> r2 = new FieldRotation<DerivativeStructure>(createVector(unit2[0], unit2[1], unit2[2]), createAngle(random.nextDouble())); FieldRotation<DerivativeStructure> rA = FieldRotation.applyTo(r1, r2); FieldRotation<DerivativeStructure> rB = r1Prime.applyTo(r2); FieldRotation<DerivativeStructure> rC = FieldRotation.applyInverseTo(r1, r2); FieldRotation<DerivativeStructure> rD = r1Prime.applyInverseTo(r2); for (double x = -0.9; x < 0.9; x += 0.2) { for (double y = -0.9; y < 0.9; y += 0.2) { for (double z = -0.9; z < 0.9; z += 0.2) { FieldVector3D<DerivativeStructure> uds = createVector(x, y, z); checkVector(r1Prime.applyTo(uds), FieldRotation.applyTo(r1, uds)); checkVector(r1Prime.applyInverseTo(uds), FieldRotation.applyInverseTo(r1, uds)); checkVector(rA.applyTo(uds), rB.applyTo(uds)); checkVector(rA.applyInverseTo(uds), rB.applyInverseTo(uds)); checkVector(rC.applyTo(uds), rD.applyTo(uds)); checkVector(rC.applyInverseTo(uds), rD.applyInverseTo(uds)); } } } } }