http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java index 4c87742..65f45a3 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D; import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixException; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.linear.MatrixUtils; import org.apache.commons.math4.linear.RealMatrix; import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator; @@ -975,7 +975,7 @@ public class FieldRotationDSTest { FieldVector3D<DerivativeStructure> uds = createVector(x, y, z); FieldVector3D<DerivativeStructure> ruds = r.applyTo(uds); FieldVector3D<DerivativeStructure> rIuds = r.applyInverseTo(uds); - Vector3D u = new Vector3D(x, y, z); + Coordinates3D u = new Coordinates3D(x, y, z); FieldVector3D<DerivativeStructure> ru = r.applyTo(u); FieldVector3D<DerivativeStructure> rIu = r.applyInverseTo(u); DerivativeStructure[] ruArray = new DerivativeStructure[3]; @@ -1000,7 +1000,7 @@ public class FieldRotationDSTest { 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]), + Rotation r1 = new Rotation(new Coordinates3D(unit1[0], unit1[1], unit1[2]), random.nextDouble(), RotationConvention.VECTOR_OPERATOR); FieldRotation<DerivativeStructure> r1Prime = new FieldRotation<>(new DerivativeStructure(4, 1, 0, r1.getQ0()), new DerivativeStructure(4, 1, 1, r1.getQ1()), @@ -1051,7 +1051,7 @@ public class FieldRotationDSTest { FieldRotation<DerivativeStructure> r = new FieldRotation<>(createAxis(kx, ky, kz), createAngle(theta), RotationConvention.VECTOR_OPERATOR); - Vector3D a = new Vector3D(kx / n, ky / n, kz / n); + Coordinates3D a = new Coordinates3D(kx / n, ky / n, kz / n); // Jacobian of the normalized rotation axis a with respect to the Cartesian vector k RealMatrix dadk = MatrixUtils.createRealMatrix(new double[][] { @@ -1063,15 +1063,15 @@ public class FieldRotationDSTest { 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) { - Vector3D u = new Vector3D(x, y, z); + Coordinates3D u = new Coordinates3D(x, y, z); FieldVector3D<DerivativeStructure> v = r.applyTo(createVector(x, y, z)); // explicit formula for rotation of vector u around axis a with angle theta - double dot = Vector3D.dotProduct(u, a); - Vector3D cross = Vector3D.crossProduct(a, u); + double dot = Coordinates3D.dotProduct(u, a); + Coordinates3D cross = Coordinates3D.crossProduct(a, u); double c1 = 1 - cosTheta; double c2 = c1 * dot; - Vector3D rt = new Vector3D(cosTheta, u, c2, a, sinTheta, cross); + Coordinates3D rt = new Coordinates3D(cosTheta, u, c2, a, sinTheta, cross); Assert.assertEquals(rt.getX(), v.getX().getReal(), eps); Assert.assertEquals(rt.getY(), v.getY().getReal(), eps); Assert.assertEquals(rt.getZ(), v.getZ().getReal(), eps); @@ -1100,8 +1100,8 @@ public class FieldRotationDSTest { // derivative with respect to rotation angle // (analytical differentiation of the explicit formula) - Vector3D dvdTheta = - new Vector3D(-sinTheta, u, sinTheta * dot, a, cosTheta, cross); + Coordinates3D dvdTheta = + new Coordinates3D(-sinTheta, u, sinTheta * dot, a, cosTheta, cross); Assert.assertEquals(dvdTheta.getX(), v.getX().getPartialDerivative(0, 0, 0, 1), eps); Assert.assertEquals(dvdTheta.getY(), v.getY().getPartialDerivative(0, 0, 0, 1), eps); Assert.assertEquals(dvdTheta.getZ(), v.getZ().getPartialDerivative(0, 0, 0, 1), eps);
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java index 5377bff..4e250c0 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D; import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixException; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; @@ -816,7 +816,7 @@ public class FieldRotationDfpTest { FieldVector3D<Dfp> uds = createVector(x, y, z); FieldVector3D<Dfp> ruds = r.applyTo(uds); FieldVector3D<Dfp> rIuds = r.applyInverseTo(uds); - Vector3D u = new Vector3D(x, y, z); + Coordinates3D u = new Coordinates3D(x, y, z); FieldVector3D<Dfp> ru = r.applyTo(u); FieldVector3D<Dfp> rIu = r.applyInverseTo(u); Dfp[] ruArray = new Dfp[3]; @@ -842,7 +842,7 @@ public class FieldRotationDfpTest { 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]), + Rotation r1 = new Rotation(new Coordinates3D(unit1[0], unit1[1], unit1[2]), random.nextDouble(), RotationConvention.VECTOR_OPERATOR); FieldRotation<Dfp> r1Prime = new FieldRotation<>(field.newDfp(r1.getQ0()), field.newDfp(r1.getQ1()), http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java index e832ea8..7728b96 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.exception.DimensionMismatchException; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.util.FastMath; @@ -59,7 +59,7 @@ public class FieldVector3DTest { createVector(1, 0, 0, 4)), 2, 0, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0, 0, 2, 0); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Vector3D(1, 0, 0)), + new Coordinates3D(1, 0, 0)), 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -71,9 +71,9 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 0, 3, -1, 0, 0, 1, 0, -1, 0, 0, 0, 0, -1, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Vector3D(1, 0, 0), + new Coordinates3D(1, 0, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Vector3D(0, 0, -1)), + new Coordinates3D(0, 0, -1)), 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -88,11 +88,11 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 5, 3, 4, 0, 0, 1, 0, 4, 0, 1, 0, 0, 4, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Vector3D(1, 0, 0), + new Coordinates3D(1, 0, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Vector3D(0, 1, 0), + new Coordinates3D(0, 1, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Vector3D(0, 0, -1)), + new Coordinates3D(0, 0, -1)), 2, 5, 3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, -1); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -110,13 +110,13 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 0, 3, 9, 0, 0, 1, 0, 9, 0, 0, 0, 0, 9, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Vector3D(1, 0, 0), + new Coordinates3D(1, 0, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Vector3D(0, 1, 0), + new Coordinates3D(0, 1, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Vector3D(0, -1, 0), + new Coordinates3D(0, -1, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Vector3D(0, 0, -1)), + new Coordinates3D(0, 0, -1)), 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1); checkVector(new FieldVector3D<>(new DerivativeStructure[] { @@ -270,12 +270,12 @@ public class FieldVector3DTest { Assert.assertEquals(0, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12); - distance = FieldVector3D.distance1(v1, new Vector3D(-4, 2, 0)); + distance = FieldVector3D.distance1(v1, new Coordinates3D(-4, 2, 0)); Assert.assertEquals(12.0, distance.getReal(), 1.0e-12); Assert.assertEquals( 1, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(-1, distance.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals( 1, distance.getPartialDerivative(0, 0, 1), 1.0e-12); - distance = FieldVector3D.distance1(new Vector3D(-4, 2, 0), v1); + distance = FieldVector3D.distance1(new Coordinates3D(-4, 2, 0), v1); Assert.assertEquals(12.0, distance.getReal(), 1.0e-12); Assert.assertEquals( 1, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(-1, distance.getPartialDerivative(0, 1, 0), 1.0e-12); @@ -292,12 +292,12 @@ public class FieldVector3DTest { Assert.assertEquals(0, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12); - distance = FieldVector3D.distance(v1, new Vector3D(-4, 2, 0)); + distance = FieldVector3D.distance(v1, new Coordinates3D(-4, 2, 0)); Assert.assertEquals(FastMath.sqrt(50), distance.getReal(), 1.0e-12); Assert.assertEquals( 5 / FastMath.sqrt(50), distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(-4 / FastMath.sqrt(50), distance.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals( 3 / FastMath.sqrt(50), distance.getPartialDerivative(0, 0, 1), 1.0e-12); - distance = FieldVector3D.distance(new Vector3D(-4, 2, 0), v1); + distance = FieldVector3D.distance(new Coordinates3D(-4, 2, 0), v1); Assert.assertEquals(FastMath.sqrt(50), distance.getReal(), 1.0e-12); Assert.assertEquals( 5 / FastMath.sqrt(50), distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(-4 / FastMath.sqrt(50), distance.getPartialDerivative(0, 1, 0), 1.0e-12); @@ -314,12 +314,12 @@ public class FieldVector3DTest { Assert.assertEquals(0, distanceSq.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(0, distanceSq.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals(0, distanceSq.getPartialDerivative(0, 0, 1), 1.0e-12); - distanceSq = FieldVector3D.distanceSq(v1, new Vector3D(-4, 2, 0)); + distanceSq = FieldVector3D.distanceSq(v1, new Coordinates3D(-4, 2, 0)); Assert.assertEquals(50.0, distanceSq.getReal(), 1.0e-12); Assert.assertEquals(10, distanceSq.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(-8, distanceSq.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals( 6, distanceSq.getPartialDerivative(0, 0, 1), 1.0e-12); - distanceSq = FieldVector3D.distanceSq(new Vector3D(-4, 2, 0), v1); + distanceSq = FieldVector3D.distanceSq(new Coordinates3D(-4, 2, 0), v1); Assert.assertEquals(50.0, distanceSq.getReal(), 1.0e-12); Assert.assertEquals(10, distanceSq.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(-8, distanceSq.getPartialDerivative(0, 1, 0), 1.0e-12); @@ -336,12 +336,12 @@ public class FieldVector3DTest { Assert.assertEquals(0, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12); - distance = FieldVector3D.distanceInf(v1, new Vector3D(-4, 2, 0)); + distance = FieldVector3D.distanceInf(v1, new Coordinates3D(-4, 2, 0)); Assert.assertEquals(5.0, distance.getReal(), 1.0e-12); Assert.assertEquals(1, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 0, 1), 1.0e-12); - distance = FieldVector3D.distanceInf(new Vector3D(-4, 2, 0), v1); + distance = FieldVector3D.distanceInf(new Coordinates3D(-4, 2, 0), v1); Assert.assertEquals(5.0, distance.getReal(), 1.0e-12); Assert.assertEquals(1, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12); @@ -368,22 +368,22 @@ public class FieldVector3DTest { 1.0e-12); Assert.assertEquals(5.0, - FieldVector3D.distanceInf(createVector( 1, -2, 3, 3), new Vector3D(-4, 2, 0)).getReal(), + FieldVector3D.distanceInf(createVector( 1, -2, 3, 3), new Coordinates3D(-4, 2, 0)).getReal(), 1.0e-12); Assert.assertEquals(5.0, - FieldVector3D.distanceInf(createVector( 1, 3, -2, 3), new Vector3D(-4, 0, 2)).getReal(), + FieldVector3D.distanceInf(createVector( 1, 3, -2, 3), new Coordinates3D(-4, 0, 2)).getReal(), 1.0e-12); Assert.assertEquals(5.0, - FieldVector3D.distanceInf(createVector(-2, 1, 3, 3), new Vector3D( 2, -4, 0)).getReal(), + FieldVector3D.distanceInf(createVector(-2, 1, 3, 3), new Coordinates3D( 2, -4, 0)).getReal(), 1.0e-12); Assert.assertEquals(5.0, - FieldVector3D.distanceInf(createVector(-2, 3, 1, 3), new Vector3D( 2, 0, -4)).getReal(), + FieldVector3D.distanceInf(createVector(-2, 3, 1, 3), new Coordinates3D( 2, 0, -4)).getReal(), 1.0e-12); Assert.assertEquals(5.0, - FieldVector3D.distanceInf(createVector(3, -2, 1, 3), new Vector3D(0, 2, -4)).getReal(), + FieldVector3D.distanceInf(createVector(3, -2, 1, 3), new Coordinates3D(0, 2, -4)).getReal(), 1.0e-12); Assert.assertEquals(5.0, - FieldVector3D.distanceInf(createVector(3, 1, -2, 3), new Vector3D(0, -4, 2)).getReal(), + FieldVector3D.distanceInf(createVector(3, 1, -2, 3), new Coordinates3D(0, -4, 2)).getReal(), 1.0e-12); } @@ -396,10 +396,10 @@ public class FieldVector3DTest { checkVector(v1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0); checkVector(v2.subtract(v1), -7, -6, -5, 1, 0, 0, 0, 1, 0, 0, 0, 1); - checkVector(v2.subtract(new Vector3D(4, 4, 4)), -7, -6, -5, 1, 0, 0, 0, 1, 0, 0, 0, 1); + checkVector(v2.subtract(new Coordinates3D(4, 4, 4)), -7, -6, -5, 1, 0, 0, 0, 1, 0, 0, 0, 1); checkVector(v2.subtract(3, v1), -15, -14, -13, 1, 0, 0, 0, 1, 0, 0, 0, 1); - checkVector(v2.subtract(3, new Vector3D(4, 4, 4)), -15, -14, -13, 1, 0, 0, 0, 1, 0, 0, 0, 1); - checkVector(v2.subtract(new DerivativeStructure(3, 1, 2, 3), new Vector3D(4, 4, 4)), + checkVector(v2.subtract(3, new Coordinates3D(4, 4, 4)), -15, -14, -13, 1, 0, 0, 0, 1, 0, 0, 0, 1); + checkVector(v2.subtract(new DerivativeStructure(3, 1, 2, 3), new Coordinates3D(4, 4, 4)), -15, -14, -13, 1, 0, -4, 0, 1, -4, 0, 0, -3); checkVector(createVector(1, 2, 3, 4).subtract(new DerivativeStructure(4, 1, 3, 5.0), @@ -419,10 +419,10 @@ public class FieldVector3DTest { checkVector(v1, -2, 0, 2, 2, 0, 0, 0, 2, 0, 0, 0, 2); checkVector(v2.add(v1), -5, -2, 1, 3, 0, 0, 0, 3, 0, 0, 0, 3); - checkVector(v2.add(new Vector3D(-2, 0, 2)), -5, -2, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1); + checkVector(v2.add(new Coordinates3D(-2, 0, 2)), -5, -2, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1); checkVector(v2.add(3, v1), -9, -2, 5, 7, 0, 0, 0, 7, 0, 0, 0, 7); - checkVector(v2.add(3, new Vector3D(-2, 0, 2)), -9, -2, 5, 1, 0, 0, 0, 1, 0, 0, 0, 1); - checkVector(v2.add(new DerivativeStructure(3, 1, 2, 3), new Vector3D(-2, 0, 2)), + checkVector(v2.add(3, new Coordinates3D(-2, 0, 2)), -9, -2, 5, 1, 0, 0, 0, 1, 0, 0, 0, 1); + checkVector(v2.add(new DerivativeStructure(3, 1, 2, 3), new Coordinates3D(-2, 0, 2)), -9, -2, 5, 1, 0, -2, 0, 1, 0, 0, 0, 3); checkVector(createVector(1, 2, 3, 4).add(new DerivativeStructure(4, 1, 3, 5.0), @@ -508,7 +508,7 @@ public class FieldVector3DTest { Assert.assertTrue(FastMath.abs(FieldVector3D.angle(v1.toVector3D(), v2).getReal() - 1.2) < 1.0e-12); try { - FieldVector3D.angle(v1, Vector3D.ZERO); + FieldVector3D.angle(v1, Coordinates3D.ZERO); Assert.fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected @@ -605,7 +605,7 @@ public class FieldVector3DTest { FieldVector3D<DerivativeStructure> uds = createVector(ux, uy, uz, 3); FieldVector3D<DerivativeStructure> vds = createVector(vx, vy, vz, 3); - Vector3D v = new Vector3D(vx, vy, vz); + Coordinates3D v = new Coordinates3D(vx, vy, vz); DerivativeStructure sAccurate = FieldVector3D.dotProduct(uds, vds); Assert.assertEquals(sNaive, sAccurate.getReal(), 2.5e-16 * sNaive); @@ -658,11 +658,11 @@ public class FieldVector3DTest { double vx = random.nextDouble(); double vy = random.nextDouble(); double vz = random.nextDouble(); - Vector3D cNaive = new Vector3D(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx); + Coordinates3D cNaive = new Coordinates3D(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx); FieldVector3D<DerivativeStructure> uds = createVector(ux, uy, uz, 3); FieldVector3D<DerivativeStructure> vds = createVector(vx, vy, vz, 3); - Vector3D v = new Vector3D(vx, vy, vz); + Coordinates3D v = new Coordinates3D(vx, vy, vz); checkVector(FieldVector3D.crossProduct(uds, vds), cNaive.getX(), cNaive.getY(), cNaive.getZ(), http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/LineTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/LineTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/LineTest.java index ad03bfa..16688c9 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/LineTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/LineTest.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.geometry.euclidean.threed; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.geometry.euclidean.threed.Line; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -28,22 +28,22 @@ public class LineTest { @Test public void testContains() throws MathIllegalArgumentException, MathArithmeticException { - Vector3D p1 = new Vector3D(0, 0, 1); - Line l = new Line(p1, new Vector3D(0, 0, 2), 1.0e-10); + Coordinates3D p1 = new Coordinates3D(0, 0, 1); + Line l = new Line(p1, new Coordinates3D(0, 0, 2), 1.0e-10); Assert.assertTrue(l.contains(p1)); - Assert.assertTrue(l.contains(new Vector3D(1.0, p1, 0.3, l.getDirection()))); - Vector3D u = l.getDirection().orthogonal(); - Vector3D v = Vector3D.crossProduct(l.getDirection(), u); + Assert.assertTrue(l.contains(new Coordinates3D(1.0, p1, 0.3, l.getDirection()))); + Coordinates3D u = l.getDirection().orthogonal(); + Coordinates3D v = Coordinates3D.crossProduct(l.getDirection(), u); for (double alpha = 0; alpha < 2 * FastMath.PI; alpha += 0.3) { - Assert.assertTrue(! l.contains(p1.add(new Vector3D(FastMath.cos(alpha), u, + Assert.assertTrue(! l.contains(p1.add(new Coordinates3D(FastMath.cos(alpha), u, FastMath.sin(alpha), v)))); } } @Test public void testSimilar() throws MathIllegalArgumentException, MathArithmeticException { - Vector3D p1 = new Vector3D (1.2, 3.4, -5.8); - Vector3D p2 = new Vector3D (3.4, -5.8, 1.2); + Coordinates3D p1 = new Coordinates3D (1.2, 3.4, -5.8); + Coordinates3D p2 = new Coordinates3D (3.4, -5.8, 1.2); Line lA = new Line(p1, p2, 1.0e-10); Line lB = new Line(p2, p1, 1.0e-10); Assert.assertTrue(lA.isSimilarTo(lB)); @@ -52,91 +52,91 @@ public class LineTest { @Test public void testPointDistance() throws MathIllegalArgumentException { - Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2), 1.0e-10); - Assert.assertEquals(FastMath.sqrt(3.0 / 2.0), l.distance(new Vector3D(1, 0, 1)), 1.0e-10); - Assert.assertEquals(0, l.distance(new Vector3D(0, -4, -4)), 1.0e-10); + Line l = new Line(new Coordinates3D(0, 1, 1), new Coordinates3D(0, 2, 2), 1.0e-10); + Assert.assertEquals(FastMath.sqrt(3.0 / 2.0), l.distance(new Coordinates3D(1, 0, 1)), 1.0e-10); + Assert.assertEquals(0, l.distance(new Coordinates3D(0, -4, -4)), 1.0e-10); } @Test public void testLineDistance() throws MathIllegalArgumentException { - Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2), 1.0e-10); + Line l = new Line(new Coordinates3D(0, 1, 1), new Coordinates3D(0, 2, 2), 1.0e-10); Assert.assertEquals(1.0, - l.distance(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2), 1.0e-10)), + l.distance(new Line(new Coordinates3D(1, 0, 1), new Coordinates3D(1, 0, 2), 1.0e-10)), 1.0e-10); Assert.assertEquals(0.5, - l.distance(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1), 1.0e-10)), + l.distance(new Line(new Coordinates3D(-0.5, 0, 0), new Coordinates3D(-0.5, -1, -1), 1.0e-10)), 1.0e-10); Assert.assertEquals(0.0, l.distance(l), 1.0e-10); Assert.assertEquals(0.0, - l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5), 1.0e-10)), + l.distance(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(0, -5, -5), 1.0e-10)), 1.0e-10); Assert.assertEquals(0.0, - l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4), 1.0e-10)), + l.distance(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(0, -3, -4), 1.0e-10)), 1.0e-10); Assert.assertEquals(0.0, - l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4), 1.0e-10)), + l.distance(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(1, -4, -4), 1.0e-10)), 1.0e-10); Assert.assertEquals(FastMath.sqrt(8), - l.distance(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0), 1.0e-10)), + l.distance(new Line(new Coordinates3D(0, -4, 0), new Coordinates3D(1, -4, 0), 1.0e-10)), 1.0e-10); } @Test public void testClosest() throws MathIllegalArgumentException { - Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2), 1.0e-10); + Line l = new Line(new Coordinates3D(0, 1, 1), new Coordinates3D(0, 2, 2), 1.0e-10); Assert.assertEquals(0.0, - l.closestPoint(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2), 1.0e-10)).distance(new Vector3D(0, 0, 0)), + l.closestPoint(new Line(new Coordinates3D(1, 0, 1), new Coordinates3D(1, 0, 2), 1.0e-10)).distance(new Coordinates3D(0, 0, 0)), 1.0e-10); Assert.assertEquals(0.5, - l.closestPoint(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1), 1.0e-10)).distance(new Vector3D(-0.5, 0, 0)), + l.closestPoint(new Line(new Coordinates3D(-0.5, 0, 0), new Coordinates3D(-0.5, -1, -1), 1.0e-10)).distance(new Coordinates3D(-0.5, 0, 0)), 1.0e-10); Assert.assertEquals(0.0, - l.closestPoint(l).distance(new Vector3D(0, 0, 0)), + l.closestPoint(l).distance(new Coordinates3D(0, 0, 0)), 1.0e-10); Assert.assertEquals(0.0, - l.closestPoint(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5), 1.0e-10)).distance(new Vector3D(0, 0, 0)), + l.closestPoint(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(0, -5, -5), 1.0e-10)).distance(new Coordinates3D(0, 0, 0)), 1.0e-10); Assert.assertEquals(0.0, - l.closestPoint(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4), 1.0e-10)).distance(new Vector3D(0, -4, -4)), + l.closestPoint(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(0, -3, -4), 1.0e-10)).distance(new Coordinates3D(0, -4, -4)), 1.0e-10); Assert.assertEquals(0.0, - l.closestPoint(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4), 1.0e-10)).distance(new Vector3D(0, -4, -4)), + l.closestPoint(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(1, -4, -4), 1.0e-10)).distance(new Coordinates3D(0, -4, -4)), 1.0e-10); Assert.assertEquals(0.0, - l.closestPoint(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0), 1.0e-10)).distance(new Vector3D(0, -2, -2)), + l.closestPoint(new Line(new Coordinates3D(0, -4, 0), new Coordinates3D(1, -4, 0), 1.0e-10)).distance(new Coordinates3D(0, -2, -2)), 1.0e-10); } @Test public void testIntersection() throws MathIllegalArgumentException { - Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2), 1.0e-10); - Assert.assertNull(l.intersection(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2), 1.0e-10))); - Assert.assertNull(l.intersection(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1), 1.0e-10))); + Line l = new Line(new Coordinates3D(0, 1, 1), new Coordinates3D(0, 2, 2), 1.0e-10); + Assert.assertNull(l.intersection(new Line(new Coordinates3D(1, 0, 1), new Coordinates3D(1, 0, 2), 1.0e-10))); + Assert.assertNull(l.intersection(new Line(new Coordinates3D(-0.5, 0, 0), new Coordinates3D(-0.5, -1, -1), 1.0e-10))); Assert.assertEquals(0.0, - l.intersection(l).distance(new Vector3D(0, 0, 0)), + l.intersection(l).distance(new Coordinates3D(0, 0, 0)), 1.0e-10); Assert.assertEquals(0.0, - l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5), 1.0e-10)).distance(new Vector3D(0, 0, 0)), + l.intersection(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(0, -5, -5), 1.0e-10)).distance(new Coordinates3D(0, 0, 0)), 1.0e-10); Assert.assertEquals(0.0, - l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4), 1.0e-10)).distance(new Vector3D(0, -4, -4)), + l.intersection(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(0, -3, -4), 1.0e-10)).distance(new Coordinates3D(0, -4, -4)), 1.0e-10); Assert.assertEquals(0.0, - l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4), 1.0e-10)).distance(new Vector3D(0, -4, -4)), + l.intersection(new Line(new Coordinates3D(0, -4, -4), new Coordinates3D(1, -4, -4), 1.0e-10)).distance(new Coordinates3D(0, -4, -4)), 1.0e-10); - Assert.assertNull(l.intersection(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0), 1.0e-10))); + Assert.assertNull(l.intersection(new Line(new Coordinates3D(0, -4, 0), new Coordinates3D(1, -4, 0), 1.0e-10))); } @Test public void testRevert() { // setup - Line line = new Line(new Vector3D(1653345.6696423641, 6170370.041579291, 90000), - new Vector3D(1650757.5050732433, 6160710.879908984, 0.9), + Line line = new Line(new Coordinates3D(1653345.6696423641, 6170370.041579291, 90000), + new Coordinates3D(1650757.5050732433, 6160710.879908984, 0.9), 1.0e-10); - Vector3D expected = line.getDirection().negate(); + Coordinates3D expected = line.getDirection().negate(); // action Line reverted = line.revert(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PLYParser.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PLYParser.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PLYParser.java index 7670e69..5439d8d 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PLYParser.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PLYParser.java @@ -40,7 +40,7 @@ import org.apache.commons.math4.util.Precision; public class PLYParser { /** Parsed vertices. */ - private Vector3D[] vertices; + private Coordinates3D[] vertices; /** Parsed faces. */ private int[][] faces; @@ -167,7 +167,7 @@ public class PLYParser { ++vPropertiesNumber; // parse vertices - vertices = new Vector3D[nbVertices]; + vertices = new Coordinates3D[nbVertices]; for (int i = 0; i < nbVertices; ++i) { fields = parseNextLine(); if (fields.size() != vPropertiesNumber || @@ -176,7 +176,7 @@ public class PLYParser { fields.get(zIndex).getToken() != Token.UNKNOWN) { complain(); } - vertices[i] = new Vector3D(Double.parseDouble(fields.get(xIndex).getValue()), + vertices[i] = new Coordinates3D(Double.parseDouble(fields.get(xIndex).getValue()), Double.parseDouble(fields.get(yIndex).getValue()), Double.parseDouble(fields.get(zIndex).getValue())); } @@ -229,7 +229,7 @@ public class PLYParser { /** Get the parsed vertices. * @return parsed vertices */ - public List<Vector3D> getVertices() { + public List<Coordinates3D> getVertices() { return Arrays.asList(vertices); } http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PlaneTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PlaneTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PlaneTest.java index 3991a10..53de398 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PlaneTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PlaneTest.java @@ -21,7 +21,7 @@ import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.geometry.euclidean.threed.Line; import org.apache.commons.math4.geometry.euclidean.threed.Plane; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.junit.Assert; import org.junit.Test; @@ -29,37 +29,37 @@ public class PlaneTest { @Test public void testContains() throws MathArithmeticException { - Plane p = new Plane(new Vector3D(0, 0, 1), new Vector3D(0, 0, 1), 1.0e-10); - Assert.assertTrue(p.contains(new Vector3D(0, 0, 1))); - Assert.assertTrue(p.contains(new Vector3D(17, -32, 1))); - Assert.assertTrue(! p.contains(new Vector3D(17, -32, 1.001))); + Plane p = new Plane(new Coordinates3D(0, 0, 1), new Coordinates3D(0, 0, 1), 1.0e-10); + Assert.assertTrue(p.contains(new Coordinates3D(0, 0, 1))); + Assert.assertTrue(p.contains(new Coordinates3D(17, -32, 1))); + Assert.assertTrue(! p.contains(new Coordinates3D(17, -32, 1.001))); } @Test public void testOffset() throws MathArithmeticException { - Vector3D p1 = new Vector3D(1, 1, 1); - Plane p = new Plane(p1, new Vector3D(0.2, 0, 0), 1.0e-10); - Assert.assertEquals(-5.0, p.getOffset(new Vector3D(-4, 0, 0)), 1.0e-10); - Assert.assertEquals(+5.0, p.getOffset(new Vector3D(6, 10, -12)), 1.0e-10); + Coordinates3D p1 = new Coordinates3D(1, 1, 1); + Plane p = new Plane(p1, new Coordinates3D(0.2, 0, 0), 1.0e-10); + Assert.assertEquals(-5.0, p.getOffset(new Coordinates3D(-4, 0, 0)), 1.0e-10); + Assert.assertEquals(+5.0, p.getOffset(new Coordinates3D(6, 10, -12)), 1.0e-10); Assert.assertEquals(0.3, - p.getOffset(new Vector3D(1.0, p1, 0.3, p.getNormal())), + p.getOffset(new Coordinates3D(1.0, p1, 0.3, p.getNormal())), 1.0e-10); Assert.assertEquals(-0.3, - p.getOffset(new Vector3D(1.0, p1, -0.3, p.getNormal())), + p.getOffset(new Coordinates3D(1.0, p1, -0.3, p.getNormal())), 1.0e-10); } @Test public void testPoint() throws MathArithmeticException { - Plane p = new Plane(new Vector3D(2, -3, 1), new Vector3D(1, 4, 9), 1.0e-10); + Plane p = new Plane(new Coordinates3D(2, -3, 1), new Coordinates3D(1, 4, 9), 1.0e-10); Assert.assertTrue(p.contains(p.getOrigin())); } @Test public void testThreePoints() throws MathArithmeticException { - Vector3D p1 = new Vector3D(1.2, 3.4, -5.8); - Vector3D p2 = new Vector3D(3.4, -5.8, 1.2); - Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7); + Coordinates3D p1 = new Coordinates3D(1.2, 3.4, -5.8); + Coordinates3D p2 = new Coordinates3D(3.4, -5.8, 1.2); + Coordinates3D p3 = new Coordinates3D(-2.0, 4.3, 0.7); Plane p = new Plane(p1, p2, p3, 1.0e-10); Assert.assertTrue(p.contains(p1)); Assert.assertTrue(p.contains(p2)); @@ -68,11 +68,11 @@ public class PlaneTest { @Test public void testRotate() throws MathArithmeticException, MathIllegalArgumentException { - Vector3D p1 = new Vector3D(1.2, 3.4, -5.8); - Vector3D p2 = new Vector3D(3.4, -5.8, 1.2); - Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7); + Coordinates3D p1 = new Coordinates3D(1.2, 3.4, -5.8); + Coordinates3D p2 = new Coordinates3D(3.4, -5.8, 1.2); + Coordinates3D p3 = new Coordinates3D(-2.0, 4.3, 0.7); Plane p = new Plane(p1, p2, p3, 1.0e-10); - Vector3D oldNormal = p.getNormal(); + Coordinates3D oldNormal = p.getNormal(); p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7, RotationConvention.VECTOR_OPERATOR)); Assert.assertTrue(p.contains(p1)); @@ -93,22 +93,22 @@ public class PlaneTest { @Test public void testTranslate() throws MathArithmeticException { - Vector3D p1 = new Vector3D(1.2, 3.4, -5.8); - Vector3D p2 = new Vector3D(3.4, -5.8, 1.2); - Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7); + Coordinates3D p1 = new Coordinates3D(1.2, 3.4, -5.8); + Coordinates3D p2 = new Coordinates3D(3.4, -5.8, 1.2); + Coordinates3D p3 = new Coordinates3D(-2.0, 4.3, 0.7); Plane p = new Plane(p1, p2, p3, 1.0e-10); - p = p.translate(new Vector3D(2.0, p.getU(), -1.5, p.getV())); + p = p.translate(new Coordinates3D(2.0, p.getU(), -1.5, p.getV())); Assert.assertTrue(p.contains(p1)); Assert.assertTrue(p.contains(p2)); Assert.assertTrue(p.contains(p3)); - p = p.translate(new Vector3D(-1.2, p.getNormal())); + p = p.translate(new Coordinates3D(-1.2, p.getNormal())); Assert.assertTrue(! p.contains(p1)); Assert.assertTrue(! p.contains(p2)); Assert.assertTrue(! p.contains(p3)); - p = p.translate(new Vector3D(+1.2, p.getNormal())); + p = p.translate(new Coordinates3D(+1.2, p.getNormal())); Assert.assertTrue(p.contains(p1)); Assert.assertTrue(p.contains(p2)); Assert.assertTrue(p.contains(p3)); @@ -117,22 +117,22 @@ public class PlaneTest { @Test public void testIntersection() throws MathArithmeticException, MathIllegalArgumentException { - Plane p = new Plane(new Vector3D(1, 2, 3), new Vector3D(-4, 1, -5), 1.0e-10); - Line l = new Line(new Vector3D(0.2, -3.5, 0.7), new Vector3D(1.2, -2.5, -0.3), 1.0e-10); - Vector3D point = p.intersection(l); + Plane p = new Plane(new Coordinates3D(1, 2, 3), new Coordinates3D(-4, 1, -5), 1.0e-10); + Line l = new Line(new Coordinates3D(0.2, -3.5, 0.7), new Coordinates3D(1.2, -2.5, -0.3), 1.0e-10); + Coordinates3D point = p.intersection(l); Assert.assertTrue(p.contains(point)); Assert.assertTrue(l.contains(point)); - Assert.assertNull(p.intersection(new Line(new Vector3D(10, 10, 10), - new Vector3D(10, 10, 10).add(p.getNormal().orthogonal()), + Assert.assertNull(p.intersection(new Line(new Coordinates3D(10, 10, 10), + new Coordinates3D(10, 10, 10).add(p.getNormal().orthogonal()), 1.0e-10))); } @Test public void testIntersection2() throws MathArithmeticException { - Vector3D p1 = new Vector3D (1.2, 3.4, -5.8); - Vector3D p2 = new Vector3D (3.4, -5.8, 1.2); - Plane pA = new Plane(p1, p2, new Vector3D (-2.0, 4.3, 0.7), 1.0e-10); - Plane pB = new Plane(p1, new Vector3D (11.4, -3.8, 5.1), p2, 1.0e-10); + Coordinates3D p1 = new Coordinates3D (1.2, 3.4, -5.8); + Coordinates3D p2 = new Coordinates3D (3.4, -5.8, 1.2); + Plane pA = new Plane(p1, p2, new Coordinates3D (-2.0, 4.3, 0.7), 1.0e-10); + Plane pB = new Plane(p1, new Coordinates3D (11.4, -3.8, 5.1), p2, 1.0e-10); Line l = pA.intersection(pB); Assert.assertTrue(l.contains(p1)); Assert.assertTrue(l.contains(p2)); @@ -141,11 +141,11 @@ public class PlaneTest { @Test public void testIntersection3() throws MathArithmeticException { - Vector3D reference = new Vector3D (1.2, 3.4, -5.8); - Plane p1 = new Plane(reference, new Vector3D(1, 3, 3), 1.0e-10); - Plane p2 = new Plane(reference, new Vector3D(-2, 4, 0), 1.0e-10); - Plane p3 = new Plane(reference, new Vector3D(7, 0, -4), 1.0e-10); - Vector3D p = Plane.intersection(p1, p2, p3); + Coordinates3D reference = new Coordinates3D (1.2, 3.4, -5.8); + Plane p1 = new Plane(reference, new Coordinates3D(1, 3, 3), 1.0e-10); + Plane p2 = new Plane(reference, new Coordinates3D(-2, 4, 0), 1.0e-10); + Plane p3 = new Plane(reference, new Coordinates3D(7, 0, -4), 1.0e-10); + Coordinates3D p = Plane.intersection(p1, p2, p3); Assert.assertEquals(reference.getX(), p.getX(), 1.0e-10); Assert.assertEquals(reference.getY(), p.getY(), 1.0e-10); Assert.assertEquals(reference.getZ(), p.getZ(), 1.0e-10); @@ -153,15 +153,15 @@ public class PlaneTest { @Test public void testSimilar() throws MathArithmeticException { - Vector3D p1 = new Vector3D (1.2, 3.4, -5.8); - Vector3D p2 = new Vector3D (3.4, -5.8, 1.2); - Vector3D p3 = new Vector3D (-2.0, 4.3, 0.7); + Coordinates3D p1 = new Coordinates3D (1.2, 3.4, -5.8); + Coordinates3D p2 = new Coordinates3D (3.4, -5.8, 1.2); + Coordinates3D p3 = new Coordinates3D (-2.0, 4.3, 0.7); Plane pA = new Plane(p1, p2, p3, 1.0e-10); - Plane pB = new Plane(p1, new Vector3D (11.4, -3.8, 5.1), p2, 1.0e-10); + Plane pB = new Plane(p1, new Coordinates3D (11.4, -3.8, 5.1), p2, 1.0e-10); Assert.assertTrue(! pA.isSimilarTo(pB)); Assert.assertTrue(pA.isSimilarTo(pA)); Assert.assertTrue(pA.isSimilarTo(new Plane(p1, p3, p2, 1.0e-10))); - Vector3D shift = new Vector3D(0.3, pA.getNormal()); + Coordinates3D shift = new Coordinates3D(0.3, pA.getNormal()); Assert.assertTrue(! pA.isSimilarTo(new Plane(p1.add(shift), p3.add(shift), p2.add(shift), http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java index 8e1bd32..73b1168 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java @@ -37,11 +37,11 @@ import org.apache.commons.math4.geometry.euclidean.threed.Plane; import org.apache.commons.math4.geometry.euclidean.threed.PolyhedronsSet; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.geometry.euclidean.threed.SubPlane; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D; import org.apache.commons.math4.geometry.euclidean.twod.PolygonsSet; import org.apache.commons.math4.geometry.euclidean.twod.SubLine; -import org.apache.commons.math4.geometry.euclidean.twod.Vector2D; +import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; import org.apache.commons.math4.geometry.partitioning.BSPTree; import org.apache.commons.math4.geometry.partitioning.BSPTreeVisitor; import org.apache.commons.math4.geometry.partitioning.BoundaryAttribute; @@ -63,7 +63,7 @@ public class PolyhedronsSetTest { PolyhedronsSet tree = new PolyhedronsSet(0, 1, 0, 1, 0, 1, 1.0e-10); Assert.assertEquals(1.0, tree.getSize(), 1.0e-10); Assert.assertEquals(6.0, tree.getBoundarySize(), 1.0e-10); - Vector3D barycenter = (Vector3D) tree.getBarycenter(); + Coordinates3D barycenter = (Coordinates3D) tree.getBarycenter(); Assert.assertEquals(0.5, barycenter.getX(), 1.0e-10); Assert.assertEquals(0.5, barycenter.getY(), 1.0e-10); Assert.assertEquals(0.5, barycenter.getZ(), 1.0e-10); @@ -75,34 +75,34 @@ public class PolyhedronsSetTest { boolean zOK = (z >= 0.0) && (z <= 1.0); Region.Location expected = (xOK && yOK && zOK) ? Region.Location.INSIDE : Region.Location.OUTSIDE; - Assert.assertEquals(expected, tree.checkPoint(new Vector3D(x, y, z))); + Assert.assertEquals(expected, tree.checkPoint(new Coordinates3D(x, y, z))); } } } - checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] { - new Vector3D(0.0, 0.5, 0.5), - new Vector3D(1.0, 0.5, 0.5), - new Vector3D(0.5, 0.0, 0.5), - new Vector3D(0.5, 1.0, 0.5), - new Vector3D(0.5, 0.5, 0.0), - new Vector3D(0.5, 0.5, 1.0) + checkPoints(Region.Location.BOUNDARY, tree, new Coordinates3D[] { + new Coordinates3D(0.0, 0.5, 0.5), + new Coordinates3D(1.0, 0.5, 0.5), + new Coordinates3D(0.5, 0.0, 0.5), + new Coordinates3D(0.5, 1.0, 0.5), + new Coordinates3D(0.5, 0.5, 0.0), + new Coordinates3D(0.5, 0.5, 1.0) }); - checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] { - new Vector3D(0.0, 1.2, 1.2), - new Vector3D(1.0, 1.2, 1.2), - new Vector3D(1.2, 0.0, 1.2), - new Vector3D(1.2, 1.0, 1.2), - new Vector3D(1.2, 1.2, 0.0), - new Vector3D(1.2, 1.2, 1.0) + checkPoints(Region.Location.OUTSIDE, tree, new Coordinates3D[] { + new Coordinates3D(0.0, 1.2, 1.2), + new Coordinates3D(1.0, 1.2, 1.2), + new Coordinates3D(1.2, 0.0, 1.2), + new Coordinates3D(1.2, 1.0, 1.2), + new Coordinates3D(1.2, 1.2, 0.0), + new Coordinates3D(1.2, 1.2, 1.0) }); } @Test public void testTetrahedron() throws MathArithmeticException { - Vector3D vertex1 = new Vector3D(1, 2, 3); - Vector3D vertex2 = new Vector3D(2, 2, 4); - Vector3D vertex3 = new Vector3D(2, 3, 3); - Vector3D vertex4 = new Vector3D(1, 3, 4); + Coordinates3D vertex1 = new Coordinates3D(1, 2, 3); + Coordinates3D vertex2 = new Coordinates3D(2, 2, 4); + Coordinates3D vertex3 = new Coordinates3D(2, 3, 3); + Coordinates3D vertex4 = new Coordinates3D(1, 3, 4); PolyhedronsSet tree = (PolyhedronsSet) new RegionFactory<Euclidean3D>().buildConvex( new Plane(vertex3, vertex2, vertex1, 1.0e-10), @@ -111,64 +111,64 @@ public class PolyhedronsSetTest { new Plane(vertex1, vertex2, vertex4, 1.0e-10)); Assert.assertEquals(1.0 / 3.0, tree.getSize(), 1.0e-10); Assert.assertEquals(2.0 * FastMath.sqrt(3.0), tree.getBoundarySize(), 1.0e-10); - Vector3D barycenter = (Vector3D) tree.getBarycenter(); + Coordinates3D barycenter = (Coordinates3D) tree.getBarycenter(); Assert.assertEquals(1.5, barycenter.getX(), 1.0e-10); Assert.assertEquals(2.5, barycenter.getY(), 1.0e-10); Assert.assertEquals(3.5, barycenter.getZ(), 1.0e-10); double third = 1.0 / 3.0; - checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] { + checkPoints(Region.Location.BOUNDARY, tree, new Coordinates3D[] { vertex1, vertex2, vertex3, vertex4, - new Vector3D(third, vertex1, third, vertex2, third, vertex3), - new Vector3D(third, vertex2, third, vertex3, third, vertex4), - new Vector3D(third, vertex3, third, vertex4, third, vertex1), - new Vector3D(third, vertex4, third, vertex1, third, vertex2) + new Coordinates3D(third, vertex1, third, vertex2, third, vertex3), + new Coordinates3D(third, vertex2, third, vertex3, third, vertex4), + new Coordinates3D(third, vertex3, third, vertex4, third, vertex1), + new Coordinates3D(third, vertex4, third, vertex1, third, vertex2) }); - checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] { - new Vector3D(1, 2, 4), - new Vector3D(2, 2, 3), - new Vector3D(2, 3, 4), - new Vector3D(1, 3, 3) + checkPoints(Region.Location.OUTSIDE, tree, new Coordinates3D[] { + new Coordinates3D(1, 2, 4), + new Coordinates3D(2, 2, 3), + new Coordinates3D(2, 3, 4), + new Coordinates3D(1, 3, 3) }); } @Test public void testIsometry() throws MathArithmeticException, MathIllegalArgumentException { - Vector3D vertex1 = new Vector3D(1.1, 2.2, 3.3); - Vector3D vertex2 = new Vector3D(2.0, 2.4, 4.2); - Vector3D vertex3 = new Vector3D(2.8, 3.3, 3.7); - Vector3D vertex4 = new Vector3D(1.0, 3.6, 4.5); + Coordinates3D vertex1 = new Coordinates3D(1.1, 2.2, 3.3); + Coordinates3D vertex2 = new Coordinates3D(2.0, 2.4, 4.2); + Coordinates3D vertex3 = new Coordinates3D(2.8, 3.3, 3.7); + Coordinates3D vertex4 = new Coordinates3D(1.0, 3.6, 4.5); PolyhedronsSet tree = (PolyhedronsSet) new RegionFactory<Euclidean3D>().buildConvex( new Plane(vertex3, vertex2, vertex1, 1.0e-10), new Plane(vertex2, vertex3, vertex4, 1.0e-10), new Plane(vertex4, vertex3, vertex1, 1.0e-10), new Plane(vertex1, vertex2, vertex4, 1.0e-10)); - Vector3D barycenter = (Vector3D) tree.getBarycenter(); - Vector3D s = new Vector3D(10.2, 4.3, -6.7); - Vector3D c = new Vector3D(-0.2, 2.1, -3.2); - Rotation r = new Rotation(new Vector3D(6.2, -4.4, 2.1), 0.12, RotationConvention.VECTOR_OPERATOR); + Coordinates3D barycenter = (Coordinates3D) tree.getBarycenter(); + Coordinates3D s = new Coordinates3D(10.2, 4.3, -6.7); + Coordinates3D c = new Coordinates3D(-0.2, 2.1, -3.2); + Rotation r = new Rotation(new Coordinates3D(6.2, -4.4, 2.1), 0.12, RotationConvention.VECTOR_OPERATOR); tree = tree.rotate(c, r).translate(s); - Vector3D newB = - new Vector3D(1.0, s, + Coordinates3D newB = + new Coordinates3D(1.0, s, 1.0, c, 1.0, r.applyTo(barycenter.subtract(c))); Assert.assertEquals(0.0, newB.subtract((Vector<Euclidean3D>) tree.getBarycenter()).getNorm(), 1.0e-10); - final Vector3D[] expectedV = new Vector3D[] { - new Vector3D(1.0, s, + final Coordinates3D[] expectedV = new Coordinates3D[] { + new Coordinates3D(1.0, s, 1.0, c, 1.0, r.applyTo(vertex1.subtract(c))), - new Vector3D(1.0, s, + new Coordinates3D(1.0, s, 1.0, c, 1.0, r.applyTo(vertex2.subtract(c))), - new Vector3D(1.0, s, + new Coordinates3D(1.0, s, 1.0, c, 1.0, r.applyTo(vertex3.subtract(c))), - new Vector3D(1.0, s, + new Coordinates3D(1.0, s, 1.0, c, 1.0, r.applyTo(vertex4.subtract(c))) }; @@ -198,11 +198,11 @@ public class PolyhedronsSetTest { private void checkFacet(SubPlane facet) { Plane plane = (Plane) facet.getHyperplane(); - Vector2D[][] vertices = + Coordinates2D[][] vertices = ((PolygonsSet) facet.getRemainingRegion()).getVertices(); Assert.assertEquals(1, vertices.length); for (int i = 0; i < vertices[0].length; ++i) { - Vector3D v = plane.toSpace(vertices[0][i]); + Coordinates3D v = plane.toSpace(vertices[0][i]); double d = Double.POSITIVE_INFINITY; for (int k = 0; k < expectedV.length; ++k) { d = FastMath.min(d, v.subtract(expectedV[k]).getNorm()); @@ -224,7 +224,7 @@ public class PolyhedronsSetTest { double l = 1.0; PolyhedronsSet tree = new PolyhedronsSet(x - l, x + l, y - w, y + w, z - w, z + w, 1.0e-10); - Vector3D barycenter = (Vector3D) tree.getBarycenter(); + Coordinates3D barycenter = (Coordinates3D) tree.getBarycenter(); Assert.assertEquals(x, barycenter.getX(), 1.0e-10); Assert.assertEquals(y, barycenter.getY(), 1.0e-10); Assert.assertEquals(z, barycenter.getZ(), 1.0e-10); @@ -248,7 +248,7 @@ public class PolyhedronsSetTest { new PolyhedronsSet(x - w, x + w, y - w, y + w, z - l, z + l, 1.0e-10); RegionFactory<Euclidean3D> factory = new RegionFactory<>(); PolyhedronsSet tree = (PolyhedronsSet) factory.union(xBeam, factory.union(yBeam, zBeam)); - Vector3D barycenter = (Vector3D) tree.getBarycenter(); + Coordinates3D barycenter = (Coordinates3D) tree.getBarycenter(); Assert.assertEquals(x, barycenter.getX(), 1.0e-10); Assert.assertEquals(y, barycenter.getY(), 1.0e-10); @@ -281,14 +281,14 @@ public class PolyhedronsSetTest { int idxA = indices[idx] * 3; int idxB = indices[idx + 1] * 3; int idxC = indices[idx + 2] * 3; - Vector3D v_1 = new Vector3D(coords[idxA], coords[idxA + 1], coords[idxA + 2]); - Vector3D v_2 = new Vector3D(coords[idxB], coords[idxB + 1], coords[idxB + 2]); - Vector3D v_3 = new Vector3D(coords[idxC], coords[idxC + 1], coords[idxC + 2]); - Vector3D[] vertices = {v_1, v_2, v_3}; + Coordinates3D v_1 = new Coordinates3D(coords[idxA], coords[idxA + 1], coords[idxA + 2]); + Coordinates3D v_2 = new Coordinates3D(coords[idxB], coords[idxB + 1], coords[idxB + 2]); + Coordinates3D v_3 = new Coordinates3D(coords[idxC], coords[idxC + 1], coords[idxC + 2]); + Coordinates3D[] vertices = {v_1, v_2, v_3}; Plane polyPlane = new Plane(v_1, v_2, v_3, 1.0e-10); ArrayList<SubHyperplane<Euclidean2D>> lines = new ArrayList<>(); - Vector2D[] projPts = new Vector2D[vertices.length]; + Coordinates2D[] projPts = new Coordinates2D[vertices.length]; for (int ptIdx = 0; ptIdx < projPts.length; ptIdx++) { projPts[ptIdx] = polyPlane.toSubSpace(vertices[ptIdx]); } @@ -322,7 +322,7 @@ public class PolyhedronsSetTest { PolyhedronsSet ps = new PolyhedronsSet(new BSPTree<Euclidean3D>(), 1.0e-10); Assert.assertNotNull(ps); try { - ps.checkPoint(Vector3D.ZERO); + ps.checkPoint(Coordinates3D.ZERO); Assert.fail("an exception should have been thrown"); } catch (NullPointerException npe) { // this is expected @@ -333,18 +333,18 @@ public class PolyhedronsSetTest { public void testDumpParse() throws IOException, ParseException { double tol=1e-8; - Vector3D[] verts=new Vector3D[8]; + Coordinates3D[] verts=new Coordinates3D[8]; double xmin=-1,xmax=1; double ymin=-1,ymax=1; double zmin=-1,zmax=1; - verts[0]=new Vector3D(xmin,ymin,zmin); - verts[1]=new Vector3D(xmax,ymin,zmin); - verts[2]=new Vector3D(xmax,ymax,zmin); - verts[3]=new Vector3D(xmin,ymax,zmin); - verts[4]=new Vector3D(xmin,ymin,zmax); - verts[5]=new Vector3D(xmax,ymin,zmax); - verts[6]=new Vector3D(xmax,ymax,zmax); - verts[7]=new Vector3D(xmin,ymax,zmax); + verts[0]=new Coordinates3D(xmin,ymin,zmin); + verts[1]=new Coordinates3D(xmax,ymin,zmin); + verts[2]=new Coordinates3D(xmax,ymax,zmin); + verts[3]=new Coordinates3D(xmin,ymax,zmin); + verts[4]=new Coordinates3D(xmin,ymin,zmax); + verts[5]=new Coordinates3D(xmax,ymin,zmax); + verts[6]=new Coordinates3D(xmax,ymax,zmax); + verts[7]=new Coordinates3D(xmin,ymax,zmax); // int[][] faces=new int[12][]; faces[0]=new int[]{3,1,0}; // bottom (-z) @@ -401,7 +401,7 @@ public class PolyhedronsSetTest { @Test public void testFacet2Vertices() throws IOException, ParseException { - checkError(Arrays.asList(Vector3D.ZERO, Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_K), + checkError(Arrays.asList(Coordinates3D.ZERO, Coordinates3D.PLUS_I, Coordinates3D.PLUS_J, Coordinates3D.PLUS_K), Arrays.asList(new int[] { 0, 1, 2 }, new int[] {2, 3}), LocalizedFormats.WRONG_NUMBER_OF_POINTS); } @@ -419,7 +419,7 @@ public class PolyhedronsSetTest { } } - private void checkError(final List<Vector3D> vertices, final List<int[]> facets, + private void checkError(final List<Coordinates3D> vertices, final List<int[]> facets, final LocalizedFormats expected) { try { new PolyhedronsSet(vertices, facets, 1.0e-10); @@ -446,14 +446,14 @@ public class PolyhedronsSetTest { UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 0xb97c9d1ade21e40al); int nrays = 1000; for (int i = 0; i < nrays; i++) { - Vector3D origin = Vector3D.ZERO; - Vector3D direction = new Vector3D(2 * random.nextDouble() - 1, + Coordinates3D origin = Coordinates3D.ZERO; + Coordinates3D direction = new Coordinates3D(2 * random.nextDouble() - 1, 2 * random.nextDouble() - 1, 2 * random.nextDouble() - 1).normalize(); Line line = new Line(origin, origin.add(direction), polyset.getTolerance()); SubHyperplane<Euclidean3D> plane = polyset.firstIntersection(origin, line); if (plane != null) { - Vector3D intersectionPoint = ((Plane)plane.getHyperplane()).intersection(line); + Coordinates3D intersectionPoint = ((Plane)plane.getHyperplane()).intersection(line); double dotProduct = direction.dotProduct(intersectionPoint.subtract(origin)); Assert.assertTrue(dotProduct > 0); } @@ -471,7 +471,7 @@ public class PolyhedronsSetTest { return builder.toString(); } - private void checkPoints(Region.Location expected, PolyhedronsSet tree, Vector3D[] points) { + private void checkPoints(Region.Location expected, PolyhedronsSet tree, Coordinates3D[] points) { for (int i = 0; i < points.length; ++i) { Assert.assertEquals(expected, tree.checkPoint(points[i])); }