This is an automated email from the ASF dual-hosted git repository. erans pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-geometry.git
commit 812f07d4e7c229c5100eb7264051b95875e94afd Author: Sven Rathgeber <[email protected]> AuthorDate: Mon Mar 18 08:00:36 2019 +0100 GEOMETRY-29 rename fromThreePoints to fromPoints, corrects typos. adds getW, adds getOriginOffset, renames fromTwoVectors to fromPlaneVectors. --- .../threed/enclosing/SphereGenerator.java | 2 +- .../commons/geometry/euclidean/threed/Plane.java | 41 ++++++++++++++++++---- .../geometry/euclidean/threed/PolyhedronsSet.java | 2 +- .../geometry/euclidean/threed/PlaneTest.java | 18 +++++----- .../euclidean/threed/PolyhedronsSetTest.java | 18 +++++----- 5 files changed, 55 insertions(+), 26 deletions(-) diff --git a/commons-geometry-enclosing/src/main/java/org/apache/commons/geometry/euclidean/threed/enclosing/SphereGenerator.java b/commons-geometry-enclosing/src/main/java/org/apache/commons/geometry/euclidean/threed/enclosing/SphereGenerator.java index c7e3d47..bd6ac7e 100644 --- a/commons-geometry-enclosing/src/main/java/org/apache/commons/geometry/euclidean/threed/enclosing/SphereGenerator.java +++ b/commons-geometry-enclosing/src/main/java/org/apache/commons/geometry/euclidean/threed/enclosing/SphereGenerator.java @@ -58,7 +58,7 @@ public class SphereGenerator implements SupportBallGenerator<Vector3D> { // delegate to 2D disk generator final DoublePrecisionContext precision = new EpsilonDoublePrecisionContext(BASE_EPS * (norm1(vA) + norm1(vB) + norm1(vC))); - final Plane p = Plane.fromThreePoints(vA, vB, vC, precision); + final Plane p = Plane.fromPoints(vA, vB, vC, precision); final EnclosingBall<Vector2D> disk = new DiskGenerator().ballOnSupport(Arrays.asList(p.toSubSpace(vA), p.toSubSpace(vB), diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java index aea5b16..e4e1f15 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java @@ -49,7 +49,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve /** Precision context used to compare floating point numbers. */ private final DoublePrecisionContext precision; - public static Plane fromTwoVectors (final Vector3D u, final Vector3D v, final DoublePrecisionContext precision) + public static Plane fromPlaneVectors (final Vector3D u, final Vector3D v, final DoublePrecisionContext precision) { Vector3D w = u.cross(v); double originOffset = 0; @@ -102,7 +102,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve * @param precision precision context used to compare floating point values * @exception IllegalArgumentException if the points do not constitute a plane */ - public static Plane fromThreePoints(final Vector3D p1, final Vector3D p2, final Vector3D p3, + public static Plane fromPoints(final Vector3D p1, final Vector3D p2, final Vector3D p3, final DoublePrecisionContext precision) throws IllegalArgumentException { return Plane.fromPointAndNormal(p1, p2.subtract(p1).cross(p3.subtract(p1)), precision); } @@ -172,6 +172,18 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve return origin; } + + /** + * Gets the offset of the origin with respect to the plane. + * + * @return the offset of the origin with respect to the plane. + */ + public double getOriginOffset() + { + return originOffset; + } + + /** * Get the normalized normal vector. * <p> @@ -191,7 +203,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve * Get the plane first canonical vector. * <p> * The frame defined by ({@link #getU getU}, {@link #getV getV}, - * {@link #getNormal getNormal}) is a rigth-handed orthonormalized frame). + * {@link #getNormal getNormal}) is a right-handed orthonormalized frame). * </p> * * @return normalized first canonical vector @@ -206,7 +218,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve * Get the plane second canonical vector. * <p> * The frame defined by ({@link #getU getU}, {@link #getV getV}, - * {@link #getNormal getNormal}) is a rigth-handed orthonormalized frame). + * {@link #getNormal getNormal}) is a right-handed orthonormalized frame). * </p> * * @return normalized second canonical vector @@ -217,6 +229,23 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve return v; } + + /** + * Get the normalized normal vector. Alias for getNormal(). + * <p> + * The frame defined by ({@link #getU getU}, {@link #getV getV}, + * {@link #getNormal getNormal}) is a right-handed orthonormalized frame). + * </p> + * + * @return normalized normal vector + * @see #getU + * @see #getV + */ + public Vector3D getW() { + return w; + } + + /** {@inheritDoc} */ @Override public Vector3D project(Vector3D point) { @@ -230,7 +259,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve } /** - * Creates a new reverted version of this plane, with opposite orientation. + * Creates a new reversed version of this plane, with opposite orientation. * <p> * The new plane frame is chosen in such a way that a 3D point that had * {@code (x, y)} in-plane coordinates and {@code z} offset with respect to the @@ -241,7 +270,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve * {@link #getNormal} method is reversed. * </p> */ - public Plane revert() { + public Plane reverse() { final Vector3D tmp = u; Vector3D u = v; Vector3D v = tmp; diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java index 66e35b1..234f81d 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java @@ -218,7 +218,7 @@ public class PolyhedronsSet extends AbstractRegion<Vector3D, Vector2D> { for (final int[] facet : facets) { // define facet plane from the first 3 points - Plane plane = Plane.fromThreePoints(vertices.get(facet[0]), vertices.get(facet[1]), vertices.get(facet[2]), + Plane plane = Plane.fromPoints(vertices.get(facet[0]), vertices.get(facet[1]), vertices.get(facet[2]), precision); // check all points are in the plane diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PlaneTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PlaneTest.java index 8480646..3b77e6e 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PlaneTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PlaneTest.java @@ -62,7 +62,7 @@ public class PlaneTest { Vector3D p1 = Vector3D.of(1.2, 3.4, -5.8); Vector3D p2 = Vector3D.of(3.4, -5.8, 1.2); Vector3D p3 = Vector3D.of(-2.0, 4.3, 0.7); - Plane p = Plane.fromThreePoints(p1, p2, p3, TEST_PRECISION); + Plane p = Plane.fromPoints(p1, p2, p3, TEST_PRECISION); Assert.assertTrue(p.contains(p1)); Assert.assertTrue(p.contains(p2)); Assert.assertTrue(p.contains(p3)); @@ -73,7 +73,7 @@ public class PlaneTest { Vector3D p1 = Vector3D.of(1.2, 3.4, -5.8); Vector3D p2 = Vector3D.of(3.4, -5.8, 1.2); Vector3D p3 = Vector3D.of(-2.0, 4.3, 0.7); - Plane p = Plane.fromThreePoints(p1, p2, p3, TEST_PRECISION); + Plane p = Plane.fromPoints(p1, p2, p3, TEST_PRECISION); Vector3D oldNormal = p.getNormal(); p = p.rotate(p2, QuaternionRotation.fromAxisAngle(p2.subtract(p1), 1.7)); @@ -98,7 +98,7 @@ public class PlaneTest { Vector3D p1 = Vector3D.of(1.2, 3.4, -5.8); Vector3D p2 = Vector3D.of(3.4, -5.8, 1.2); Vector3D p3 = Vector3D.of(-2.0, 4.3, 0.7); - Plane p = Plane.fromThreePoints(p1, p2, p3, TEST_PRECISION); + Plane p = Plane.fromPoints(p1, p2, p3, TEST_PRECISION); p = p.translate(Vector3D.linearCombination(2.0, p.getU(), -1.5, p.getV())); Assert.assertTrue(p.contains(p1)); @@ -133,8 +133,8 @@ public class PlaneTest { public void testIntersection2() { Vector3D p1 = Vector3D.of(1.2, 3.4, -5.8); Vector3D p2 = Vector3D.of(3.4, -5.8, 1.2); - Plane pA = Plane.fromThreePoints(p1, p2, Vector3D.of(-2.0, 4.3, 0.7), TEST_PRECISION); - Plane pB = Plane.fromThreePoints(p1, Vector3D.of(11.4, -3.8, 5.1), p2, TEST_PRECISION); + Plane pA = Plane.fromPoints(p1, p2, Vector3D.of(-2.0, 4.3, 0.7), TEST_PRECISION); + Plane pB = Plane.fromPoints(p1, Vector3D.of(11.4, -3.8, 5.1), p2, TEST_PRECISION); Line l = pA.intersection(pB); Assert.assertTrue(l.contains(p1)); Assert.assertTrue(l.contains(p2)); @@ -158,13 +158,13 @@ public class PlaneTest { Vector3D p1 = Vector3D.of(1.2, 3.4, -5.8); Vector3D p2 = Vector3D.of(3.4, -5.8, 1.2); Vector3D p3 = Vector3D.of(-2.0, 4.3, 0.7); - Plane pA = Plane.fromThreePoints(p1, p2, p3, TEST_PRECISION); - Plane pB = Plane.fromThreePoints(p1, Vector3D.of(11.4, -3.8, 5.1), p2, TEST_PRECISION); + Plane pA = Plane.fromPoints(p1, p2, p3, TEST_PRECISION); + Plane pB = Plane.fromPoints(p1, Vector3D.of(11.4, -3.8, 5.1), p2, TEST_PRECISION); Assert.assertTrue(! pA.isSimilarTo(pB)); Assert.assertTrue(pA.isSimilarTo(pA)); - Assert.assertTrue(pA.isSimilarTo(Plane.fromThreePoints(p1, p3, p2, TEST_PRECISION))); + Assert.assertTrue(pA.isSimilarTo(Plane.fromPoints(p1, p3, p2, TEST_PRECISION))); Vector3D shift = Vector3D.linearCombination(0.3, pA.getNormal()); - Assert.assertTrue(! pA.isSimilarTo(Plane.fromThreePoints(p1.add(shift), + Assert.assertTrue(! pA.isSimilarTo(Plane.fromPoints(p1.add(shift), p3.add(shift), p2.add(shift), TEST_PRECISION))); diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java index 52c8ff9..093501e 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java @@ -465,10 +465,10 @@ public class PolyhedronsSetTest { // act PolyhedronsSet tree = (PolyhedronsSet) new RegionFactory<Vector3D>().buildConvex( - Plane.fromThreePoints(vertex3, vertex2, vertex1, TEST_PRECISION), - Plane.fromThreePoints(vertex2, vertex3, vertex4, TEST_PRECISION), - Plane.fromThreePoints(vertex4, vertex3, vertex1, TEST_PRECISION), - Plane.fromThreePoints(vertex1, vertex2, vertex4, TEST_PRECISION)); + Plane.fromPoints(vertex3, vertex2, vertex1, TEST_PRECISION), + Plane.fromPoints(vertex2, vertex3, vertex4, TEST_PRECISION), + Plane.fromPoints(vertex4, vertex3, vertex1, TEST_PRECISION), + Plane.fromPoints(vertex1, vertex2, vertex4, TEST_PRECISION)); // assert Assert.assertEquals(1.0 / 3.0, tree.getSize(), TEST_EPS); @@ -539,10 +539,10 @@ public class PolyhedronsSetTest { // act PolyhedronsSet tree = (PolyhedronsSet) new RegionFactory<Vector3D>().buildConvex( - Plane.fromThreePoints(vertex3, vertex2, vertex1, TEST_PRECISION), - Plane.fromThreePoints(vertex2, vertex3, vertex4, TEST_PRECISION), - Plane.fromThreePoints(vertex4, vertex3, vertex1, TEST_PRECISION), - Plane.fromThreePoints(vertex1, vertex2, vertex4, TEST_PRECISION)); + Plane.fromPoints(vertex3, vertex2, vertex1, TEST_PRECISION), + Plane.fromPoints(vertex2, vertex3, vertex4, TEST_PRECISION), + Plane.fromPoints(vertex4, vertex3, vertex1, TEST_PRECISION), + Plane.fromPoints(vertex1, vertex2, vertex4, TEST_PRECISION)); // assert Vector3D barycenter = tree.getBarycenter(); @@ -691,7 +691,7 @@ public class PolyhedronsSetTest { Vector3D v_2 = Vector3D.of(coords[idxB], coords[idxB + 1], coords[idxB + 2]); Vector3D v_3 = Vector3D.of(coords[idxC], coords[idxC + 1], coords[idxC + 2]); Vector3D[] vertices = {v_1, v_2, v_3}; - Plane polyPlane = Plane.fromThreePoints(v_1, v_2, v_3, TEST_PRECISION); + Plane polyPlane = Plane.fromPoints(v_1, v_2, v_3, TEST_PRECISION); ArrayList<SubHyperplane<Vector2D>> lines = new ArrayList<>(); Vector2D[] projPts = new Vector2D[vertices.length];
