You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/05/20 13:39:13 UTC

[commons-geometry] branch master updated (e94830b -> c45647f)

This is an automated email from the ASF dual-hosted git repository.

erans pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-geometry.git.


    from e94830b  Avoid redundant computations.
     new 73b1962  GEOMETRY-29 first version.
     new d8697cf  GEOMETRY-29 replaces removes redundant method: calculateW.
     new b17f640  GEOMETRY-29 corrects comment for copy factory method, corrects typo. Removes factory method with all arguments supplied.
     new 812f07d  GEOMETRY-29 rename fromThreePoints to fromPoints, corrects typos. adds getW, adds getOriginOffset, renames fromTwoVectors to fromPlaneVectors.
     new f6cee8c  GEOMETRY-29 first Version of api according jira issue. Adds equals/toString to Line, adds areCoplanar to Vector3D, adds some tests.
     new 8a10b16  GEOMETRY-29 improves javadoc. Adds tests.
     new 7d5a006  GEOMETRY-29 removes my alternative version (probably slower) of contains(Plane).
     new c206720  GEOMETRY-29 adds tests
     new d0302b9  GEOMETRY-29 working on Matts review.
     new e99a03b  GEOMETRY-29 working on Matts review. Part II
     new c949642  GEOMETRY-29 working on Matts review. Part III
     new b14d63c  GEOMETRY-29 adds javadoc comment.
     new be6c6c8  GEOMETRY-29 makes {{origin}} computed instead of stored. Makes {{areCoplanar}} a private helper method in {{Plane}}.
     new 4c84bea  GEOMETRY-29 fixes errors in Plane and Line reported by checkstyle.
     new 7a42a6f  Trailing spaces, syntax convention.
     new c45647f  Merge branch 'GEOMETRY-29__sven'

The 16 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../threed/enclosing/SphereGenerator.java          |   2 +-
 .../commons/geometry/euclidean/threed/Line.java    |  29 +
 .../commons/geometry/euclidean/threed/Plane.java   | 597 +++++++++++++--------
 .../geometry/euclidean/threed/PolyhedronsSet.java  |  14 +-
 .../geometry/euclidean/threed/Vector3D.java        |   4 +-
 .../geometry/euclidean/EuclideanTestUtils.java     |   2 +-
 .../geometry/euclidean/threed/PlaneTest.java       | 272 +++++++---
 .../euclidean/threed/PolyhedronsSetTest.java       |  38 +-
 8 files changed, 640 insertions(+), 318 deletions(-)


[commons-geometry] 05/16: GEOMETRY-29 first Version of api according jira issue. Adds equals/toString to Line, adds areCoplanar to Vector3D, adds some tests.

Posted by er...@apache.org.
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 f6cee8c82f0124c944b0c17972475f75fadb1ca6
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Wed Mar 20 14:37:37 2019 +0100

    GEOMETRY-29 first Version of api according jira issue. Adds equals/toString to Line, adds areCoplanar to Vector3D, adds some tests.
---
 .../commons/geometry/euclidean/threed/Line.java    |  26 ++
 .../commons/geometry/euclidean/threed/Plane.java   | 271 ++++++++++++++-------
 .../geometry/euclidean/threed/Vector3D.java        |  15 +-
 .../geometry/euclidean/threed/PlaneTest.java       |  75 ++++--
 4 files changed, 277 insertions(+), 110 deletions(-)

diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
index a804725..7bfd4a5 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.geometry.euclidean.threed;
 
+import java.util.Objects;
+
 import org.apache.commons.geometry.core.partitioning.Embedding;
 import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
 import org.apache.commons.geometry.euclidean.oned.IntervalsSet;
@@ -236,5 +238,29 @@ public class Line implements Embedding<Vector3D, Vector1D> {
     public SubLine wholeLine() {
         return new SubLine(this, new IntervalsSet(precision));
     }
+    
+    
 
+    @Override
+    public int hashCode() {
+        throw new IllegalStateException("Must not be used in maps.");
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Line other = (Line) obj;
+        return this.direction.equals(other.direction, precision) && this.zero.equals(other.zero, precision);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "Line [direction=" + direction + ", zero=" + zero + "]";
+    }
 }
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 e4e1f15..45ff084 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
@@ -18,6 +18,7 @@ package org.apache.commons.geometry.euclidean.threed;
 
 import java.util.Objects;
 
+import org.apache.commons.geometry.core.exception.IllegalNormException;
 import org.apache.commons.geometry.core.partitioning.Embedding;
 import org.apache.commons.geometry.core.partitioning.Hyperplane;
 import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
@@ -27,15 +28,15 @@ import org.apache.commons.geometry.euclidean.twod.PolygonsSet;
 import org.apache.commons.geometry.euclidean.twod.Vector2D;
 
 /**
- * The class represent planes in a three dimensional space.
+ * The class represents a plane in a three dimensional space.
  */
 public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D> {
 
     /** Offset of the origin with respect to the plane. */
     private final double originOffset;
 
-    /** Origin of the plane frame. */
-    private final Vector3D origin;
+    /** orthogonal projection of the 3D-space origin in the plane. */
+    private final Vector3D projectedOrigin;
 
     /** First vector of the plane frame (in plane). */
     private final Vector3D u;
@@ -43,53 +44,89 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     /** Second vector of the plane frame (in plane). */
     private final Vector3D v;
 
-    /** Third vector of the plane frame (plane normal). */
+    /** Third vector of the plane frame (normalized plane normal). */
     private final Vector3D w;
 
     /** Precision context used to compare floating point numbers. */
     private final DoublePrecisionContext precision;
 
-    public static Plane fromPlaneVectors (final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
+    /** 
+     * Constructor, made private to prevent inheritance.
+     * 
+     * Builds a new plane with the given values.
+     * @param u u vector (on plane)
+     * @param v v vector (on plane)
+     * @param w unit normal vector
+     * @param projectedOrigin orthogonal projection of the 3D-space origin in the plane.
+     * @param precision precision context used to compare floating point values
+     * @param precision the precision context
+     * @throws IllegalArgumentException if the provided vectors are coplanar
+     */
+    private Plane(Vector3D u, Vector3D v, Vector3D w, Vector3D projectedOrigin, double originOffset,
+            DoublePrecisionContext precision) {
+        this.u = u;
+        this.v = v;
+        this.w = w;
+        if (Vector3D.areCoplanar(u, v, w, precision))
+        {
+            throw new IllegalArgumentException("Provided vectors must not be a coplanar.");
+        }
+        this.projectedOrigin = projectedOrigin;
+        this.originOffset = originOffset;
+        this.precision = precision;
+    }
+    
+    /**
+     * Build a plane from a point and two (on plane) vectors.
+     * @param p the provided point (on plane)
+     * @param u u vector (on plane)
+     * @param v v vector (on plane)
+     * @param precision precision context used to compare floating point values
+     * @return a new plane
+     * @throws IllegalNormException if the norm of the given values is zero, NaN, or infinite.
+     */
+    public static Plane fromPointAndPlaneVectors (Vector3D p, final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
     {
-        Vector3D w = u.cross(v);
-        double originOffset = 0;
-        Vector3D origin = calculateOrigin(w, originOffset);
-        return new Plane(u, v, w, origin, originOffset, precision);
+        Vector3D u_norm = u.normalize();
+        Vector3D v_norm = v.normalize();
+        Vector3D w = u_norm.cross(v_norm);
+        double originOffset = -p.dot(w);
+        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
+        return new Plane(u_norm, v_norm, w, projectedOrigin, originOffset, precision);
     }
     
+    /**
+     * Build a plane from a normal.
+     * Chooses origin as point on plane. 
+     * @param normal    normal direction to the plane
+     * @param precision precision context used to compare floating point values
+     * @return a new plane
+     * @exception IllegalArgumentException if the normal norm is too small
+     */
     public static Plane fromNormal(final Vector3D normal, final DoublePrecisionContext precision)
             throws IllegalArgumentException {
-        Vector3D w = normal.normalize();
-        double originOffset = 0;
-        Vector3D origin = calculateOrigin(w, originOffset);
-        Vector3D u = w.orthogonal();
-        Vector3D v = w.cross(u);
-        return new Plane(u, v, w, origin, originOffset, precision);
+        return fromPointAndNormal(Vector3D.ZERO, normal, precision);
     }
 
-    private static Vector3D calculateOrigin(Vector3D w, double originOffset) {
-        return w.multiply(-originOffset);
-    }
-
-
     /**
      * Build a plane from a point and a normal.
      * 
      * @param p         point belonging to the plane
      * @param normal    normal direction to the plane
      * @param precision precision context used to compare floating point values
+     * @return a new plane
      * @exception IllegalArgumentException if the normal norm is too small
      */
     public static Plane fromPointAndNormal(final Vector3D p, final Vector3D normal, final DoublePrecisionContext precision)
             throws IllegalArgumentException {
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D origin = calculateOrigin(w, originOffset);
+        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
         Vector3D u = w.orthogonal();
         Vector3D v = w.cross(u);
-        return new Plane(u, v, w, origin, originOffset, precision);
+        return new Plane(u, v, w, projectedOrigin, originOffset, precision);
     }
-
+    
     /**
      * Build a plane from three points.
      * <p>
@@ -100,6 +137,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param p2        second point belonging to the plane
      * @param p3        third point belonging to the plane
      * @param precision precision context used to compare floating point values
+     * @return a new plane
      * @exception IllegalArgumentException if the points do not constitute a plane
      */
     public static Plane fromPoints(final Vector3D p1, final Vector3D p2, final Vector3D p3,
@@ -115,30 +153,10 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * </p>
      * 
      * @param plane plane to copy
+     * @return a new plane
      */
     public static Plane of(final Plane plane) {
-        return new Plane(plane.u, plane.v, plane.w, plane.origin, plane.originOffset, plane.getPrecision());
-    }
-
-    /** 
-     * Constructor, made private to prevent inheritance.
-     * 
-     * Creates a new instance with the given values.
-     * @param u u axis
-     * @param v v axis
-     * @param w w axis
-     * @param origin origin
-     * @param originOffset offset of the origin
-     * @param precision the precision context
-     */
-    private Plane(Vector3D u, Vector3D v, Vector3D w, Vector3D origin, double originOffset,
-            DoublePrecisionContext precision) {
-        this.u = u;
-        this.v = v;
-        this.w = w;
-        this.origin = origin;
-        this.originOffset = originOffset;
-        this.precision = precision;
+        return new Plane(plane.u, plane.v, plane.w, plane.projectedOrigin, plane.originOffset, plane.getPrecision());
     }
 
     /**
@@ -154,27 +172,20 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     @Deprecated
     @Override
     public Plane copySelf() {
-        return new Plane(this.u, this.v, this.w, this.origin, this.originOffset, this.precision);
+        return new Plane(this.u, this.v, this.w, this.projectedOrigin, this.originOffset, this.precision);
     }
 
-
     /**
-     * Get the origin point of the plane frame.
-     * <p>
-     * The point returned is the orthogonal projection of the 3D-space origin in the
-     * plane.
-     * </p>
-     * 
+     * Get the orthogonal projection of the 3D-space origin in the plane.      
      * @return the origin point of the plane frame (point closest to the 3D-space
      *         origin)
      */
     public Vector3D getOrigin() {
-        return origin;
+        return projectedOrigin;
     }
-
     
     /**
-     *  Gets the offset of the origin with respect to the plane. 
+     *  Get the offset of the origin with respect to the plane. 
      *  
      *  @return the offset of the origin with respect to the plane. 
      */
@@ -182,24 +193,8 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     {
         return originOffset;
     }
-
     
     /**
-     * Get the normalized normal vector.
-     * <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 getNormal() {
-        return w;
-    }
-
-    /**
      * Get the plane first canonical vector.
      * <p>
      * The frame defined by ({@link #getU getU}, {@link #getV getV},
@@ -228,10 +223,9 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public Vector3D getV() {
         return v;
     }
-
     
     /**
-     * Get the normalized normal vector. Alias for getNormal().
+     * 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).
@@ -244,7 +238,21 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public Vector3D getW() {
         return w;
     }
-
+    
+    /**
+     * Get the normalized normal vector.
+     * <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 getNormal() {
+        return w;
+    }
     
     /** {@inheritDoc} */
     @Override
@@ -252,6 +260,21 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         return toSpace(toSubSpace(point));
     }
 
+    /**
+     * 3D line projected onto plane
+     * @param line the line to project
+     * @return the projection of the given line onto the plane.
+     */
+    public Line project(Line line)
+    {
+        Vector3D direction = line.getDirection();
+        Vector3D projection = w.multiply(direction.dot(w)).multiply(1/Math.pow(w.norm(), 2));
+        Vector3D projectedLineDirection = direction.subtract(projection);
+        Vector3D p1 = project(line.getOrigin());
+        Vector3D p2 = p1.add(projectedLineDirection);
+        return new Line(p1,p2, precision);
+    }
+
     /** {@inheritDoc} */
     @Override
     public DoublePrecisionContext getPrecision() {
@@ -259,7 +282,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     }
 
     /**
-     * Creates a new reversed version of this plane, with opposite orientation.
+     * Build 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
@@ -269,6 +292,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * {@link #getV} methods are exchanged, and the {@code w} vector returned by the
      * {@link #getNormal} method is reversed.
      * </p>
+     * @return a new reversed plane
      */
     public Plane reverse() {
         final Vector3D tmp = u;
@@ -276,8 +300,8 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         Vector3D v = tmp;
         Vector3D w = this.w.negate();
         double originOffset = -this.originOffset;
-        Vector3D origin = calculateOrigin(w, originOffset);
-        return new Plane(u, v, w, origin, originOffset, this.precision);
+        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
+        return new Plane(u, v, w, projectedOrigin, originOffset, this.precision);
     }
 
     /**
@@ -313,12 +337,12 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return one point in the 3D-space, with given coordinates and offset relative
      *         to the plane
      */
-    public Vector3D getPointAt(final Vector2D inPlane, final double offset) {
+    public Vector3D pointAt(final Vector2D inPlane, final double offset) {
         return Vector3D.linearCombination(inPlane.getX(), u, inPlane.getY(), v, offset - originOffset, w);
     }
 
     /**
-     * Check if the instance is similar to another plane.
+     * Check if the instance contains another plane.
      * <p>
      * Planes are considered similar if they contain the same points. This does not
      * mean they are equal since they can have opposite normals.
@@ -327,12 +351,28 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane plane to which the instance is compared
      * @return true if the planes are similar
      */
-    public boolean isSimilarTo(final Plane plane) {
-        final double angle = w.angle(plane.w);
+    public boolean contains(final Plane plane) {
+        //final double angle = w.angle(plane.w);
 
-        return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset))
-                || ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
+//        return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset))
+//                || ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
+    
+        Vector3D u_other = plane.getU();
+        Vector3D v_other = plane.getV();
+        
+        boolean isVOtherInPlane = Vector3D.areCoplanar(u, v, v_other, precision); 
+        boolean isUOtherInPlane = Vector3D.areCoplanar(u, v, u_other, precision);
+        if (isVOtherInPlane && isUOtherInPlane && contains(plane.getOrigin()))
+        {
+            return true;
+        }
+        return false;
+    
+                
+    
     }
+    
+    
 
     /**
      * Rotate the plane around the specified point.
@@ -345,15 +385,15 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return a new plane
      */
     public Plane rotate(final Vector3D center, final QuaternionRotation rotation) {
-        final Vector3D delta = origin.subtract(center);
+        final Vector3D delta = projectedOrigin.subtract(center);
         Vector3D p = center.add(rotation.apply(delta));
         Vector3D normal = rotation.apply(this.w);
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D origin = calculateOrigin(w, originOffset);
+        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
         Vector3D u = rotation.apply(this.u);
         Vector3D v = rotation.apply(this.v);
-        return new Plane(u, v, w, origin, originOffset, this.precision);
+        return new Plane(u, v, w, projectedOrigin, originOffset, this.precision);
     }
 
     /**
@@ -366,12 +406,12 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return a new plane
      */
     public Plane translate(final Vector3D translation) {
-        Vector3D p = origin.add(translation);
+        Vector3D p = projectedOrigin.add(translation);
         Vector3D normal = this.w;
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D origin = calculateOrigin(w, originOffset);
-        return new Plane(this.u, this.v, w, origin, originOffset, this.precision);
+        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
+        return new Plane(this.u, this.v, w, projectedOrigin, originOffset, this.precision);
     }
 
     /**
@@ -481,7 +521,34 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public boolean contains(final Vector3D p) {
         return precision.eqZero(getOffset(p));
     }
+    
+    /**
+     * Check if the instance contains a line
+     * @param line line to check
+     * @return true if line is contained in this plane
+     */
+    public boolean contains(Line line)
+    {
+        Vector3D origin = line.getOrigin();
+        Vector3D direction = line.getDirection();
+        return (contains(origin) && Vector3D.areCoplanar(u, v, direction, precision));
+    }
 
+    /** Check, if the line is parallel to the instance.
+     * @param line line to check.
+     * @return true if the line is parallel to the instance, false otherwise.
+     */
+    public boolean isParallel(Line line) {
+        final Vector3D direction = line.getDirection();
+        final double   dot       = w.dot(direction);
+        if (precision.eqZero(dot)) {
+            return true;
+        }
+        return false;
+    }
+
+    
+    
     /**
      * Get the offset (oriented distance) of a parallel plane.
      * <p>
@@ -502,6 +569,20 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     }
 
     /**
+     *  Returns the distance of the given line to the plane instance.
+     *  Returns 0.0, if the line is not parallel to the plane instance.
+     * @param line to calculate the distance to the plane instance
+     * @return the distance or 0.0, if the line is not parallel to the plane instance.
+     */
+    public double getOffset(Line line) {
+        if (!isParallel(line))
+        {
+            return 0.0;
+        }
+        return getOffset(line.getOrigin());
+    }
+    
+    /**
      * Get the offset (oriented distance) of a point.
      * <p>
      * The offset is 0 if the point is on the underlying hyperplane, it is positive
@@ -533,14 +614,14 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     /** {@inheritDoc} */
     @Override
     public String toString() {
-        return "Plane [originOffset=" + originOffset + ", origin=" + origin + ", u=" + u + ", v=" + v + ", w=" + w
+        return "Plane [originOffset=" + originOffset + ", projectedOrigin=" + projectedOrigin + ", u=" + u + ", v=" + v + ", w=" + w
                 + ", precision=" + precision + "]";
     }
 
     /** {@inheritDoc} */
     @Override
     public int hashCode() {
-        return Objects.hash(origin, originOffset, u, v, w);
+        return Objects.hash(projectedOrigin, originOffset, u, v, w);
     }
 
     /** {@inheritDoc} */
@@ -553,8 +634,12 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         if (getClass() != obj.getClass())
             return false;
         Plane other = (Plane) obj;
-        return Objects.equals(origin, other.origin)
+        return Objects.equals(projectedOrigin, other.projectedOrigin)
                 && Double.doubleToLongBits(originOffset) == Double.doubleToLongBits(other.originOffset)
                 && Objects.equals(u, other.u) && Objects.equals(v, other.v) && Objects.equals(w, other.w);
     }
+    
+    private static Vector3D calculateOrigin(Vector3D w, double originOffset) {
+        return w.multiply(-originOffset);
+    }
 }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
index b503b7c..afd1e7f 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
@@ -89,7 +89,7 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> {
     }
 
     /** Returns the abscissa (first coordinate) value of the instance.
-     * @return the abscisaa
+     * @return the abscissa
      */
     public double getX() {
         return x;
@@ -371,6 +371,19 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> {
         return transform.apply(this);
     }
 
+    /**
+     * Check if provided vectors are coplanar.
+     * @param u first vector
+     * @param v second vector
+     * @param w third vector
+     * @param precision precision context used to compare floating point values
+     * @return true if vectors a coplanar, false otherwise.
+     */
+    public static boolean areCoplanar(Vector3D u, Vector3D v, Vector3D w, DoublePrecisionContext precision)
+    {
+        return precision.eqZero(u.dot(v.cross(w)));
+    }
+    
     /** {@inheritDoc} */
     @Override
     public boolean equals(final Vector3D vec, final DoublePrecisionContext precision) {
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 3b77e6e..bb5f9dc 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
@@ -22,6 +22,7 @@ import org.apache.commons.geometry.euclidean.threed.rotation.QuaternionRotation;
 import org.junit.Assert;
 import org.junit.Test;
 
+@SuppressWarnings("javadoc")
 public class PlaneTest {
 
     private static final double TEST_EPS = 1e-10;
@@ -38,19 +39,61 @@ public class PlaneTest {
     }
 
     @Test
-                public void testFromNormalfset() {
-                    Vector3D p1 = Vector3D.of(1, 1, 1);
-                    Plane p = Plane.fromPointAndNormal(p1, Vector3D.of(0.2, 0, 0), TEST_PRECISION);
-                    Assert.assertEquals(-5.0, p.getOffset(Vector3D.of(-4, 0, 0)), TEST_EPS);
-                    Assert.assertEquals(+5.0, p.getOffset(Vector3D.of(6, 10, -12)), TEST_EPS);
-                    Assert.assertEquals(0.3,
-                                        p.getOffset(Vector3D.linearCombination(1.0, p1, 0.3, p.getNormal())),
-                                        TEST_EPS);
-                    Assert.assertEquals(-0.3,
-                                        p.getOffset(Vector3D.linearCombination(1.0, p1, -0.3, p.getNormal())),
-                                        TEST_EPS);
-                }
+    public void testContainsLine() {
+        Plane p = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Line line = new Line(Vector3D.of(1, 0, 1), Vector3D.of(2, 0, 1), TEST_PRECISION);
+        Assert.assertTrue(p.contains(line));
+    }
+    
+    
+    @Test
+    public void testProjectLine() {
+        Plane p = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Line line = new Line(Vector3D.of(1, 0, 1), Vector3D.of(2, 0, 2), TEST_PRECISION);
+        Line expectedProjection = new Line(Vector3D.of(1, 0, 1),Vector3D.of(2, 0, 1), TEST_PRECISION);
+        Assert.assertEquals(expectedProjection, p.project(line));
+    }
+    
+    @Test
+    public void testOffset() {
+        Vector3D p1 = Vector3D.of(1, 1, 1);
+        Plane p = Plane.fromPointAndNormal(p1, Vector3D.of(0.2, 0, 0), TEST_PRECISION);
+        Assert.assertEquals(-5.0, p.getOffset(Vector3D.of(-4, 0, 0)), TEST_EPS);
+        Assert.assertEquals(+5.0, p.getOffset(Vector3D.of(6, 10, -12)), TEST_EPS);
+        Assert.assertEquals(0.3,
+                            p.getOffset(Vector3D.linearCombination(1.0, p1, 0.3, p.getNormal())),
+                            TEST_EPS);
+        Assert.assertEquals(-0.3,
+                            p.getOffset(Vector3D.linearCombination(1.0, p1, -0.3, p.getNormal())),
+                            TEST_EPS);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testVectorsAreColinear()
+    {
+      Plane.fromPointAndPlaneVectors(Vector3D.of(1, 1, 1), Vector3D.of(2, 0, 0), Vector3D.of(2,0,0), TEST_PRECISION);
+    }
+
+    
+    @Test
+    public void testVectorsAreNormalizedForSuppliedUAndV() {
+        Plane p = Plane.fromPointAndPlaneVectors(Vector3D.of(1, 1, 1), Vector3D.of(2, 0, 0), Vector3D.of(0,2,0), TEST_PRECISION);
+        Assert.assertEquals(1.0, p.getNormal().norm(), TEST_EPS);
+        Assert.assertEquals(1.0, p.getV().norm(), TEST_EPS);
+        Assert.assertEquals(1.0, p.getU().norm(), TEST_EPS);
+    }
+
+    
+    
+    @Test
+    public void testVectorsAreNormalized() {
+        Plane p = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
+        Assert.assertEquals(1.0, p.getNormal().norm(), TEST_EPS);
+        Assert.assertEquals(1.0, p.getV().norm(), TEST_EPS);
+        Assert.assertEquals(1.0, p.getU().norm(), TEST_EPS);
+    }
 
+    
     @Test
     public void testPoint() {
         Plane p = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
@@ -160,11 +203,11 @@ public class PlaneTest {
         Vector3D p3  = Vector3D.of(-2.0, 4.3, 0.7);
         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.fromPoints(p1, p3, p2, TEST_PRECISION)));
+        Assert.assertTrue(! pA.contains(pB));
+        Assert.assertTrue(pA.contains(pA));
+        Assert.assertTrue(pA.contains(Plane.fromPoints(p1, p3, p2, TEST_PRECISION)));
         Vector3D shift = Vector3D.linearCombination(0.3, pA.getNormal());
-        Assert.assertTrue(! pA.isSimilarTo(Plane.fromPoints(p1.add(shift),
+        Assert.assertTrue(! pA.contains(Plane.fromPoints(p1.add(shift),
                                                      p3.add(shift),
                                                      p2.add(shift),
                                                      TEST_PRECISION)));


[commons-geometry] 15/16: Trailing spaces, syntax convention.

Posted by er...@apache.org.
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 7a42a6f317b0de8ee63b0461e868532c8e025b4e
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Mon May 20 15:24:28 2019 +0200

    Trailing spaces, syntax convention.
---
 .../commons/geometry/euclidean/threed/Line.java    |  6 ++--
 .../commons/geometry/euclidean/threed/Plane.java   | 33 +++++++++-------------
 .../geometry/euclidean/threed/PlaneTest.java       | 32 ++++++++++-----------
 3 files changed, 32 insertions(+), 39 deletions(-)

diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
index 4835682..9f859e7 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
@@ -248,13 +248,13 @@ public class Line implements Embedding<Vector3D, Vector1D> {
     /** {@inheritDoc} */
     @Override
     public boolean equals(Object obj) {
-        if (this == obj){
+        if (this == obj) {
             return true;
         }
-        if (obj == null){
+        if (obj == null) {
             return false;
         }
-        if (getClass() != obj.getClass()){
+        if (getClass() != obj.getClass()) {
             return false;
         }
         Line other = (Line) obj;
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 8c1ce6b..f82ae52 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
@@ -62,8 +62,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         this.u = u;
         this.v = v;
         this.w = w;
-        if (areCoplanar(u, v, w, precision))
-        {
+        if (areCoplanar(u, v, w, precision)) {
             throw new IllegalArgumentException("Provided vectors must not be coplanar.");
         }
         this.originOffset = originOffset;
@@ -80,8 +79,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @throws IllegalNormException if the norm of the given values is zero, NaN, or infinite.
      * @throws IllegalArgumentException if the provided vectors are collinear
      */
-    public static Plane fromPointAndPlaneVectors (final Vector3D p, final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
-    {
+    public static Plane fromPointAndPlaneVectors (final Vector3D p, final Vector3D u, final Vector3D v, final DoublePrecisionContext precision) {
         Vector3D uNorm = u.normalize();
         Vector3D vNorm = uNorm.orthogonal(v);
         Vector3D wNorm = uNorm.cross(vNorm).normalize();
@@ -97,7 +95,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return a new plane
      * @throws IllegalNormException if the norm of the given values is zero, NaN, or infinite.
      */
-    public static Plane fromNormal(final Vector3D normal, final DoublePrecisionContext precision){
+    public static Plane fromNormal(final Vector3D normal, final DoublePrecisionContext precision) {
         return fromPointAndNormal(Vector3D.ZERO, normal, precision);
     }
 
@@ -167,8 +165,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      *
      *  @return the offset of the origin with respect to the plane.
      */
-    public double getOriginOffset()
-    {
+    public double getOriginOffset() {
         return originOffset;
     }
 
@@ -243,8 +240,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param line the line to project
      * @return the projection of the given line onto the plane.
      */
-    public Line project(final Line line)
-    {
+    public Line project(final Line line) {
         Vector3D direction = line.getDirection();
         Vector3D projection = w.multiply(direction.dot(w) * (1/w.normSq()));
         Vector3D projectedLineDirection = direction.subtract(projection);
@@ -487,8 +483,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param line line to check
      * @return true if line is contained in this plane
      */
-    public boolean contains(final Line line)
-    {
+    public boolean contains(final Line line) {
         Vector3D origin = line.getOrigin();
         Vector3D direction = line.getDirection();
         return contains(origin) && areCoplanar(u, v, direction, precision);
@@ -542,9 +537,8 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return the distance or 0.0, if the line is not parallel to the plane instance.
      */
     public double getOffset(final Line line) {
-        if (!isParallel(line))
-        {
-            return 0.0;
+        if (!isParallel(line)) {
+            return 0;
         }
         return getOffset(line.getOrigin());
     }
@@ -575,7 +569,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      */
     @Override
     public boolean sameOrientationAs(final Hyperplane<Vector3D> other) {
-        return (((Plane) other).w).dot(w) > 0.0;
+        return (((Plane) other).w).dot(w) > 0;
     }
 
     @Override
@@ -592,13 +586,13 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     /** {@inheritDoc} */
     @Override
     public boolean equals(Object obj) {
-        if (this == obj){
+        if (this == obj) {
             return true;
         }
-        if (obj == null){
+        if (obj == null) {
             return false;
         }
-        if (getClass() != obj.getClass()){
+        if (getClass() != obj.getClass()) {
             return false;
         }
         Plane other = (Plane) obj;
@@ -614,8 +608,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param precision precision context used to compare floating point values
      * @return true if vectors are coplanar, false otherwise.
      */
-    private static boolean areCoplanar(final Vector3D u, final Vector3D v, final Vector3D w, final DoublePrecisionContext precision)
-    {
+    private static boolean areCoplanar(final Vector3D u, final Vector3D v, final Vector3D w, final DoublePrecisionContext precision) {
         return precision.eqZero(u.dot(v.cross(w)));
     }
 }
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 957f38f..d250269 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
@@ -40,7 +40,7 @@ public class PlaneTest {
     public void testUAndVAreCollinear() {
         Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 2), TEST_PRECISION);
     }
-    
+
     @Test(expected=IllegalNormException.class)
     public void testUAndVAreCollinear2() {
         Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 0, -2), TEST_PRECISION);
@@ -50,7 +50,7 @@ public class PlaneTest {
     public void testPointsDoNotConstituteAPlane() {
         Plane.fromPoints(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 1, 0), TEST_PRECISION);
     }
-    
+
     @Test
     public void testContains() {
         Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
@@ -65,25 +65,25 @@ public class PlaneTest {
         Line line = new Line(Vector3D.of(1, 0, 1), Vector3D.of(2, 0, 1), TEST_PRECISION);
         Assert.assertTrue(plane.contains(line));
     }
-    
+
     @Test(expected=IllegalNormException.class)
     public void testFromPointPlaneVectorsWithZeroVector()
     {
         Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.ZERO, Vector3D.of(1,0,0), TEST_PRECISION);
     }
-    
+
     @Test(expected=IllegalNormException.class)
     public void testFromPointAndNormalWithZeroNormal()
     {
         Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.ZERO, TEST_PRECISION);
     }
-     
+
     @Test(expected=IllegalNormException.class)
     public void testFromNormal()
     {
         Plane.fromNormal(Vector3D.ZERO, TEST_PRECISION);
     }
-     
+
     @Test
     public void testIsParallelAndGetOffset()
     {
@@ -95,10 +95,10 @@ public class PlaneTest {
         Assert.assertFalse(plane.isParallel(nonParallelLine));
         Assert.assertEquals(0.0, plane.getOffset(nonParallelLine), TEST_EPS);
     }
-    
+
     @Test
     public void testCreation()
-    {  
+    {
         Vector3D normalAliasW =  Vector3D.of(0, 0, 1);
         Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1),normalAliasW , TEST_PRECISION);
         Assert.assertEquals(normalAliasW, plane.getW());
@@ -110,7 +110,7 @@ public class PlaneTest {
         Vector3D expectedOrigin = Vector3D.of(0, 0, 1);
         Assert.assertEquals(expectedOrigin, plane.getOrigin());
     }
-    
+
     @Test
     public void testReverse()
     {
@@ -124,7 +124,7 @@ public class PlaneTest {
         Vector3D p1XYswapped = Vector3D.of(0,1,1);
         Assert.assertTrue(reversePlane.contains(p1XYswapped));
     }
-    
+
     @Test
     public void testIsPlaneParallel()
     {
@@ -136,7 +136,7 @@ public class PlaneTest {
         Plane nonParallelPlane = Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(1, 1.5, 1), Vector3D.of(0,1,1), TEST_PRECISION);
         Assert.assertFalse(plane.isParallel(nonParallelPlane));
     }
-    
+
     @Test
     public void testProjectLine() {
         Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
@@ -144,7 +144,7 @@ public class PlaneTest {
         Line expectedProjection = new Line(Vector3D.of(1, 0, 1),Vector3D.of(2, 0, 1), TEST_PRECISION);
         Assert.assertEquals(expectedProjection, plane.project(line));
     }
-    
+
     @Test
     public void testOffset() {
         Vector3D p1 = Vector3D.of(1, 1, 1);
@@ -165,7 +165,7 @@ public class PlaneTest {
       Plane.fromPointAndPlaneVectors(Vector3D.of(1, 1, 1), Vector3D.of(2, 0, 0), Vector3D.of(2,0,0), TEST_PRECISION);
     }
 
-    
+
     @Test
     public void testVectorsAreNormalizedForSuppliedUAndV() {
         Plane plane = Plane.fromPointAndPlaneVectors(Vector3D.of(1, 1, 1), Vector3D.of(2, 0, 0), Vector3D.of(0,2,0), TEST_PRECISION);
@@ -174,8 +174,8 @@ public class PlaneTest {
         Assert.assertEquals(1.0, plane.getU().norm(), TEST_EPS);
     }
 
-    
-    
+
+
     @Test
     public void testVectorsAreNormalized() {
         Plane plane = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
@@ -184,7 +184,7 @@ public class PlaneTest {
         Assert.assertEquals(1.0, plane.getU().norm(), TEST_EPS);
     }
 
-    
+
     @Test
     public void testPoint() {
         Plane plane = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);


[commons-geometry] 10/16: GEOMETRY-29 working on Matts review. Part II

Posted by er...@apache.org.
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 e99a03bcaab4763cb57cefcb2faccc2b211fea5e
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Wed Apr 3 18:57:14 2019 +0200

    GEOMETRY-29 working on Matts review. Part II
---
 .../commons/geometry/euclidean/threed/Line.java    |  4 +-
 .../commons/geometry/euclidean/threed/Plane.java   | 95 +++++++++-------------
 .../geometry/euclidean/threed/Vector3D.java        |  2 +-
 .../geometry/euclidean/threed/PlaneTest.java       | 26 ++++--
 4 files changed, 57 insertions(+), 70 deletions(-)

diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
index 7bfd4a5..bd3c189 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
@@ -239,11 +239,9 @@ public class Line implements Embedding<Vector3D, Vector1D> {
         return new SubLine(this, new IntervalsSet(precision));
     }
     
-    
-
     @Override
     public int hashCode() {
-        throw new IllegalStateException("Must not be used in maps.");
+        return Objects.hash(direction, precision, zero);
     }
 
     @Override
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 c644a39..4e39954 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
@@ -45,7 +45,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     private final double originOffset;
 
     /** orthogonal projection of the 3D-space origin in the plane. */
-    private final Vector3D projectedOrigin;
+    private final Vector3D origin;
     
     /** Precision context used to compare floating point numbers. */
     private final DoublePrecisionContext precision;
@@ -56,25 +56,21 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param u u vector (on plane)
      * @param v v vector (on plane)
      * @param w unit normal vector
-     * @param projectedOrigin orthogonal projection of the 3D-space origin in the plane.
+     * @param origin orthogonal projection of the 3D-space origin in the plane.
      * @param precision precision context used to compare floating point values
      * @throws IllegalArgumentException if the provided vectors are coplanar or not normalized
      */
-    private Plane(Vector3D u, Vector3D v, Vector3D w, Vector3D projectedOrigin, double originOffset,
-            DoublePrecisionContext precision) {
+    private Plane(final Vector3D u, final Vector3D v, final Vector3D w, final Vector3D origin, double originOffset,
+            final DoublePrecisionContext precision) {
         this.u = u;
         this.v = v;
         this.w = w;
-        
-        if (!areVectorsNormalized(u, v, w, precision))
-        {
-            throw new IllegalArgumentException("Provided vectors must be normalized.");
-        }
+      
         if (Vector3D.areCoplanar(u, v, w, precision))
         {
             throw new IllegalArgumentException("Provided vectors must not be coplanar.");
         }
-        this.projectedOrigin = projectedOrigin;
+        this.origin = origin;
         this.originOffset = originOffset;
         this.precision = precision;
     }
@@ -89,14 +85,14 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @throws IllegalNormException if the norm of the given values is zero, NaN, or infinite.
      * @throws IllegalArgumentException if the provided vectors are collinear 
      */
-    public static Plane fromPointAndPlaneVectors (Vector3D p, final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
+    public static Plane fromPointAndPlaneVectors (final Vector3D p, final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
     {
         Vector3D uNorm = u.normalize();
-        Vector3D vNorm = v.normalize();
+        Vector3D vNorm = uNorm.orthogonal(v);
         Vector3D wNorm = uNorm.cross(vNorm).normalize();
         double originOffset = -p.dot(wNorm);
-        Vector3D projectedOrigin = calculateOrigin(wNorm, originOffset);
-        return new Plane(uNorm, vNorm, wNorm, projectedOrigin, originOffset, precision);
+        Vector3D origin = calculateOrigin(wNorm, originOffset);
+        return new Plane(uNorm, vNorm, wNorm, origin, originOffset, precision);
     }
     
     /**
@@ -123,10 +119,10 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public static Plane fromPointAndNormal(final Vector3D p, final Vector3D normal, final DoublePrecisionContext precision) {
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
+        Vector3D origin = calculateOrigin(w, originOffset);
         Vector3D u = w.orthogonal();
         Vector3D v = w.cross(u);
-        return new Plane(u, v, w, projectedOrigin, originOffset, precision);
+        return new Plane(u, v, w, origin, originOffset, precision);
     }
     
     /**
@@ -146,22 +142,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
             final DoublePrecisionContext precision) {
         return Plane.fromPointAndNormal(p1, p1.vectorTo(p2).cross(p1.vectorTo(p3)), precision);
     }
-
-    /**
-     * Copy plane.
-     * <p>
-     * The instance created is completely independent of the original one. A deep
-     * copy is used, none of the underlying object are shared.
-     * </p>
-     * 
-     * @param plane plane to copy
-     * @return a new plane
-     */
-    public static Plane of(Plane plane) {
-        return new Plane(plane.u, plane.v, plane.w, plane.projectedOrigin, plane.originOffset, plane.getPrecision());
-    }
-
-    
+   
     // This should be removed after GEOMETRY-32 is done.
     
     /**
@@ -177,7 +158,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     @Deprecated
     @Override
     public Plane copySelf() {
-        return new Plane(this.u, this.v, this.w, this.projectedOrigin, this.originOffset, this.precision);
+        return new Plane(this.u, this.v, this.w, this.origin, this.originOffset, this.precision);
     }
 
     /**
@@ -186,7 +167,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      *         origin)
      */
     public Vector3D getOrigin() {
-        return projectedOrigin;
+        return origin;
     }
     
     /**
@@ -261,7 +242,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     
     /** {@inheritDoc} */
     @Override
-    public Vector3D project(Vector3D point) {
+    public Vector3D project(final Vector3D point) {
         return toSpace(toSubSpace(point));
     }
 
@@ -270,10 +251,10 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param line the line to project
      * @return the projection of the given line onto the plane.
      */
-    public Line project(Line line)
+    public Line project(final Line line)
     {
         Vector3D direction = line.getDirection();
-        Vector3D projection = w.multiply(direction.dot(w)).multiply(1/w.normSq());
+        Vector3D projection = w.multiply(direction.dot(w) * (1/w.normSq()));
         Vector3D projectedLineDirection = direction.subtract(projection);
         Vector3D p1 = project(line.getOrigin());
         Vector3D p2 = p1.add(projectedLineDirection);
@@ -305,8 +286,8 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         Vector3D v = tmp;
         Vector3D w = this.w.negate();
         double originOffset = -this.originOffset;
-        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
-        return new Plane(u, v, w, projectedOrigin, originOffset, this.precision);
+        Vector3D origin = calculateOrigin(w, originOffset);
+        return new Plane(u, v, w, origin, originOffset, this.precision);
     }
 
     /**
@@ -356,7 +337,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane plane to which the instance is compared
      * @return true if the planes are similar
      */
-    public boolean contains(Plane plane) {
+    public boolean contains(final Plane plane) {
         final double angle = w.angle(plane.w);
         return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset))
                 || ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
@@ -375,15 +356,15 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return a new plane
      */
     public Plane rotate(final Vector3D center, final QuaternionRotation rotation) {
-        final Vector3D delta = projectedOrigin.subtract(center);
+        final Vector3D delta = origin.subtract(center);
         Vector3D p = center.add(rotation.apply(delta));
         Vector3D normal = rotation.apply(this.w);
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
+        Vector3D origin = calculateOrigin(w, originOffset);
         Vector3D u = rotation.apply(this.u);
         Vector3D v = rotation.apply(this.v);
-        return new Plane(u, v, w, projectedOrigin, originOffset, this.precision);
+        return new Plane(u, v, w, origin, originOffset, this.precision);
     }
 
     /**
@@ -396,12 +377,12 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return a new plane
      */
     public Plane translate(final Vector3D translation) {
-        Vector3D p = projectedOrigin.add(translation);
+        Vector3D p = origin.add(translation);
         Vector3D normal = this.w;
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
-        return new Plane(this.u, this.v, w, projectedOrigin, originOffset, this.precision);
+        Vector3D origin = calculateOrigin(w, originOffset);
+        return new Plane(this.u, this.v, w, origin, originOffset, this.precision);
     }
 
     /**
@@ -429,7 +410,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return line at the intersection of the instance and the other plane (really
      *         a {@link Line Line} instance)
      */
-    public Line intersection(Plane other) {
+    public Line intersection(final Plane other) {
         final Vector3D direction = w.cross(other.w);
         if (precision.eqZero(direction.norm())) {
             return null;
@@ -446,7 +427,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane3 third plane2
      * @return intersection point of three planes, null if some planes are parallel
      */
-    public static Vector3D intersection(Plane plane1, Plane plane2, Plane plane3) {
+    public static Vector3D intersection(final Plane plane1, final Plane plane2, final Plane plane3) {
 
         // coefficients of the three planes linear equations
         final double a1 = plane1.w.getX();
@@ -517,7 +498,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param line line to check
      * @return true if line is contained in this plane
      */
-    public boolean contains(Line line)
+    public boolean contains(final Line line)
     {
         Vector3D origin = line.getOrigin();
         Vector3D direction = line.getDirection();
@@ -528,7 +509,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param line line to check.
      * @return true if the line is parallel to the instance, false otherwise.
      */
-    public boolean isParallel(Line line) {
+    public boolean isParallel(final Line line) {
         final Vector3D direction = line.getDirection();
         final double   dot       = w.dot(direction);
         if (precision.eqZero(dot)) {
@@ -541,7 +522,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane plane to check.
      * @return true if the plane is parallel to the instance, false otherwise.
      */
-    public boolean isParallel(Plane plane) {
+    public boolean isParallel(final Plane plane) {
         return precision.eqZero(w.cross(plane.w).norm());
     }
 
@@ -561,7 +542,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane plane to check
      * @return offset of the plane
      */
-    public double getOffset(Plane plane) {
+    public double getOffset(final Plane plane) {
         return originOffset + (sameOrientationAs(plane) ? -plane.originOffset : plane.originOffset);
     }
 
@@ -571,7 +552,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param line to calculate the distance to the plane instance
      * @return the distance or 0.0, if the line is not parallel to the plane instance.
      */
-    public double getOffset(Line line) {
+    public double getOffset(final Line line) {
         if (!isParallel(line))
         {
             return 0.0;
@@ -608,17 +589,15 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         return (((Plane) other).w).dot(w) > 0.0;
     }
 
-    /** {@inheritDoc} */
     @Override
     public String toString() {
-        return "Plane [originOffset=" + originOffset + ", projectedOrigin=" + projectedOrigin + ", u=" + u + ", v=" + v + ", w=" + w
-                + ", precision=" + precision + "]";
+        return "Plane [u=" + u + ", v=" + v + ", w=" + w + ", origin=" + origin + "]";
     }
 
     /** {@inheritDoc} */
     @Override
     public int hashCode() {
-        return Objects.hash(projectedOrigin, originOffset, u, v, w);
+        return Objects.hash(origin, originOffset, u, v, w);
     }
 
     /** {@inheritDoc} */
@@ -631,7 +610,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         if (getClass() != obj.getClass())
             return false;
         Plane other = (Plane) obj;
-        return Objects.equals(projectedOrigin, other.projectedOrigin)
+        return Objects.equals(origin, other.origin)
                 && Double.doubleToLongBits(originOffset) == Double.doubleToLongBits(other.originOffset)
                 && Objects.equals(u, other.u) && Objects.equals(v, other.v) && Objects.equals(w, other.w);
     }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
index c92c1ac..1b54d0b 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
@@ -379,7 +379,7 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> {
      * @param precision precision context used to compare floating point values
      * @return true if vectors are coplanar, false otherwise.
      */
-    public static boolean areCoplanar(Vector3D u, Vector3D v, Vector3D w, DoublePrecisionContext precision)
+    public static boolean areCoplanar(final Vector3D u, final Vector3D v, final Vector3D w, final DoublePrecisionContext precision)
     {
         return precision.eqZero(u.dot(v.cross(w)));
     }
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 5dde469..957f38f 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
@@ -66,6 +66,24 @@ public class PlaneTest {
         Assert.assertTrue(plane.contains(line));
     }
     
+    @Test(expected=IllegalNormException.class)
+    public void testFromPointPlaneVectorsWithZeroVector()
+    {
+        Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.ZERO, Vector3D.of(1,0,0), TEST_PRECISION);
+    }
+    
+    @Test(expected=IllegalNormException.class)
+    public void testFromPointAndNormalWithZeroNormal()
+    {
+        Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.ZERO, TEST_PRECISION);
+    }
+     
+    @Test(expected=IllegalNormException.class)
+    public void testFromNormal()
+    {
+        Plane.fromNormal(Vector3D.ZERO, TEST_PRECISION);
+    }
+     
     @Test
     public void testIsParallelAndGetOffset()
     {
@@ -79,14 +97,6 @@ public class PlaneTest {
     }
     
     @Test
-    public void testCopy()
-    {
-        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
-        Plane copyPlane = Plane.of(plane);
-        Assert.assertEquals(plane, copyPlane); 
-    }
-    
-    @Test
     public void testCreation()
     {  
         Vector3D normalAliasW =  Vector3D.of(0, 0, 1);


[commons-geometry] 04/16: GEOMETRY-29 rename fromThreePoints to fromPoints, corrects typos. adds getW, adds getOriginOffset, renames fromTwoVectors to fromPlaneVectors.

Posted by er...@apache.org.
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 <sv...@dfs.de>
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];


[commons-geometry] 08/16: GEOMETRY-29 adds tests

Posted by er...@apache.org.
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 c206720b669c56dfb8af1e9c5d3579ab25e59b28
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Mon Mar 25 16:35:12 2019 +0100

    GEOMETRY-29 adds tests
---
 .../commons/geometry/euclidean/threed/Plane.java   |  18 +-
 .../geometry/euclidean/threed/PlaneTest.java       | 224 +++++++++++++--------
 2 files changed, 154 insertions(+), 88 deletions(-)

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 59e83ea..d0556da 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
@@ -78,7 +78,6 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         this.originOffset = originOffset;
         this.precision = precision;
     }
-
     
     /**
      * Build a plane from a point and two (on plane) vectors.
@@ -94,10 +93,10 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     {
         Vector3D u_norm = u.normalize();
         Vector3D v_norm = v.normalize();
-        Vector3D w = u_norm.cross(v_norm);
-        double originOffset = -p.dot(w);
-        Vector3D projectedOrigin = calculateOrigin(w, originOffset);
-        return new Plane(u_norm, v_norm, w, projectedOrigin, originOffset, precision);
+        Vector3D w_norm = u_norm.cross(v_norm).normalize();
+        double originOffset = -p.dot(w_norm);
+        Vector3D projectedOrigin = calculateOrigin(w_norm, originOffset);
+        return new Plane(u_norm, v_norm, w_norm, projectedOrigin, originOffset, precision);
     }
     
     /**
@@ -535,7 +534,14 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         return false;
     }
 
-    
+    /** Check, if the plane is parallel to the instance.
+     * @param plane plane to check.
+     * @return true if the plane is parallel to the instance, false otherwise.
+     */
+    public boolean isParallel(Plane plane) {
+        return precision.eqZero(w.cross(plane.w).norm());
+    }
+
     
     /**
      * Get the offset (oriented distance) of a parallel 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 ac0efae..5dde469 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
@@ -31,17 +31,17 @@ public class PlaneTest {
     private static final DoublePrecisionContext TEST_PRECISION =
             new EpsilonDoublePrecisionContext(TEST_EPS);
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected=IllegalNormException.class)
     public void testUAndVAreIdentical() {
         Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
     }
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected=IllegalNormException.class)
     public void testUAndVAreCollinear() {
         Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 2), TEST_PRECISION);
     }
     
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected=IllegalNormException.class)
     public void testUAndVAreCollinear2() {
         Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 0, -2), TEST_PRECISION);
     }
@@ -53,43 +53,103 @@ public class PlaneTest {
     
     @Test
     public void testContains() {
-        Plane p = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
-        Assert.assertTrue(p.contains(Vector3D.of(0, 0, 1)));
-        Assert.assertTrue(p.contains(Vector3D.of(17, -32, 1)));
-        Assert.assertTrue(! p.contains(Vector3D.of(17, -32, 1.001)));
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Assert.assertTrue(plane.contains(Vector3D.of(0, 0, 1)));
+        Assert.assertTrue(plane.contains(Vector3D.of(17, -32, 1)));
+        Assert.assertTrue(! plane.contains(Vector3D.of(17, -32, 1.001)));
     }
 
     @Test
     public void testContainsLine() {
-        Plane p = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
         Line line = new Line(Vector3D.of(1, 0, 1), Vector3D.of(2, 0, 1), TEST_PRECISION);
-        Assert.assertTrue(p.contains(line));
+        Assert.assertTrue(plane.contains(line));
+    }
+    
+    @Test
+    public void testIsParallelAndGetOffset()
+    {
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Line parallelLine = new Line(Vector3D.of(1, 0, 2), Vector3D.of(2, 0, 2), TEST_PRECISION);
+        Assert.assertTrue(plane.isParallel(parallelLine));
+        Assert.assertEquals(1.0, plane.getOffset(parallelLine), TEST_EPS);
+        Line nonParallelLine = new Line(Vector3D.of(1, 0, 2), Vector3D.of(2, 0, 1), TEST_PRECISION);
+        Assert.assertFalse(plane.isParallel(nonParallelLine));
+        Assert.assertEquals(0.0, plane.getOffset(nonParallelLine), TEST_EPS);
+    }
+    
+    @Test
+    public void testCopy()
+    {
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Plane copyPlane = Plane.of(plane);
+        Assert.assertEquals(plane, copyPlane); 
     }
     
+    @Test
+    public void testCreation()
+    {  
+        Vector3D normalAliasW =  Vector3D.of(0, 0, 1);
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1),normalAliasW , TEST_PRECISION);
+        Assert.assertEquals(normalAliasW, plane.getW());
+        double expectedX = 1.0;
+        Assert.assertEquals(expectedX,  Math.abs(plane.getV().getX()), TEST_EPS);
+        double expectedY = 1.0;
+        Assert.assertEquals(expectedY,  Math.abs(plane.getU().getY()), TEST_EPS);
+        Assert.assertEquals(-1.0, plane.getOriginOffset(), TEST_EPS);
+        Vector3D expectedOrigin = Vector3D.of(0, 0, 1);
+        Assert.assertEquals(expectedOrigin, plane.getOrigin());
+    }
+    
+    @Test
+    public void testReverse()
+    {
+        Vector3D normalAliasW =  Vector3D.of(0, 0, 1);
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1),normalAliasW , TEST_PRECISION);
+        Assert.assertEquals(-1.0, plane.getOriginOffset(), TEST_EPS);
+        Vector3D p1 = Vector3D.of(1,0,1);
+        Assert.assertTrue(plane.contains(p1));
+        Plane reversePlane = plane.reverse();
+        Assert.assertEquals(1.0, reversePlane.getOriginOffset(), TEST_EPS);
+        Vector3D p1XYswapped = Vector3D.of(0,1,1);
+        Assert.assertTrue(reversePlane.contains(p1XYswapped));
+    }
+    
+    @Test
+    public void testIsPlaneParallel()
+    {
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Plane parallelPlane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Plane parallelPlane2 = Plane.fromPointAndNormal(Vector3D.of(0, 0, 2), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Assert.assertTrue(plane.isParallel(parallelPlane));
+        Assert.assertTrue(plane.isParallel(parallelPlane2));
+        Plane nonParallelPlane = Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(1, 1.5, 1), Vector3D.of(0,1,1), TEST_PRECISION);
+        Assert.assertFalse(plane.isParallel(nonParallelPlane));
+    }
     
     @Test
     public void testProjectLine() {
-        Plane p = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
         Line line = new Line(Vector3D.of(1, 0, 1), Vector3D.of(2, 0, 2), TEST_PRECISION);
         Line expectedProjection = new Line(Vector3D.of(1, 0, 1),Vector3D.of(2, 0, 1), TEST_PRECISION);
-        Assert.assertEquals(expectedProjection, p.project(line));
+        Assert.assertEquals(expectedProjection, plane.project(line));
     }
     
     @Test
     public void testOffset() {
         Vector3D p1 = Vector3D.of(1, 1, 1);
-        Plane p = Plane.fromPointAndNormal(p1, Vector3D.of(0.2, 0, 0), TEST_PRECISION);
-        Assert.assertEquals(-5.0, p.getOffset(Vector3D.of(-4, 0, 0)), TEST_EPS);
-        Assert.assertEquals(+5.0, p.getOffset(Vector3D.of(6, 10, -12)), TEST_EPS);
+        Plane plane = Plane.fromPointAndNormal(p1, Vector3D.of(0.2, 0, 0), TEST_PRECISION);
+        Assert.assertEquals(-5.0, plane.getOffset(Vector3D.of(-4, 0, 0)), TEST_EPS);
+        Assert.assertEquals(+5.0, plane.getOffset(Vector3D.of(6, 10, -12)), TEST_EPS);
         Assert.assertEquals(0.3,
-                            p.getOffset(Vector3D.linearCombination(1.0, p1, 0.3, p.getNormal())),
+                            plane.getOffset(Vector3D.linearCombination(1.0, p1, 0.3, plane.getNormal())),
                             TEST_EPS);
         Assert.assertEquals(-0.3,
-                            p.getOffset(Vector3D.linearCombination(1.0, p1, -0.3, p.getNormal())),
+                            plane.getOffset(Vector3D.linearCombination(1.0, p1, -0.3, plane.getNormal())),
                             TEST_EPS);
     }
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected=IllegalNormException.class)
     public void testVectorsAreColinear()
     {
       Plane.fromPointAndPlaneVectors(Vector3D.of(1, 1, 1), Vector3D.of(2, 0, 0), Vector3D.of(2,0,0), TEST_PRECISION);
@@ -98,27 +158,27 @@ public class PlaneTest {
     
     @Test
     public void testVectorsAreNormalizedForSuppliedUAndV() {
-        Plane p = Plane.fromPointAndPlaneVectors(Vector3D.of(1, 1, 1), Vector3D.of(2, 0, 0), Vector3D.of(0,2,0), TEST_PRECISION);
-        Assert.assertEquals(1.0, p.getNormal().norm(), TEST_EPS);
-        Assert.assertEquals(1.0, p.getV().norm(), TEST_EPS);
-        Assert.assertEquals(1.0, p.getU().norm(), TEST_EPS);
+        Plane plane = Plane.fromPointAndPlaneVectors(Vector3D.of(1, 1, 1), Vector3D.of(2, 0, 0), Vector3D.of(0,2,0), TEST_PRECISION);
+        Assert.assertEquals(1.0, plane.getNormal().norm(), TEST_EPS);
+        Assert.assertEquals(1.0, plane.getV().norm(), TEST_EPS);
+        Assert.assertEquals(1.0, plane.getU().norm(), TEST_EPS);
     }
 
     
     
     @Test
     public void testVectorsAreNormalized() {
-        Plane p = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
-        Assert.assertEquals(1.0, p.getNormal().norm(), TEST_EPS);
-        Assert.assertEquals(1.0, p.getV().norm(), TEST_EPS);
-        Assert.assertEquals(1.0, p.getU().norm(), TEST_EPS);
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
+        Assert.assertEquals(1.0, plane.getNormal().norm(), TEST_EPS);
+        Assert.assertEquals(1.0, plane.getV().norm(), TEST_EPS);
+        Assert.assertEquals(1.0, plane.getU().norm(), TEST_EPS);
     }
 
     
     @Test
     public void testPoint() {
-        Plane p = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
-        Assert.assertTrue(p.contains(p.getOrigin()));
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
+        Assert.assertTrue(plane.contains(plane.getOrigin()));
     }
 
     @Test
@@ -126,10 +186,10 @@ 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.fromPoints(p1, p2, p3, TEST_PRECISION);
-        Assert.assertTrue(p.contains(p1));
-        Assert.assertTrue(p.contains(p2));
-        Assert.assertTrue(p.contains(p3));
+        Plane    plane  = Plane.fromPoints(p1, p2, p3, TEST_PRECISION);
+        Assert.assertTrue(plane.contains(p1));
+        Assert.assertTrue(plane.contains(p2));
+        Assert.assertTrue(plane.contains(p3));
     }
 
     @Test
@@ -137,23 +197,23 @@ 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.fromPoints(p1, p2, p3, TEST_PRECISION);
-        Vector3D oldNormal = p.getNormal();
+        Plane    plane  = Plane.fromPoints(p1, p2, p3, TEST_PRECISION);
+        Vector3D oldNormal = plane.getNormal();
 
-        p = p.rotate(p2, QuaternionRotation.fromAxisAngle(p2.subtract(p1), 1.7));
-        Assert.assertTrue(p.contains(p1));
-        Assert.assertTrue(p.contains(p2));
-        Assert.assertTrue(! p.contains(p3));
+        plane = plane.rotate(p2, QuaternionRotation.fromAxisAngle(p2.subtract(p1), 1.7));
+        Assert.assertTrue(plane.contains(p1));
+        Assert.assertTrue(plane.contains(p2));
+        Assert.assertTrue(! plane.contains(p3));
 
-        p = p.rotate(p2, QuaternionRotation.fromAxisAngle(oldNormal, 0.1));
-        Assert.assertTrue(! p.contains(p1));
-        Assert.assertTrue(p.contains(p2));
-        Assert.assertTrue(! p.contains(p3));
+        plane = plane.rotate(p2, QuaternionRotation.fromAxisAngle(oldNormal, 0.1));
+        Assert.assertTrue(! plane.contains(p1));
+        Assert.assertTrue(plane.contains(p2));
+        Assert.assertTrue(! plane.contains(p3));
 
-        p = p.rotate(p1, QuaternionRotation.fromAxisAngle(oldNormal, 0.1));
-        Assert.assertTrue(! p.contains(p1));
-        Assert.assertTrue(! p.contains(p2));
-        Assert.assertTrue(! p.contains(p3));
+        plane = plane.rotate(p1, QuaternionRotation.fromAxisAngle(oldNormal, 0.1));
+        Assert.assertTrue(! plane.contains(p1));
+        Assert.assertTrue(! plane.contains(p2));
+        Assert.assertTrue(! plane.contains(p3));
 
     }
 
@@ -162,34 +222,34 @@ 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.fromPoints(p1, p2, p3, TEST_PRECISION);
+        Plane    plane  = 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));
-        Assert.assertTrue(p.contains(p2));
-        Assert.assertTrue(p.contains(p3));
+        plane = plane.translate(Vector3D.linearCombination(2.0, plane.getU(), -1.5, plane.getV()));
+        Assert.assertTrue(plane.contains(p1));
+        Assert.assertTrue(plane.contains(p2));
+        Assert.assertTrue(plane.contains(p3));
 
-        p = p.translate(Vector3D.linearCombination(-1.2, p.getNormal()));
-        Assert.assertTrue(! p.contains(p1));
-        Assert.assertTrue(! p.contains(p2));
-        Assert.assertTrue(! p.contains(p3));
+        plane = plane.translate(Vector3D.linearCombination(-1.2, plane.getNormal()));
+        Assert.assertTrue(! plane.contains(p1));
+        Assert.assertTrue(! plane.contains(p2));
+        Assert.assertTrue(! plane.contains(p3));
 
-        p = p.translate(Vector3D.linearCombination(+1.2, p.getNormal()));
-        Assert.assertTrue(p.contains(p1));
-        Assert.assertTrue(p.contains(p2));
-        Assert.assertTrue(p.contains(p3));
+        plane = plane.translate(Vector3D.linearCombination(+1.2, plane.getNormal()));
+        Assert.assertTrue(plane.contains(p1));
+        Assert.assertTrue(plane.contains(p2));
+        Assert.assertTrue(plane.contains(p3));
 
     }
 
     @Test
     public void testIntersection() {
-        Plane p = Plane.fromPointAndNormal(Vector3D.of(1, 2, 3), Vector3D.of(-4, 1, -5), TEST_PRECISION);
-        Line  l = new Line(Vector3D.of(0.2, -3.5, 0.7), Vector3D.of(1.2, -2.5, -0.3), TEST_PRECISION);
-        Vector3D point = p.intersection(l);
-        Assert.assertTrue(p.contains(point));
-        Assert.assertTrue(l.contains(point));
-        Assert.assertNull(p.intersection(new Line(Vector3D.of(10, 10, 10),
-                                                  Vector3D.of(10, 10, 10).add(p.getNormal().orthogonal()),
+        Plane plane = Plane.fromPointAndNormal(Vector3D.of(1, 2, 3), Vector3D.of(-4, 1, -5), TEST_PRECISION);
+        Line  line = new Line(Vector3D.of(0.2, -3.5, 0.7), Vector3D.of(1.2, -2.5, -0.3), TEST_PRECISION);
+        Vector3D point = plane.intersection(line);
+        Assert.assertTrue(plane.contains(point));
+        Assert.assertTrue(line.contains(point));
+        Assert.assertNull(plane.intersection(new Line(Vector3D.of(10, 10, 10),
+                                                  Vector3D.of(10, 10, 10).add(plane.getNormal().orthogonal()),
                                                   TEST_PRECISION)));
     }
 
@@ -197,12 +257,12 @@ 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.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));
-        Assert.assertNull(pA.intersection(pA));
+        Plane    planeA  = Plane.fromPoints(p1, p2, Vector3D.of(-2.0, 4.3, 0.7), TEST_PRECISION);
+        Plane    planeB  = Plane.fromPoints(p1, Vector3D.of(11.4, -3.8, 5.1), p2, TEST_PRECISION);
+        Line     line   = planeA.intersection(planeB);
+        Assert.assertTrue(line.contains(p1));
+        Assert.assertTrue(line.contains(p2));
+        Assert.assertNull(planeA.intersection(planeA));
     }
 
     @Test
@@ -211,10 +271,10 @@ public class PlaneTest {
         Plane p1 = Plane.fromPointAndNormal(reference, Vector3D.of(1, 3, 3), TEST_PRECISION);
         Plane p2 = Plane.fromPointAndNormal(reference, Vector3D.of(-2, 4, 0), TEST_PRECISION);
         Plane p3 = Plane.fromPointAndNormal(reference, Vector3D.of(7, 0, -4), TEST_PRECISION);
-        Vector3D p = Plane.intersection(p1, p2, p3);
-        Assert.assertEquals(reference.getX(), p.getX(), TEST_EPS);
-        Assert.assertEquals(reference.getY(), p.getY(), TEST_EPS);
-        Assert.assertEquals(reference.getZ(), p.getZ(), TEST_EPS);
+        Vector3D plane = Plane.intersection(p1, p2, p3);
+        Assert.assertEquals(reference.getX(), plane.getX(), TEST_EPS);
+        Assert.assertEquals(reference.getY(), plane.getY(), TEST_EPS);
+        Assert.assertEquals(reference.getZ(), plane.getZ(), TEST_EPS);
     }
 
     @Test
@@ -222,13 +282,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.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.contains(pB));
-        Assert.assertTrue(pA.contains(pA));
-        Assert.assertTrue(pA.contains(Plane.fromPoints(p1, p3, p2, TEST_PRECISION)));
-        Vector3D shift = Vector3D.linearCombination(0.3, pA.getNormal());
-        Assert.assertTrue(! pA.contains(Plane.fromPoints(p1.add(shift),
+        Plane    planeA  = Plane.fromPoints(p1, p2, p3, TEST_PRECISION);
+        Plane    planeB  = Plane.fromPoints(p1, Vector3D.of(11.4, -3.8, 5.1), p2, TEST_PRECISION);
+        Assert.assertTrue(! planeA.contains(planeB));
+        Assert.assertTrue(planeA.contains(planeA));
+        Assert.assertTrue(planeA.contains(Plane.fromPoints(p1, p3, p2, TEST_PRECISION)));
+        Vector3D shift = Vector3D.linearCombination(0.3, planeA.getNormal());
+        Assert.assertTrue(! planeA.contains(Plane.fromPoints(p1.add(shift),
                                                      p3.add(shift),
                                                      p2.add(shift),
                                                      TEST_PRECISION)));


[commons-geometry] 01/16: GEOMETRY-29 first version.

Posted by er...@apache.org.
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 73b19620e5b701845b75f71ce3cfbe0af82bc318
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Fri Mar 15 15:10:48 2019 +0100

    GEOMETRY-29 first version.
---
 .../threed/enclosing/SphereGenerator.java          |   2 +-
 .../commons/geometry/euclidean/threed/Plane.java   | 495 ++++++++++++---------
 .../geometry/euclidean/threed/PolyhedronsSet.java  |  14 +-
 .../geometry/euclidean/threed/Vector3D.java        |   2 +-
 .../geometry/euclidean/EuclideanTestUtils.java     |   2 +-
 .../geometry/euclidean/threed/PlaneTest.java       |  54 +--
 .../euclidean/threed/PolyhedronsSetTest.java       |  38 +-
 7 files changed, 349 insertions(+), 258 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 471fab8..c7e3d47 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 = new Plane(vA, vB, vC, precision);
+                        final Plane p = Plane.fromThreePoints(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 f390de6..8060a8b 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
@@ -16,7 +16,8 @@
  */
 package org.apache.commons.geometry.euclidean.threed;
 
-import org.apache.commons.geometry.core.exception.IllegalNormException;
+import java.util.Objects;
+
 import org.apache.commons.geometry.core.partitioning.Embedding;
 import org.apache.commons.geometry.core.partitioning.Hyperplane;
 import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
@@ -26,152 +27,173 @@ import org.apache.commons.geometry.euclidean.threed.rotation.QuaternionRotation;
 import org.apache.commons.geometry.euclidean.twod.PolygonsSet;
 import org.apache.commons.geometry.euclidean.twod.Vector2D;
 
-/** The class represent planes in a three dimensional space.
+/**
+ * The class represent planes in a three dimensional space.
  */
-public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D> {
+public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D> {
 
     /** Offset of the origin with respect to the plane. */
-    private double originOffset;
+    private final double originOffset;
 
     /** Origin of the plane frame. */
-    private Vector3D origin;
+    private final Vector3D origin;
 
     /** First vector of the plane frame (in plane). */
-    private Vector3D u;
+    private final Vector3D u;
 
     /** Second vector of the plane frame (in plane). */
-    private Vector3D v;
+    private final Vector3D v;
 
     /** Third vector of the plane frame (plane normal). */
-    private Vector3D w;
+    private final Vector3D w;
 
     /** Precision context used to compare floating point numbers. */
     private final DoublePrecisionContext precision;
 
-    /** Build a plane normal to a given direction and containing the origin.
-     * @param normal normal direction to the plane
-     * @param precision precision context used to compare floating point values
-     * @exception IllegalArgumentException if the normal norm is too small
-     */
-    public Plane(final Vector3D normal, final DoublePrecisionContext precision)
-        throws IllegalArgumentException {
-        setNormal(normal);
-        this.precision = precision;
-        originOffset = 0;
-        setFrame();
+    public static Plane fromTwoVectors (final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
+    {
+        Vector3D w = u.cross(v);
+        double originOffset = 0;
+        Vector3D origin = calculateOrigin(w, originOffset);
+        return new Plane(u, v, w, origin, originOffset, precision);
+    }
+    
+    public static Plane fromNormal(final Vector3D normal, final DoublePrecisionContext precision)
+            throws IllegalArgumentException {
+        Vector3D w = calculateW(normal);
+        double originOffset = 0;
+        Vector3D origin = calculateOrigin(w, originOffset);
+        Vector3D u = w.orthogonal();
+        Vector3D v = w.cross(u);
+        return new Plane(u, v, w, origin, originOffset, precision);
     }
 
-    /** Build a plane from a point and a normal.
-     * @param p point belonging to the plane
-     * @param normal normal direction to the plane
+    private static Vector3D calculateOrigin(Vector3D w, double originOffset) {
+        return w.multiply(-originOffset);
+    }
+
+    private static Vector3D calculateW(final Vector3D normal) {
+        final double norm = Vectors.checkedNorm(normal);
+        return normal.multiply(1.0 / norm);
+    }
+
+    /**
+     * Build a plane from a point and a normal.
+     * 
+     * @param p         point belonging to the plane
+     * @param normal    normal direction to the plane
      * @param precision precision context used to compare floating point values
      * @exception IllegalArgumentException if the normal norm is too small
      */
-    public Plane(final Vector3D p, final Vector3D normal, final DoublePrecisionContext precision)
-        throws IllegalArgumentException {
-        setNormal(normal);
-        this.precision = precision;
-        this.originOffset = -p.dot(w);
-        setFrame();
+    public static Plane fromPointAndNormal(final Vector3D p, final Vector3D normal, final DoublePrecisionContext precision)
+            throws IllegalArgumentException {
+        Vector3D w = calculateW(normal);
+        double originOffset = -p.dot(w);
+        Vector3D origin = calculateOrigin(w, originOffset);
+        Vector3D u = w.orthogonal();
+        Vector3D v = w.cross(u);
+        return new Plane(u, v, w, origin, originOffset, precision);
     }
 
-    /** Build a plane from three points.
-     * <p>The plane is oriented in the direction of
-     * {@code (p2-p1) ^ (p3-p1)}</p>
-     * @param p1 first point belonging to the plane
-     * @param p2 second point belonging to the plane
-     * @param p3 third point belonging to the plane
+    // TODO check this one
+    public static Plane of(Vector3D u, Vector3D v, Vector3D w, Vector3D origin, double originOffset,
+            DoublePrecisionContext precision) {
+        if (!w.orthogonal().equals(u, precision))
+        {
+            throw new IllegalArgumentException("w must be orthogonal to u.");
+        }
+        return new Plane(u, v, w, origin, originOffset, precision);
+    }
+
+    /**
+     * Build a plane from three points.
+     * <p>
+     * The plane is oriented in the direction of {@code (p2-p1) ^ (p3-p1)}
+     * </p>
+     * 
+     * @param p1        first point belonging to the plane
+     * @param p2        second point belonging to the plane
+     * @param p3        third point belonging to the plane
      * @param precision precision context used to compare floating point values
      * @exception IllegalArgumentException if the points do not constitute a plane
      */
-    public Plane(final Vector3D p1, final Vector3D p2, final Vector3D p3, final DoublePrecisionContext precision)
-        throws IllegalArgumentException {
-        this(p1, p2.subtract(p1).cross(p3.subtract(p1)), precision);
+    public static Plane fromThreePoints(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);
     }
 
-    /** Copy constructor.
-     * <p>The instance created is completely independent of the original
-     * one. A deep copy is used, none of the underlying object are
-     * shared.</p>
+    /**
+     * Copy constructor.
+     * <p>
+     * The instance created is completely independent of the original one. A deep
+     * copy is used, none of the underlying object are shared.
+     * </p>
+     * 
      * @param plane plane to copy
      */
-    public Plane(final Plane plane) {
-        originOffset = plane.originOffset;
-        origin       = plane.origin;
-        u            = plane.u;
-        v            = plane.v;
-        w            = plane.w;
-        precision    = plane.precision;
-    }
-
-    /** Copy the instance.
-     * <p>The instance created is completely independant of the original
-     * one. A deep copy is used, none of the underlying objects are
-     * shared (except for immutable objects).</p>
-     * @return a new hyperplane, copy of the instance
-     */
-    @Override
-    public Plane copySelf() {
-        return new Plane(this);
-    }
-
-    /** Reset the instance as if built from a point and a normal.
-     * @param p point belonging to the plane
-     * @param normal normal direction to the plane
-     * @exception IllegalArgumentException if the normal norm is too small
-     */
-    public void reset(final Vector3D p, final Vector3D normal) {
-        setNormal(normal);
-        originOffset = -p.dot(w);
-        setFrame();
+    public static Plane of(final Plane plane) {
+        return new Plane(plane.u, plane.v, plane.w, plane.origin, plane.originOffset, plane.getPrecision());
     }
 
-    /** Reset the instance from another one.
-     * <p>The updated instance is completely independant of the original
-     * one. A deep reset is used none of the underlying object is
-     * shared.</p>
-     * @param original plane to reset from
+    /** 
+     * Constructor, made private to prevent inheritance.
+     * 
+     * Creates a new instance with the given values.
+     * @param u u axis
+     * @param v v axis
+     * @param w w axis
+     * @param origin origin
+     * @param originOffset offset of the origin
+     * @param precision the precision context
      */
-    public void reset(final Plane original) {
-        originOffset = original.originOffset;
-        origin       = original.origin;
-        u            = original.u;
-        v            = original.v;
-        w            = original.w;
+    private Plane(Vector3D u, Vector3D v, Vector3D w, Vector3D origin, double originOffset,
+            DoublePrecisionContext precision) {
+        this.u = u;
+        this.v = v;
+        this.w = w;
+        this.origin = origin;
+        this.originOffset = originOffset;
+        this.precision = precision;
     }
 
-    /** Set the normal vactor.
-     * @param normal normal direction to the plane (will be copied)
-     * @exception IllegalNormException if the normal norm zero, NaN, or infinite
+    /**
+     * Copy the instance.
+     * <p>
+     * The instance created is completely independent of the original one. A deep
+     * copy is used, none of the underlying objects are shared (except for immutable
+     * objects).
+     * </p>
+     * 
+     * @return a new hyperplane, copy of the instance
      */
-    private void setNormal(final Vector3D normal) {
-        final double norm = Vectors.checkedNorm(normal);
-
-        w = Vector3D.linearCombination(1.0 / norm, normal);
+    @Deprecated
+    @Override
+    public Plane copySelf() {
+        return new Plane(this.u, this.v, this.w, this.origin, this.originOffset, this.precision);
     }
 
-    /** Reset the plane frame.
-     */
-    private void setFrame() {
-        origin = Vector3D.linearCombination(-originOffset, w);
-        u = w.orthogonal();
-        v = w.cross(u);
-    }
 
-    /** Get the origin point of the plane frame.
-     * <p>The point returned is the orthogonal projection of the
-     * 3D-space origin in the plane.</p>
-     * @return the origin point of the plane frame (point closest to the
-     * 3D-space origin)
+    /**
+     * Get the origin point of the plane frame.
+     * <p>
+     * The point returned is the orthogonal projection of the 3D-space origin in the
+     * plane.
+     * </p>
+     * 
+     * @return the origin point of the plane frame (point closest to the 3D-space
+     *         origin)
      */
     public Vector3D getOrigin() {
         return origin;
     }
 
-    /** Get the normalized normal vector.
-     * <p>The frame defined by ({@link #getU getU}, {@link #getV getV},
-     * {@link #getNormal getNormal}) is a rigth-handed orthonormalized
-     * frame).</p>
+    /**
+     * Get the normalized normal vector.
+     * <p>
+     * The frame defined by ({@link #getU getU}, {@link #getV getV},
+     * {@link #getNormal getNormal}) is a rigth-handed orthonormalized frame).
+     * </p>
+     * 
      * @return normalized normal vector
      * @see #getU
      * @see #getV
@@ -180,10 +202,13 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return w;
     }
 
-    /** 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).</p>
+    /**
+     * 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).
+     * </p>
+     * 
      * @return normalized first canonical vector
      * @see #getV
      * @see #getNormal
@@ -192,10 +217,13 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return u;
     }
 
-    /** 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).</p>
+    /**
+     * 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).
+     * </p>
+     * 
      * @return normalized second canonical vector
      * @see #getU
      * @see #getNormal
@@ -216,26 +244,31 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return precision;
     }
 
-    /** Revert the plane.
-     * <p>Replace the instance by a similar plane with opposite orientation.</p>
-     * <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 plane and is unaffected by the change will have
-     * {@code (y, x)} in-plane coordinates and {@code -z} offset with
-     * respect to the new plane. This means that the {@code u} and {@code v}
-     * vectors returned by the {@link #getU} and {@link #getV} methods are exchanged,
-     * and the {@code w} vector returned by the {@link #getNormal} method is
-     * reversed.</p>
+    /**
+     * Creates a new reverted 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
+     * plane and is unaffected by the change will have {@code (y, x)} in-plane
+     * coordinates and {@code -z} offset with respect to the new plane. This means
+     * that the {@code u} and {@code v} vectors returned by the {@link #getU} and
+     * {@link #getV} methods are exchanged, and the {@code w} vector returned by the
+     * {@link #getNormal} method is reversed.
+     * </p>
      */
-    public void revertSelf() {
+    public Plane revert() {
         final Vector3D tmp = u;
-        u = v;
-        v = tmp;
-        w = w.negate();
-        originOffset = -originOffset;
+        Vector3D u = v;
+        Vector3D v = tmp;
+        Vector3D w = this.w.negate();
+        double originOffset = -this.originOffset;
+        Vector3D origin = calculateOrigin(w, originOffset);
+        return new Plane(u, v, w, origin, originOffset, this.precision);
     }
 
-    /** Transform a 3D space point into an in-plane point.
+    /**
+     * Transform a 3D space point into an in-plane point.
+     * 
      * @param point point of the space (must be a {@link Vector3D} instance)
      * @return in-plane point
      * @see #toSpace
@@ -246,7 +279,9 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return Vector2D.of(vec.dot(u), vec.dot(v));
     }
 
-    /** Transform an in-plane point into a 3D space point.
+    /**
+     * Transform an in-plane point into a 3D space point.
+     * 
      * @param point in-plane point (must be a {@link Vector2D} instance)
      * @return 3D space point
      * @see #toSubSpace
@@ -256,99 +291,112 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return Vector3D.linearCombination(point.getX(), u, point.getY(), v, -originOffset, w);
     }
 
-    /** Get one point from the 3D-space.
-     * @param inPlane desired in-plane coordinates for the point in the
-     * plane
-     * @param offset desired offset for the point
-     * @return one point in the 3D-space, with given coordinates and offset
-     * relative to the plane
+    /**
+     * Get one point from the 3D-space.
+     * 
+     * @param inPlane desired in-plane coordinates for the point in the plane
+     * @param offset  desired offset for the point
+     * @return one point in the 3D-space, with given coordinates and offset relative
+     *         to the plane
      */
     public Vector3D getPointAt(final Vector2D inPlane, final double offset) {
         return Vector3D.linearCombination(inPlane.getX(), u, inPlane.getY(), v, offset - originOffset, w);
     }
 
-    /** Check if the instance is similar to another plane.
-     * <p>Planes are considered similar if they contain the same
-     * points. This does not mean they are equal since they can have
-     * opposite normals.</p>
+    /**
+     * Check if the instance is similar to another plane.
+     * <p>
+     * Planes are considered similar if they contain the same points. This does not
+     * mean they are equal since they can have opposite normals.
+     * </p>
+     * 
      * @param plane plane to which the instance is compared
      * @return true if the planes are similar
      */
     public boolean isSimilarTo(final Plane plane) {
         final double angle = w.angle(plane.w);
 
-        return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset)) ||
-                ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
+        return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset))
+                || ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
     }
 
-    /** Rotate the plane around the specified point.
-     * <p>The instance is not modified, a new instance is created.</p>
-     * @param center rotation center
+    /**
+     * Rotate the plane around the specified point.
+     * <p>
+     * The instance is not modified, a new instance is created.
+     * </p>
+     * 
+     * @param center   rotation center
      * @param rotation 3-dimensional rotation
      * @return a new plane
      */
     public Plane rotate(final Vector3D center, final QuaternionRotation rotation) {
-
         final Vector3D delta = origin.subtract(center);
-        final Plane plane = new Plane(center.add(rotation.apply(delta)),
-                                      rotation.apply(w), precision);
-
-        // make sure the frame is transformed as desired
-        plane.u = rotation.apply(u);
-        plane.v = rotation.apply(v);
-
-        return plane;
-
+        Vector3D p = center.add(rotation.apply(delta));
+        Vector3D normal = rotation.apply(this.w);
+        Vector3D w = calculateW(normal);
+        double originOffset = -p.dot(w);
+        Vector3D origin = calculateOrigin(w, originOffset);
+        Vector3D u = rotation.apply(this.u);
+        Vector3D v = rotation.apply(this.v);
+        return new Plane(u, v, w, origin, originOffset, this.precision);
     }
 
-    /** Translate the plane by the specified amount.
-     * <p>The instance is not modified, a new instance is created.</p>
+    /**
+     * Translate the plane by the specified amount.
+     * <p>
+     * The instance is not modified, a new instance is created.
+     * </p>
+     * 
      * @param translation translation to apply
      * @return a new plane
      */
     public Plane translate(final Vector3D translation) {
-
-        final Plane plane = new Plane(origin.add(translation), w, precision);
-
-        // make sure the frame is transformed as desired
-        plane.u = u;
-        plane.v = v;
-
-        return plane;
-
+        Vector3D p = origin.add(translation);
+        Vector3D normal = this.w;
+        Vector3D w = calculateW(normal);
+        double originOffset = -p.dot(w);
+        Vector3D origin = calculateOrigin(w, originOffset);
+        return new Plane(this.u, this.v, w, origin, originOffset, this.precision);
     }
 
-    /** Get the intersection of a line with the instance.
+    /**
+     * Get the intersection of a line with the instance.
+     * 
      * @param line line intersecting the instance
-     * @return intersection point between between the line and the
-     * instance (null if the line is parallel to the instance)
+     * @return intersection point between between the line and the instance (null if
+     *         the line is parallel to the instance)
      */
     public Vector3D intersection(final Line line) {
         final Vector3D direction = line.getDirection();
-        final double   dot       = w.dot(direction);
+        final double dot = w.dot(direction);
         if (precision.eqZero(dot)) {
             return null;
         }
         final Vector3D point = line.toSpace(Vector1D.ZERO);
-        final double   k     = -(originOffset + w.dot(point)) / dot;
+        final double k = -(originOffset + w.dot(point)) / dot;
         return Vector3D.linearCombination(1.0, point, k, direction);
     }
 
-    /** Build the line shared by the instance and another plane.
+    /**
+     * Build the line shared by the instance and another plane.
+     * 
      * @param other other plane
-     * @return line at the intersection of the instance and the
-     * other plane (really a {@link Line Line} instance)
+     * @return line at the intersection of the instance and the other plane (really
+     *         a {@link Line Line} instance)
      */
     public Line intersection(final Plane other) {
         final Vector3D direction = w.cross(other.w);
         if (precision.eqZero(direction.norm())) {
             return null;
         }
-        final Vector3D point = intersection(this, other, new Plane(direction, precision));
+        final Vector3D point = intersection(this, other, Plane.fromNormal(direction, precision));
         return new Line(point, point.add(direction), precision);
     }
 
-    /** Get the intersection point of three planes.
+    /**
+     * Get the intersection point of three planes.
+     * 
      * @param plane1 first plane1
      * @param plane2 second plane2
      * @param plane3 third plane2
@@ -374,23 +422,24 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
 
         // direct Cramer resolution of the linear system
         // (this is still feasible for a 3x3 system)
-        final double a23         = b2 * c3 - b3 * c2;
-        final double b23         = c2 * a3 - c3 * a2;
-        final double c23         = a2 * b3 - a3 * b2;
+        final double a23 = b2 * c3 - b3 * c2;
+        final double b23 = c2 * a3 - c3 * a2;
+        final double c23 = a2 * b3 - a3 * b2;
         final double determinant = a1 * a23 + b1 * b23 + c1 * c23;
         if (Math.abs(determinant) < 1.0e-10) {
             return null;
         }
 
         final double r = 1.0 / determinant;
-        return Vector3D.of(
-                            (-a23 * d1 - (c1 * b3 - c3 * b1) * d2 - (c2 * b1 - c1 * b2) * d3) * r,
-                            (-b23 * d1 - (c3 * a1 - c1 * a3) * d2 - (c1 * a2 - c2 * a1) * d3) * r,
-                            (-c23 * d1 - (b1 * a3 - b3 * a1) * d2 - (b2 * a1 - b1 * a2) * d3) * r);
+        return Vector3D.of((-a23 * d1 - (c1 * b3 - c3 * b1) * d2 - (c2 * b1 - c1 * b2) * d3) * r,
+                (-b23 * d1 - (c3 * a1 - c1 * a3) * d2 - (c1 * a2 - c2 * a1) * d3) * r,
+                (-c23 * d1 - (b1 * a3 - b3 * a1) * d2 - (b2 * a1 - b1 * a2) * d3) * r);
 
     }
 
-    /** Build a region covering the whole hyperplane.
+    /**
+     * Build a region covering the whole hyperplane.
+     * 
      * @return a region covering the whole hyperplane
      */
     @Override
@@ -398,16 +447,20 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return new SubPlane(this, new PolygonsSet(precision));
     }
 
-    /** Build a region covering the whole space.
-     * @return a region containing the instance (really a {@link
-     * PolyhedronsSet PolyhedronsSet} instance)
+    /**
+     * Build a region covering the whole space.
+     * 
+     * @return a region containing the instance (really a {@link PolyhedronsSet
+     *         PolyhedronsSet} instance)
      */
     @Override
     public PolyhedronsSet wholeSpace() {
         return new PolyhedronsSet(precision);
     }
 
-    /** Check if the instance contains a point.
+    /**
+     * Check if the instance contains a point.
+     * 
      * @param p point to check
      * @return true if p belongs to the plane
      */
@@ -415,13 +468,18 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return precision.eqZero(getOffset(p));
     }
 
-    /** Get the offset (oriented distance) of a parallel plane.
-     * <p>This method should be called only for parallel planes otherwise
-     * the result is not meaningful.</p>
-     * <p>The offset is 0 if both planes are the same, it is
-     * positive if the plane is on the plus side of the instance and
-     * negative if it is on the minus side, according to its natural
-     * orientation.</p>
+    /**
+     * Get the offset (oriented distance) of a parallel plane.
+     * <p>
+     * This method should be called only for parallel planes otherwise the result is
+     * not meaningful.
+     * </p>
+     * <p>
+     * The offset is 0 if both planes are the same, it is positive if the plane is
+     * on the plus side of the instance and negative if it is on the minus side,
+     * according to its natural orientation.
+     * </p>
+     * 
      * @param plane plane to check
      * @return offset of the plane
      */
@@ -429,11 +487,15 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return originOffset + (sameOrientationAs(plane) ? -plane.originOffset : plane.originOffset);
     }
 
-    /** Get the offset (oriented distance) of a point.
-     * <p>The offset is 0 if the point is on the underlying hyperplane,
-     * it is positive if the point is on one particular side of the
-     * hyperplane, and it is negative if the point is on the other side,
-     * according to the hyperplane natural orientation.</p>
+    /**
+     * Get the offset (oriented distance) of a point.
+     * <p>
+     * The offset is 0 if the point is on the underlying hyperplane, it is positive
+     * if the point is on one particular side of the hyperplane, and it is negative
+     * if the point is on the other side, according to the hyperplane natural
+     * orientation.
+     * </p>
+     * 
      * @param point point to check
      * @return offset of the point
      */
@@ -442,14 +504,43 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D
         return point.dot(w) + originOffset;
     }
 
-    /** Check if the instance has the same orientation as another hyperplane.
+    /**
+     * Check if the instance has the same orientation as another hyperplane.
+     * 
      * @param other other hyperplane to check against the instance
-     * @return true if the instance and the other hyperplane have
-     * the same orientation
+     * @return true if the instance and the other hyperplane have the same
+     *         orientation
      */
     @Override
     public boolean sameOrientationAs(final Hyperplane<Vector3D> other) {
         return (((Plane) other).w).dot(w) > 0.0;
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "Plane [originOffset=" + originOffset + ", origin=" + origin + ", u=" + u + ", v=" + v + ", w=" + w
+                + ", precision=" + precision + "]";
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(origin, originOffset, u, v, w);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Plane other = (Plane) obj;
+        return Objects.equals(origin, other.origin)
+                && Double.doubleToLongBits(originOffset) == Double.doubleToLongBits(other.originOffset)
+                && Objects.equals(u, other.u) && Objects.equals(v, other.v) && Objects.equals(w, other.w);
+    }
 }
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 d522f7c..66e35b1 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
@@ -155,12 +155,12 @@ public class PolyhedronsSet extends AbstractRegion<Vector3D, Vector2D> {
             // too thin box, build an empty polygons set
             return new BSPTree<>(Boolean.FALSE);
         }
-        final Plane pxMin = new Plane(Vector3D.of(xMin, 0,    0),   Vector3D.MINUS_X, precision);
-        final Plane pxMax = new Plane(Vector3D.of(xMax, 0,    0),   Vector3D.PLUS_X,  precision);
-        final Plane pyMin = new Plane(Vector3D.of(0,    yMin, 0),   Vector3D.MINUS_Y, precision);
-        final Plane pyMax = new Plane(Vector3D.of(0,    yMax, 0),   Vector3D.PLUS_Y,  precision);
-        final Plane pzMin = new Plane(Vector3D.of(0,    0,   zMin), Vector3D.MINUS_Z, precision);
-        final Plane pzMax = new Plane(Vector3D.of(0,    0,   zMax), Vector3D.PLUS_Z,  precision);
+        final Plane pxMin = Plane.fromPointAndNormal(Vector3D.of(xMin, 0,    0),   Vector3D.MINUS_X, precision);
+        final Plane pxMax = Plane.fromPointAndNormal(Vector3D.of(xMax, 0,    0),   Vector3D.PLUS_X,  precision);
+        final Plane pyMin = Plane.fromPointAndNormal(Vector3D.of(0,    yMin, 0),   Vector3D.MINUS_Y, precision);
+        final Plane pyMax = Plane.fromPointAndNormal(Vector3D.of(0,    yMax, 0),   Vector3D.PLUS_Y,  precision);
+        final Plane pzMin = Plane.fromPointAndNormal(Vector3D.of(0,    0,   zMin), Vector3D.MINUS_Z, precision);
+        final Plane pzMax = Plane.fromPointAndNormal(Vector3D.of(0,    0,   zMax), Vector3D.PLUS_Z,  precision);
         final Region<Vector3D> boundary =
         new RegionFactory<Vector3D>().buildConvex(pxMin, pxMax, pyMin, pyMax, pzMin, pzMax);
         return boundary.getTree(false);
@@ -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 = new Plane(vertices.get(facet[0]), vertices.get(facet[1]), vertices.get(facet[2]),
+            Plane plane = Plane.fromThreePoints(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/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
index 232675c..b503b7c 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
@@ -528,7 +528,7 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> {
      * @return vector with coordinates calculated by {@code a * c}
      */
     public static Vector3D linearCombination(double a, Vector3D c) {
-        return new Vector3D(a * c.x, a * c.y, a * c.z);
+        return c.multiply(a);
     }
 
     /** Returns a vector consisting of the linear combination of the inputs.
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/EuclideanTestUtils.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/EuclideanTestUtils.java
index 7d6bf18..5b7b0db 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/EuclideanTestUtils.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/EuclideanTestUtils.java
@@ -340,7 +340,7 @@ public class EuclideanTestUtils {
             @Override
             public Plane parseHyperplane()
                 throws ParseException {
-                return new Plane(Vector3D.of(getNumber(), getNumber(), getNumber()),
+                return Plane.fromPointAndNormal(Vector3D.of(getNumber(), getNumber(), getNumber()),
                                  Vector3D.of(getNumber(), getNumber(), getNumber()),
                                  getPrecision());
             }
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 f76471a..8480646 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
@@ -31,29 +31,29 @@ public class PlaneTest {
 
     @Test
     public void testContains() {
-        Plane p = new Plane(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+        Plane p = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
         Assert.assertTrue(p.contains(Vector3D.of(0, 0, 1)));
         Assert.assertTrue(p.contains(Vector3D.of(17, -32, 1)));
         Assert.assertTrue(! p.contains(Vector3D.of(17, -32, 1.001)));
     }
 
     @Test
-    public void testOffset() {
-        Vector3D p1 = Vector3D.of(1, 1, 1);
-        Plane p = new Plane(p1, Vector3D.of(0.2, 0, 0), TEST_PRECISION);
-        Assert.assertEquals(-5.0, p.getOffset(Vector3D.of(-4, 0, 0)), TEST_EPS);
-        Assert.assertEquals(+5.0, p.getOffset(Vector3D.of(6, 10, -12)), TEST_EPS);
-        Assert.assertEquals(0.3,
-                            p.getOffset(Vector3D.linearCombination(1.0, p1, 0.3, p.getNormal())),
-                            TEST_EPS);
-        Assert.assertEquals(-0.3,
-                            p.getOffset(Vector3D.linearCombination(1.0, p1, -0.3, p.getNormal())),
-                            TEST_EPS);
-    }
+                public void testFromNormalfset() {
+                    Vector3D p1 = Vector3D.of(1, 1, 1);
+                    Plane p = Plane.fromPointAndNormal(p1, Vector3D.of(0.2, 0, 0), TEST_PRECISION);
+                    Assert.assertEquals(-5.0, p.getOffset(Vector3D.of(-4, 0, 0)), TEST_EPS);
+                    Assert.assertEquals(+5.0, p.getOffset(Vector3D.of(6, 10, -12)), TEST_EPS);
+                    Assert.assertEquals(0.3,
+                                        p.getOffset(Vector3D.linearCombination(1.0, p1, 0.3, p.getNormal())),
+                                        TEST_EPS);
+                    Assert.assertEquals(-0.3,
+                                        p.getOffset(Vector3D.linearCombination(1.0, p1, -0.3, p.getNormal())),
+                                        TEST_EPS);
+                }
 
     @Test
     public void testPoint() {
-        Plane p = new Plane(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
+        Plane p = Plane.fromPointAndNormal(Vector3D.of(2, -3, 1), Vector3D.of(1, 4, 9), TEST_PRECISION);
         Assert.assertTrue(p.contains(p.getOrigin()));
     }
 
@@ -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  = new Plane(p1, p2, p3, TEST_PRECISION);
+        Plane    p  = Plane.fromThreePoints(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  = new Plane(p1, p2, p3, TEST_PRECISION);
+        Plane    p  = Plane.fromThreePoints(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  = new Plane(p1, p2, p3, TEST_PRECISION);
+        Plane    p  = Plane.fromThreePoints(p1, p2, p3, TEST_PRECISION);
 
         p = p.translate(Vector3D.linearCombination(2.0, p.getU(), -1.5, p.getV()));
         Assert.assertTrue(p.contains(p1));
@@ -119,7 +119,7 @@ public class PlaneTest {
 
     @Test
     public void testIntersection() {
-        Plane p = new Plane(Vector3D.of(1, 2, 3), Vector3D.of(-4, 1, -5), TEST_PRECISION);
+        Plane p = Plane.fromPointAndNormal(Vector3D.of(1, 2, 3), Vector3D.of(-4, 1, -5), TEST_PRECISION);
         Line  l = new Line(Vector3D.of(0.2, -3.5, 0.7), Vector3D.of(1.2, -2.5, -0.3), TEST_PRECISION);
         Vector3D point = p.intersection(l);
         Assert.assertTrue(p.contains(point));
@@ -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  = new Plane(p1, p2, Vector3D.of(-2.0, 4.3, 0.7), TEST_PRECISION);
-        Plane    pB  = new Plane(p1, Vector3D.of(11.4, -3.8, 5.1), p2, TEST_PRECISION);
+        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);
         Line     l   = pA.intersection(pB);
         Assert.assertTrue(l.contains(p1));
         Assert.assertTrue(l.contains(p2));
@@ -144,9 +144,9 @@ public class PlaneTest {
     @Test
     public void testIntersection3() {
         Vector3D reference = Vector3D.of(1.2, 3.4, -5.8);
-        Plane p1 = new Plane(reference, Vector3D.of(1, 3, 3), TEST_PRECISION);
-        Plane p2 = new Plane(reference, Vector3D.of(-2, 4, 0), TEST_PRECISION);
-        Plane p3 = new Plane(reference, Vector3D.of(7, 0, -4), TEST_PRECISION);
+        Plane p1 = Plane.fromPointAndNormal(reference, Vector3D.of(1, 3, 3), TEST_PRECISION);
+        Plane p2 = Plane.fromPointAndNormal(reference, Vector3D.of(-2, 4, 0), TEST_PRECISION);
+        Plane p3 = Plane.fromPointAndNormal(reference, Vector3D.of(7, 0, -4), TEST_PRECISION);
         Vector3D p = Plane.intersection(p1, p2, p3);
         Assert.assertEquals(reference.getX(), p.getX(), TEST_EPS);
         Assert.assertEquals(reference.getY(), p.getY(), TEST_EPS);
@@ -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  = new Plane(p1, p2, p3, TEST_PRECISION);
-        Plane    pB  = new Plane(p1, Vector3D.of(11.4, -3.8, 5.1), p2, TEST_PRECISION);
+        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);
         Assert.assertTrue(! pA.isSimilarTo(pB));
         Assert.assertTrue(pA.isSimilarTo(pA));
-        Assert.assertTrue(pA.isSimilarTo(new Plane(p1, p3, p2, TEST_PRECISION)));
+        Assert.assertTrue(pA.isSimilarTo(Plane.fromThreePoints(p1, p3, p2, TEST_PRECISION)));
         Vector3D shift = Vector3D.linearCombination(0.3, pA.getNormal());
-        Assert.assertTrue(! pA.isSimilarTo(new Plane(p1.add(shift),
+        Assert.assertTrue(! pA.isSimilarTo(Plane.fromThreePoints(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 a635e46..52c8ff9 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
@@ -96,7 +96,7 @@ public class PolyhedronsSetTest {
     public void testHalfSpace() {
         // arrange
         List<SubHyperplane<Vector3D>> boundaries = new ArrayList<>();
-        boundaries.add(new SubPlane(new Plane(Vector3D.ZERO, Vector3D.PLUS_Y, TEST_PRECISION),
+        boundaries.add(new SubPlane(Plane.fromPointAndNormal(Vector3D.ZERO, Vector3D.PLUS_Y, TEST_PRECISION),
                 new PolygonsSet(TEST_PRECISION)));
 
         // act
@@ -465,10 +465,10 @@ public class PolyhedronsSetTest {
         // act
         PolyhedronsSet tree =
             (PolyhedronsSet) new RegionFactory<Vector3D>().buildConvex(
-                new Plane(vertex3, vertex2, vertex1, TEST_PRECISION),
-                new Plane(vertex2, vertex3, vertex4, TEST_PRECISION),
-                new Plane(vertex4, vertex3, vertex1, TEST_PRECISION),
-                new Plane(vertex1, vertex2, vertex4, TEST_PRECISION));
+                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));
 
         // 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(
-                new Plane(vertex3, vertex2, vertex1, TEST_PRECISION),
-                new Plane(vertex2, vertex3, vertex4, TEST_PRECISION),
-                new Plane(vertex4, vertex3, vertex1, TEST_PRECISION),
-                new Plane(vertex1, vertex2, vertex4, TEST_PRECISION));
+                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));
 
         // 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 = new Plane(v_1, v_2, v_3, TEST_PRECISION);
+            Plane polyPlane = Plane.fromThreePoints(v_1, v_2, v_3, TEST_PRECISION);
             ArrayList<SubHyperplane<Vector2D>> lines = new ArrayList<>();
 
             Vector2D[] projPts = new Vector2D[vertices.length];
@@ -1476,12 +1476,12 @@ public class PolyhedronsSetTest {
         double offset = size * 0.5;
         DoublePrecisionContext precision = new EpsilonDoublePrecisionContext(eps);
 
-        Plane xMinus = new Plane(center.add(Vector3D.of(-offset, 0, 0)), Vector3D.MINUS_X, precision);
-        Plane xPlus = new Plane(center.add(Vector3D.of(offset, 0, 0)), Vector3D.PLUS_X, precision);
-        Plane yPlus = new Plane(center.add(Vector3D.of(0, offset, 0)), Vector3D.PLUS_Y, precision);
-        Plane yMinus = new Plane(center.add(Vector3D.of(0, -offset, 0)), Vector3D.MINUS_Y, precision);
-        Plane zPlus = new Plane(center.add(Vector3D.of(0, 0, offset)), Vector3D.PLUS_Z, precision);
-        Plane zMinus = new Plane(center.add(Vector3D.of(0, 0, -offset)), Vector3D.MINUS_Z, precision);
+        Plane xMinus = Plane.fromPointAndNormal(center.add(Vector3D.of(-offset, 0, 0)), Vector3D.MINUS_X, precision);
+        Plane xPlus = Plane.fromPointAndNormal(center.add(Vector3D.of(offset, 0, 0)), Vector3D.PLUS_X, precision);
+        Plane yPlus = Plane.fromPointAndNormal(center.add(Vector3D.of(0, offset, 0)), Vector3D.PLUS_Y, precision);
+        Plane yMinus = Plane.fromPointAndNormal(center.add(Vector3D.of(0, -offset, 0)), Vector3D.MINUS_Y, precision);
+        Plane zPlus = Plane.fromPointAndNormal(center.add(Vector3D.of(0, 0, offset)), Vector3D.PLUS_Z, precision);
+        Plane zMinus = Plane.fromPointAndNormal(center.add(Vector3D.of(0, 0, -offset)), Vector3D.MINUS_Z, precision);
 
         // +x
         boundaries.add(createSubPlane(xPlus,
@@ -1546,8 +1546,8 @@ public class PolyhedronsSetTest {
         Vector3D topZ = Vector3D.of(center.getX(), center.getY(), center.getZ() + radius);
         Vector3D bottomZ = Vector3D.of(center.getX(), center.getY(), center.getZ() - radius);
 
-        planes.add(new Plane(topZ, Vector3D.PLUS_Z, TEST_PRECISION));
-        planes.add(new Plane(bottomZ, Vector3D.MINUS_Z, TEST_PRECISION));
+        planes.add(Plane.fromPointAndNormal(topZ, Vector3D.PLUS_Z, TEST_PRECISION));
+        planes.add(Plane.fromPointAndNormal(bottomZ, Vector3D.MINUS_Z, TEST_PRECISION));
 
         // add the side planes
         double vDelta = Math.PI / stacks;
@@ -1580,7 +1580,7 @@ public class PolyhedronsSetTest {
                 norm = Vector3D.of(x, y, stackHeight).normalize();
                 pt = center.add(norm.multiply(adjustedRadius));
 
-                planes.add(new Plane(pt, norm, TEST_PRECISION));
+                planes.add(Plane.fromPointAndNormal(pt, norm, TEST_PRECISION));
             }
         }
 


[commons-geometry] 03/16: GEOMETRY-29 corrects comment for copy factory method, corrects typo. Removes factory method with all arguments supplied.

Posted by er...@apache.org.
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 b17f640f95daf4ca19f39df5af7987bdf3ab574c
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Mon Mar 18 07:40:11 2019 +0100

    GEOMETRY-29 corrects comment for copy factory method, corrects typo. Removes factory method with all arguments supplied.
---
 .../apache/commons/geometry/euclidean/threed/Plane.java    | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

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 f581dc1..aea5b16 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
@@ -90,16 +90,6 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         return new Plane(u, v, w, origin, originOffset, precision);
     }
 
-    // TODO check this one
-    public static Plane of(Vector3D u, Vector3D v, Vector3D w, Vector3D origin, double originOffset,
-            DoublePrecisionContext precision) {
-        if (!w.orthogonal().equals(u, precision))
-        {
-            throw new IllegalArgumentException("w must be orthogonal to u.");
-        }
-        return new Plane(u, v, w, origin, originOffset, precision);
-    }
-
     /**
      * Build a plane from three points.
      * <p>
@@ -118,7 +108,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     }
 
     /**
-     * Copy constructor.
+     * Copy plane.
      * <p>
      * The instance created is completely independent of the original one. A deep
      * copy is used, none of the underlying object are shared.
@@ -186,7 +176,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * Get the normalized normal 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 normal vector


[commons-geometry] 11/16: GEOMETRY-29 working on Matts review. Part III

Posted by er...@apache.org.
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 c949642d949bd768fc5faa090170fec13090d7ad
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Wed Apr 3 21:44:39 2019 +0200

    GEOMETRY-29 working on Matts review. Part III
---
 .../main/java/org/apache/commons/geometry/euclidean/threed/Plane.java  | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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 4e39954..1e71e22 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
@@ -140,11 +140,10 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      */
     public static Plane fromPoints(final Vector3D p1, final Vector3D p2, final Vector3D p3,
             final DoublePrecisionContext precision) {
-        return Plane.fromPointAndNormal(p1, p1.vectorTo(p2).cross(p1.vectorTo(p3)), precision);
+        return Plane.fromPointAndPlaneVectors(p1, p1.vectorTo(p2), p1.vectorTo(p3), precision);
     }
    
     // This should be removed after GEOMETRY-32 is done.
-    
     /**
      * Copy the instance.
      * <p>


[commons-geometry] 06/16: GEOMETRY-29 improves javadoc. Adds tests.

Posted by er...@apache.org.
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 8a10b16dd01c69cc1dd5d31dd09bfd93b1ac40b5
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Sun Mar 24 06:24:09 2019 +0100

    GEOMETRY-29 improves javadoc. Adds tests.
---
 .../commons/geometry/euclidean/threed/Plane.java   | 54 +++++++++++++---------
 .../geometry/euclidean/threed/Vector3D.java        |  2 +-
 .../geometry/euclidean/threed/PlaneTest.java       | 21 +++++++++
 3 files changed, 53 insertions(+), 24 deletions(-)

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 45ff084..150e7dc 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
@@ -32,49 +32,53 @@ import org.apache.commons.geometry.euclidean.twod.Vector2D;
  */
 public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D> {
 
-    /** Offset of the origin with respect to the plane. */
-    private final double originOffset;
-
-    /** orthogonal projection of the 3D-space origin in the plane. */
-    private final Vector3D projectedOrigin;
-
-    /** First vector of the plane frame (in plane). */
+    /** First normalized vector of the plane frame (in plane). */
     private final Vector3D u;
 
-    /** Second vector of the plane frame (in plane). */
+    /** Second normalized vector of the plane frame (in plane). */
     private final Vector3D v;
 
-    /** Third vector of the plane frame (normalized plane normal). */
+    /** Normalized plane normal. */
     private final Vector3D w;
 
+    /** Offset of the origin with respect to the plane. */
+    private final double originOffset;
+
+    /** orthogonal projection of the 3D-space origin in the plane. */
+    private final Vector3D projectedOrigin;
+    
     /** Precision context used to compare floating point numbers. */
     private final DoublePrecisionContext precision;
 
     /** 
-     * Constructor, made private to prevent inheritance.
-     * 
-     * Builds a new plane with the given values.
+     * Constructor to build a new plane with the given values.
+     * Made private to prevent inheritance.
      * @param u u vector (on plane)
      * @param v v vector (on plane)
      * @param w unit normal vector
      * @param projectedOrigin orthogonal projection of the 3D-space origin in the plane.
      * @param precision precision context used to compare floating point values
-     * @param precision the precision context
-     * @throws IllegalArgumentException if the provided vectors are coplanar
+     * @throws IllegalArgumentException if the provided vectors are coplanar or not normalized
      */
     private Plane(Vector3D u, Vector3D v, Vector3D w, Vector3D projectedOrigin, double originOffset,
             DoublePrecisionContext precision) {
         this.u = u;
         this.v = v;
         this.w = w;
+        
+        if (!areVectorsNormalized(u, v, w, precision))
+        {
+            throw new IllegalArgumentException("Provided vectors must be normalized.");
+        }
         if (Vector3D.areCoplanar(u, v, w, precision))
         {
-            throw new IllegalArgumentException("Provided vectors must not be a coplanar.");
+            throw new IllegalArgumentException("Provided vectors must not be coplanar.");
         }
         this.projectedOrigin = projectedOrigin;
         this.originOffset = originOffset;
         this.precision = precision;
     }
+
     
     /**
      * Build a plane from a point and two (on plane) vectors.
@@ -84,6 +88,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param precision precision context used to compare floating point values
      * @return a new plane
      * @throws IllegalNormException if the norm of the given values is zero, NaN, or infinite.
+     * @throws IllegalArgumentException if the provided vectors are collinear 
      */
     public static Plane fromPointAndPlaneVectors (Vector3D p, final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
     {
@@ -101,10 +106,9 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param normal    normal direction to the plane
      * @param precision precision context used to compare floating point values
      * @return a new plane
-     * @exception IllegalArgumentException if the normal norm is too small
+     * @throws IllegalNormException if the norm of the given values is zero, NaN, or infinite.
      */
-    public static Plane fromNormal(final Vector3D normal, final DoublePrecisionContext precision)
-            throws IllegalArgumentException {
+    public static Plane fromNormal(final Vector3D normal, final DoublePrecisionContext precision){
         return fromPointAndNormal(Vector3D.ZERO, normal, precision);
     }
 
@@ -115,10 +119,9 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param normal    normal direction to the plane
      * @param precision precision context used to compare floating point values
      * @return a new plane
-     * @exception IllegalArgumentException if the normal norm is too small
+     * @throws IllegalNormException if the norm of the given values is zero, NaN, or infinite.
      */
-    public static Plane fromPointAndNormal(final Vector3D p, final Vector3D normal, final DoublePrecisionContext precision)
-            throws IllegalArgumentException {
+    public static Plane fromPointAndNormal(final Vector3D p, final Vector3D normal, final DoublePrecisionContext precision) {
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
         Vector3D projectedOrigin = calculateOrigin(w, originOffset);
@@ -138,10 +141,10 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param p3        third point belonging to the plane
      * @param precision precision context used to compare floating point values
      * @return a new plane
-     * @exception IllegalArgumentException if the points do not constitute a plane
+     * @throws IllegalNormException if the points do not constitute a plane
      */
     public static Plane fromPoints(final Vector3D p1, final Vector3D p2, final Vector3D p3,
-            final DoublePrecisionContext precision) throws IllegalArgumentException {
+            final DoublePrecisionContext precision) {
         return Plane.fromPointAndNormal(p1, p2.subtract(p1).cross(p3.subtract(p1)), precision);
     }
 
@@ -642,4 +645,9 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     private static Vector3D calculateOrigin(Vector3D w, double originOffset) {
         return w.multiply(-originOffset);
     }
+    
+    private boolean areVectorsNormalized(Vector3D u, Vector3D v, Vector3D w, DoublePrecisionContext precision) {
+        return precision.eq(u.normSq(), 1) && precision.eq(v.normSq(), 1) && precision.eq(w.normSq(), 1);
+    }
+
 }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
index afd1e7f..c92c1ac 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
@@ -377,7 +377,7 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> {
      * @param v second vector
      * @param w third vector
      * @param precision precision context used to compare floating point values
-     * @return true if vectors a coplanar, false otherwise.
+     * @return true if vectors are coplanar, false otherwise.
      */
     public static boolean areCoplanar(Vector3D u, Vector3D v, Vector3D w, DoublePrecisionContext precision)
     {
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 bb5f9dc..ac0efae 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
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.geometry.euclidean.threed;
 
+import org.apache.commons.geometry.core.exception.IllegalNormException;
 import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
 import org.apache.commons.geometry.core.precision.EpsilonDoublePrecisionContext;
 import org.apache.commons.geometry.euclidean.threed.rotation.QuaternionRotation;
@@ -30,6 +31,26 @@ public class PlaneTest {
     private static final DoublePrecisionContext TEST_PRECISION =
             new EpsilonDoublePrecisionContext(TEST_EPS);
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testUAndVAreIdentical() {
+        Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testUAndVAreCollinear() {
+        Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 2), TEST_PRECISION);
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void testUAndVAreCollinear2() {
+        Plane.fromPointAndPlaneVectors(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 0, -2), TEST_PRECISION);
+    }
+
+    @Test(expected=IllegalNormException.class)
+    public void testPointsDoNotConstituteAPlane() {
+        Plane.fromPoints(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), Vector3D.of(0, 1, 0), TEST_PRECISION);
+    }
+    
     @Test
     public void testContains() {
         Plane p = Plane.fromPointAndNormal(Vector3D.of(0, 0, 1), Vector3D.of(0, 0, 1), TEST_PRECISION);


[commons-geometry] 14/16: GEOMETRY-29 fixes errors in Plane and Line reported by checkstyle.

Posted by er...@apache.org.
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 4c84beac35f1c00ea70e9b7ee87733b6c7be26b8
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Mon May 20 10:07:58 2019 +0200

    GEOMETRY-29 fixes errors in Plane and Line reported by checkstyle.
---
 .../commons/geometry/euclidean/threed/Line.java    |  11 +-
 .../commons/geometry/euclidean/threed/Plane.java   | 136 +++++++++++----------
 2 files changed, 76 insertions(+), 71 deletions(-)

diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
index af1740b..4835682 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
@@ -238,7 +238,7 @@ public class Line implements Embedding<Vector3D, Vector1D> {
     public SubLine wholeLine() {
         return new SubLine(this, new IntervalsSet(precision));
     }
-    
+
     /** {@inheritDoc} */
     @Override
     public int hashCode() {
@@ -248,12 +248,15 @@ public class Line implements Embedding<Vector3D, Vector1D> {
     /** {@inheritDoc} */
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj){
             return true;
-        if (obj == null)
+        }
+        if (obj == null){
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()){
             return false;
+        }
         Line other = (Line) obj;
         return this.direction.equals(other.direction, precision) && this.zero.equals(other.zero, precision);
     }
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 c513fc3..8c1ce6b 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
@@ -47,13 +47,13 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     /** Precision context used to compare floating point numbers. */
     private final DoublePrecisionContext precision;
 
-    /** 
+    /**
      * Constructor to build a new plane with the given values.
      * Made private to prevent inheritance.
      * @param u u vector (on plane)
      * @param v v vector (on plane)
      * @param w unit normal vector
-     * @param origin orthogonal projection of the 3D-space origin in the plane.
+     * @param originOffset offset of the origin with respect to the plane.
      * @param precision precision context used to compare floating point values
      * @throws IllegalArgumentException if the provided vectors are coplanar or not normalized
      */
@@ -62,7 +62,6 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         this.u = u;
         this.v = v;
         this.w = w;
-      
         if (areCoplanar(u, v, w, precision))
         {
             throw new IllegalArgumentException("Provided vectors must not be coplanar.");
@@ -70,7 +69,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         this.originOffset = originOffset;
         this.precision = precision;
     }
-    
+
     /**
      * Build a plane from a point and two (on plane) vectors.
      * @param p the provided point (on plane)
@@ -79,7 +78,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param precision precision context used to compare floating point values
      * @return a new plane
      * @throws IllegalNormException if the norm of the given values is zero, NaN, or infinite.
-     * @throws IllegalArgumentException if the provided vectors are collinear 
+     * @throws IllegalArgumentException if the provided vectors are collinear
      */
     public static Plane fromPointAndPlaneVectors (final Vector3D p, final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
     {
@@ -89,10 +88,10 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         double originOffset = -p.dot(wNorm);
         return new Plane(uNorm, vNorm, wNorm, originOffset, precision);
     }
-    
+
     /**
      * Build a plane from a normal.
-     * Chooses origin as point on plane. 
+     * Chooses origin as point on plane.
      * @param normal    normal direction to the plane
      * @param precision precision context used to compare floating point values
      * @return a new plane
@@ -104,7 +103,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Build a plane from a point and a normal.
-     * 
+     *
      * @param p         point belonging to the plane
      * @param normal    normal direction to the plane
      * @param precision precision context used to compare floating point values
@@ -118,13 +117,13 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         Vector3D v = w.cross(u);
         return new Plane(u, v, w, originOffset, precision);
     }
-    
+
     /**
      * Build a plane from three points.
      * <p>
      * The plane is oriented in the direction of {@code (p2-p1) ^ (p3-p1)}
      * </p>
-     * 
+     *
      * @param p1        first point belonging to the plane
      * @param p2        second point belonging to the plane
      * @param p3        third point belonging to the plane
@@ -136,7 +135,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
             final DoublePrecisionContext precision) {
         return Plane.fromPointAndPlaneVectors(p1, p1.vectorTo(p2), p1.vectorTo(p3), precision);
     }
-   
+
     // This should be removed after GEOMETRY-32 is done.
     /**
      * Copy the instance.
@@ -145,7 +144,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * copy is used, none of the underlying objects are shared (except for immutable
      * objects).
      * </p>
-     * 
+     *
      * @return a new hyperplane, copy of the instance
      */
     @Deprecated
@@ -155,31 +154,31 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     }
 
     /**
-     * Get the orthogonal projection of the 3D-space origin in the plane.      
+     * Get the orthogonal projection of the 3D-space origin in the plane.
      * @return the origin point of the plane frame (point closest to the 3D-space
      *         origin)
      */
     public Vector3D getOrigin() {
         return w.multiply(-originOffset);
     }
-    
+
     /**
-     *  Get the offset of the origin with respect to the plane. 
-     *  
-     *  @return the offset of the origin with respect to the plane. 
+     *  Get 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 plane first canonical vector.
      * <p>
      * The frame defined by ({@link #getU getU}, {@link #getV getV},
      * {@link #getNormal getNormal}) is a right-handed orthonormalized frame).
      * </p>
-     * 
+     *
      * @return normalized first canonical vector
      * @see #getV
      * @see #getNormal
@@ -194,7 +193,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * The frame defined by ({@link #getU getU}, {@link #getV getV},
      * {@link #getNormal getNormal}) is a right-handed orthonormalized frame).
      * </p>
-     * 
+     *
      * @return normalized second canonical vector
      * @see #getU
      * @see #getNormal
@@ -202,14 +201,14 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public Vector3D getV() {
         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
@@ -217,14 +216,14 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public Vector3D getW() {
         return w;
     }
-    
+
     /**
      * Get the normalized normal vector.
      * <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
@@ -232,7 +231,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public Vector3D getNormal() {
         return w;
     }
-    
+
     /** {@inheritDoc} */
     @Override
     public Vector3D project(final Vector3D point) {
@@ -275,16 +274,16 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      */
     public Plane reverse() {
         final Vector3D tmp = u;
-        Vector3D u = v;
-        Vector3D v = tmp;
-        Vector3D w = this.w.negate();
-        double originOffset = -this.originOffset;
-        return new Plane(u, v, w, originOffset, this.precision);
+        Vector3D uTmp = v;
+        Vector3D vTmp = tmp;
+        Vector3D wTmp = this.w.negate();
+        double originOffsetTmp = -this.originOffset;
+        return new Plane(uTmp, vTmp, wTmp, originOffsetTmp, this.precision);
     }
 
     /**
      * Transform a 3D space point into an in-plane point.
-     * 
+     *
      * @param point point of the space (must be a {@link Vector3D} instance)
      * @return in-plane point
      * @see #toSpace
@@ -297,7 +296,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Transform an in-plane point into a 3D space point.
-     * 
+     *
      * @param point in-plane point (must be a {@link Vector2D} instance)
      * @return 3D space point
      * @see #toSubSpace
@@ -309,7 +308,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Get one point from the 3D-space.
-     * 
+     *
      * @param inPlane desired in-plane coordinates for the point in the plane
      * @param offset  desired offset for the point
      * @return one point in the 3D-space, with given coordinates and offset relative
@@ -325,24 +324,24 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * Planes are considered similar if they contain the same points. This does not
      * mean they are equal since they can have opposite normals.
      * </p>
-     * 
+     *
      * @param plane plane to which the instance is compared
      * @return true if the planes are similar
      */
     public boolean contains(final Plane plane) {
         final double angle = w.angle(plane.w);
-        return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset))
-                || ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
+        return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset)) ||
+                ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
     }
-    
-    
+
+
 
     /**
      * Rotate the plane around the specified point.
      * <p>
      * The instance is not modified, a new instance is created.
      * </p>
-     * 
+     *
      * @param center   rotation center
      * @param rotation 3-dimensional rotation
      * @return a new plane
@@ -351,11 +350,11 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         final Vector3D delta = getOrigin().subtract(center);
         Vector3D p = center.add(rotation.apply(delta));
         Vector3D normal = rotation.apply(this.w);
-        Vector3D w = normal.normalize();
-        double originOffset = -p.dot(w);
-        Vector3D u = rotation.apply(this.u);
-        Vector3D v = rotation.apply(this.v);
-        return new Plane(u, v, w, originOffset, this.precision);
+        Vector3D wTmp = normal.normalize();
+        double originOffsetTmp = -p.dot(wTmp);
+        Vector3D uTmp = rotation.apply(this.u);
+        Vector3D vTmp = rotation.apply(this.v);
+        return new Plane(uTmp, vTmp, wTmp, originOffsetTmp, this.precision);
     }
 
     /**
@@ -363,21 +362,21 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * <p>
      * The instance is not modified, a new instance is created.
      * </p>
-     * 
+     *
      * @param translation translation to apply
      * @return a new plane
      */
     public Plane translate(final Vector3D translation) {
         Vector3D p = getOrigin().add(translation);
         Vector3D normal = this.w;
-        Vector3D w = normal.normalize();
-        double originOffset = -p.dot(w);
-        return new Plane(this.u, this.v, w, originOffset, this.precision);
+        Vector3D wTmp = normal.normalize();
+        double originOffsetTmp = -p.dot(wTmp);
+        return new Plane(this.u, this.v, wTmp, originOffsetTmp, this.precision);
     }
 
     /**
      * Get the intersection of a line with the instance.
-     * 
+     *
      * @param line line intersecting the instance
      * @return intersection point between between the line and the instance (null if
      *         the line is parallel to the instance)
@@ -395,7 +394,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Build the line shared by the instance and another plane.
-     * 
+     *
      * @param other other plane
      * @return line at the intersection of the instance and the other plane (really
      *         a {@link Line Line} instance)
@@ -411,7 +410,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Get the intersection point of three planes.
-     * 
+     *
      * @param plane1 first plane1
      * @param plane2 second plane2
      * @param plane3 third plane2
@@ -454,7 +453,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Build a region covering the whole hyperplane.
-     * 
+     *
      * @return a region covering the whole hyperplane
      */
     @Override
@@ -464,7 +463,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Build a region covering the whole space.
-     * 
+     *
      * @return a region containing the instance (really a {@link PolyhedronsSet
      *         PolyhedronsSet} instance)
      */
@@ -475,14 +474,14 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Check if the instance contains a point.
-     * 
+     *
      * @param p point to check
      * @return true if p belongs to the plane
      */
     public boolean contains(final Vector3D p) {
         return precision.eqZero(getOffset(p));
     }
-    
+
     /**
      * Check if the instance contains a line
      * @param line line to check
@@ -492,7 +491,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     {
         Vector3D origin = line.getOrigin();
         Vector3D direction = line.getDirection();
-        return (contains(origin) && areCoplanar(u, v, direction, precision));
+        return contains(origin) && areCoplanar(u, v, direction, precision);
     }
 
     /** Check, if the line is parallel to the instance.
@@ -516,7 +515,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         return precision.eqZero(w.cross(plane.w).norm());
     }
 
-    
+
     /**
      * Get the offset (oriented distance) of a parallel plane.
      * <p>
@@ -528,7 +527,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * on the plus side of the instance and negative if it is on the minus side,
      * according to its natural orientation.
      * </p>
-     * 
+     *
      * @param plane plane to check
      * @return offset of the plane
      */
@@ -549,7 +548,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         }
         return getOffset(line.getOrigin());
     }
-    
+
     /**
      * Get the offset (oriented distance) of a point.
      * <p>
@@ -558,7 +557,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * if the point is on the other side, according to the hyperplane natural
      * orientation.
      * </p>
-     * 
+     *
      * @param point point to check
      * @return offset of the point
      */
@@ -569,7 +568,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     /**
      * Check if the instance has the same orientation as another hyperplane.
-     * 
+     *
      * @param other other hyperplane to check against the instance
      * @return true if the instance and the other hyperplane have the same
      *         orientation
@@ -593,17 +592,20 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     /** {@inheritDoc} */
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj){
             return true;
-        if (obj == null)
+        }
+        if (obj == null){
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()){
             return false;
+        }
         Plane other = (Plane) obj;
-        return  Double.doubleToLongBits(originOffset) == Double.doubleToLongBits(other.originOffset)
-                && Objects.equals(u, other.u) && Objects.equals(v, other.v) && Objects.equals(w, other.w);
+        return  Double.doubleToLongBits(originOffset) == Double.doubleToLongBits(other.originOffset) &&
+                Objects.equals(u, other.u) && Objects.equals(v, other.v) && Objects.equals(w, other.w);
     }
-    
+
     /**
      * Check if provided vectors are coplanar.
      * @param u first vector


[commons-geometry] 16/16: Merge branch 'GEOMETRY-29__sven'

Posted by er...@apache.org.
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 c45647f45df7d81819e47ad6bd0d342069fb305d
Merge: e94830b 7a42a6f
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Mon May 20 15:25:38 2019 +0200

    Merge branch 'GEOMETRY-29__sven'
    
    Closes #31.

 .../threed/enclosing/SphereGenerator.java          |   2 +-
 .../commons/geometry/euclidean/threed/Line.java    |  29 +
 .../commons/geometry/euclidean/threed/Plane.java   | 597 +++++++++++++--------
 .../geometry/euclidean/threed/PolyhedronsSet.java  |  14 +-
 .../geometry/euclidean/threed/Vector3D.java        |   4 +-
 .../geometry/euclidean/EuclideanTestUtils.java     |   2 +-
 .../geometry/euclidean/threed/PlaneTest.java       | 272 +++++++---
 .../euclidean/threed/PolyhedronsSetTest.java       |  38 +-
 8 files changed, 640 insertions(+), 318 deletions(-)



[commons-geometry] 12/16: GEOMETRY-29 adds javadoc comment.

Posted by er...@apache.org.
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 b14d63c553cf827e1783ed889fa5414072adf850
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Wed Apr 3 21:53:27 2019 +0200

    GEOMETRY-29 adds javadoc comment.
---
 .../main/java/org/apache/commons/geometry/euclidean/threed/Line.java    | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
index bd3c189..af1740b 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
@@ -239,11 +239,13 @@ public class Line implements Embedding<Vector3D, Vector1D> {
         return new SubLine(this, new IntervalsSet(precision));
     }
     
+    /** {@inheritDoc} */
     @Override
     public int hashCode() {
         return Objects.hash(direction, precision, zero);
     }
 
+    /** {@inheritDoc} */
     @Override
     public boolean equals(Object obj) {
         if (this == obj)


[commons-geometry] 13/16: GEOMETRY-29 makes {{origin}} computed instead of stored. Makes {{areCoplanar}} a private helper method in {{Plane}}.

Posted by er...@apache.org.
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 be6c6c82a55ac4320577e836adf4d5da8f3a0f2a
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Wed Apr 10 10:12:56 2019 +0200

    GEOMETRY-29 makes {{origin}} computed instead of stored. Makes {{areCoplanar}} a private helper method in {{Plane}}.
---
 .../commons/geometry/euclidean/threed/Plane.java   | 57 ++++++++++------------
 .../geometry/euclidean/threed/Vector3D.java        | 13 -----
 2 files changed, 26 insertions(+), 44 deletions(-)

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 1e71e22..c513fc3 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
@@ -44,9 +44,6 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     /** Offset of the origin with respect to the plane. */
     private final double originOffset;
 
-    /** orthogonal projection of the 3D-space origin in the plane. */
-    private final Vector3D origin;
-    
     /** Precision context used to compare floating point numbers. */
     private final DoublePrecisionContext precision;
 
@@ -60,17 +57,16 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param precision precision context used to compare floating point values
      * @throws IllegalArgumentException if the provided vectors are coplanar or not normalized
      */
-    private Plane(final Vector3D u, final Vector3D v, final Vector3D w, final Vector3D origin, double originOffset,
+    private Plane(final Vector3D u, final Vector3D v, final Vector3D w, double originOffset,
             final DoublePrecisionContext precision) {
         this.u = u;
         this.v = v;
         this.w = w;
       
-        if (Vector3D.areCoplanar(u, v, w, precision))
+        if (areCoplanar(u, v, w, precision))
         {
             throw new IllegalArgumentException("Provided vectors must not be coplanar.");
         }
-        this.origin = origin;
         this.originOffset = originOffset;
         this.precision = precision;
     }
@@ -91,8 +87,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         Vector3D vNorm = uNorm.orthogonal(v);
         Vector3D wNorm = uNorm.cross(vNorm).normalize();
         double originOffset = -p.dot(wNorm);
-        Vector3D origin = calculateOrigin(wNorm, originOffset);
-        return new Plane(uNorm, vNorm, wNorm, origin, originOffset, precision);
+        return new Plane(uNorm, vNorm, wNorm, originOffset, precision);
     }
     
     /**
@@ -119,10 +114,9 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public static Plane fromPointAndNormal(final Vector3D p, final Vector3D normal, final DoublePrecisionContext precision) {
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D origin = calculateOrigin(w, originOffset);
         Vector3D u = w.orthogonal();
         Vector3D v = w.cross(u);
-        return new Plane(u, v, w, origin, originOffset, precision);
+        return new Plane(u, v, w, originOffset, precision);
     }
     
     /**
@@ -157,7 +151,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     @Deprecated
     @Override
     public Plane copySelf() {
-        return new Plane(this.u, this.v, this.w, this.origin, this.originOffset, this.precision);
+        return new Plane(this.u, this.v, this.w, this.originOffset, this.precision);
     }
 
     /**
@@ -166,7 +160,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      *         origin)
      */
     public Vector3D getOrigin() {
-        return origin;
+        return w.multiply(-originOffset);
     }
     
     /**
@@ -285,8 +279,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         Vector3D v = tmp;
         Vector3D w = this.w.negate();
         double originOffset = -this.originOffset;
-        Vector3D origin = calculateOrigin(w, originOffset);
-        return new Plane(u, v, w, origin, originOffset, this.precision);
+        return new Plane(u, v, w, originOffset, this.precision);
     }
 
     /**
@@ -355,15 +348,14 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return a new plane
      */
     public Plane rotate(final Vector3D center, final QuaternionRotation rotation) {
-        final Vector3D delta = origin.subtract(center);
+        final Vector3D delta = getOrigin().subtract(center);
         Vector3D p = center.add(rotation.apply(delta));
         Vector3D normal = rotation.apply(this.w);
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D origin = calculateOrigin(w, originOffset);
         Vector3D u = rotation.apply(this.u);
         Vector3D v = rotation.apply(this.v);
-        return new Plane(u, v, w, origin, originOffset, this.precision);
+        return new Plane(u, v, w, originOffset, this.precision);
     }
 
     /**
@@ -376,12 +368,11 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return a new plane
      */
     public Plane translate(final Vector3D translation) {
-        Vector3D p = origin.add(translation);
+        Vector3D p = getOrigin().add(translation);
         Vector3D normal = this.w;
         Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
-        Vector3D origin = calculateOrigin(w, originOffset);
-        return new Plane(this.u, this.v, w, origin, originOffset, this.precision);
+        return new Plane(this.u, this.v, w, originOffset, this.precision);
     }
 
     /**
@@ -501,7 +492,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     {
         Vector3D origin = line.getOrigin();
         Vector3D direction = line.getDirection();
-        return (contains(origin) && Vector3D.areCoplanar(u, v, direction, precision));
+        return (contains(origin) && areCoplanar(u, v, direction, precision));
     }
 
     /** Check, if the line is parallel to the instance.
@@ -590,13 +581,13 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
 
     @Override
     public String toString() {
-        return "Plane [u=" + u + ", v=" + v + ", w=" + w + ", origin=" + origin + "]";
+        return "Plane [u=" + u + ", v=" + v + ", w=" + w  + "]";
     }
 
     /** {@inheritDoc} */
     @Override
     public int hashCode() {
-        return Objects.hash(origin, originOffset, u, v, w);
+        return Objects.hash(originOffset, u, v, w);
     }
 
     /** {@inheritDoc} */
@@ -609,16 +600,20 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         if (getClass() != obj.getClass())
             return false;
         Plane other = (Plane) obj;
-        return Objects.equals(origin, other.origin)
-                && Double.doubleToLongBits(originOffset) == Double.doubleToLongBits(other.originOffset)
+        return  Double.doubleToLongBits(originOffset) == Double.doubleToLongBits(other.originOffset)
                 && Objects.equals(u, other.u) && Objects.equals(v, other.v) && Objects.equals(w, other.w);
     }
     
-    private static Vector3D calculateOrigin(Vector3D w, double originOffset) {
-        return w.multiply(-originOffset);
-    }
-    
-    private boolean areVectorsNormalized(Vector3D u, Vector3D v, Vector3D w, DoublePrecisionContext precision) {
-        return precision.eq(u.normSq(), 1) && precision.eq(v.normSq(), 1) && precision.eq(w.normSq(), 1);
+    /**
+     * Check if provided vectors are coplanar.
+     * @param u first vector
+     * @param v second vector
+     * @param w third vector
+     * @param precision precision context used to compare floating point values
+     * @return true if vectors are coplanar, false otherwise.
+     */
+    private static boolean areCoplanar(final Vector3D u, final Vector3D v, final Vector3D w, final DoublePrecisionContext precision)
+    {
+        return precision.eqZero(u.dot(v.cross(w)));
     }
 }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
index 1b54d0b..080b348 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
@@ -371,19 +371,6 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> {
         return transform.apply(this);
     }
 
-    /**
-     * Check if provided vectors are coplanar.
-     * @param u first vector
-     * @param v second vector
-     * @param w third vector
-     * @param precision precision context used to compare floating point values
-     * @return true if vectors are coplanar, false otherwise.
-     */
-    public static boolean areCoplanar(final Vector3D u, final Vector3D v, final Vector3D w, final DoublePrecisionContext precision)
-    {
-        return precision.eqZero(u.dot(v.cross(w)));
-    }
-    
     /** {@inheritDoc} */
     @Override
     public boolean equals(final Vector3D vec, final DoublePrecisionContext precision) {


[commons-geometry] 07/16: GEOMETRY-29 removes my alternative version (probably slower) of contains(Plane).

Posted by er...@apache.org.
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 7d5a0063f5bbb90edbffc0f00053016703a8faba
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Sun Mar 24 06:38:20 2019 +0100

    GEOMETRY-29 removes my alternative version (probably slower) of contains(Plane).
---
 .../commons/geometry/euclidean/threed/Plane.java   | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

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 150e7dc..59e83ea 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
@@ -355,24 +355,9 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return true if the planes are similar
      */
     public boolean contains(final Plane plane) {
-        //final double angle = w.angle(plane.w);
-
-//        return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset))
-//                || ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
-    
-        Vector3D u_other = plane.getU();
-        Vector3D v_other = plane.getV();
-        
-        boolean isVOtherInPlane = Vector3D.areCoplanar(u, v, v_other, precision); 
-        boolean isUOtherInPlane = Vector3D.areCoplanar(u, v, u_other, precision);
-        if (isVOtherInPlane && isUOtherInPlane && contains(plane.getOrigin()))
-        {
-            return true;
-        }
-        return false;
-    
-                
-    
+        final double angle = w.angle(plane.w);
+        return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset))
+                || ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
     }
     
     
@@ -649,5 +634,4 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     private boolean areVectorsNormalized(Vector3D u, Vector3D v, Vector3D w, DoublePrecisionContext precision) {
         return precision.eq(u.normSq(), 1) && precision.eq(v.normSq(), 1) && precision.eq(w.normSq(), 1);
     }
-
 }


[commons-geometry] 09/16: GEOMETRY-29 working on Matts review.

Posted by er...@apache.org.
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 d0302b95080e036c1caa5d26becf018b54b4bc1e
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Sun Mar 31 18:41:49 2019 +0200

    GEOMETRY-29 working on Matts review.
---
 .../commons/geometry/euclidean/threed/Plane.java   | 29 ++++++++++++----------
 1 file changed, 16 insertions(+), 13 deletions(-)

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 d0556da..c644a39 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
@@ -91,12 +91,12 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      */
     public static Plane fromPointAndPlaneVectors (Vector3D p, final Vector3D u, final Vector3D v, final DoublePrecisionContext precision)
     {
-        Vector3D u_norm = u.normalize();
-        Vector3D v_norm = v.normalize();
-        Vector3D w_norm = u_norm.cross(v_norm).normalize();
-        double originOffset = -p.dot(w_norm);
-        Vector3D projectedOrigin = calculateOrigin(w_norm, originOffset);
-        return new Plane(u_norm, v_norm, w_norm, projectedOrigin, originOffset, precision);
+        Vector3D uNorm = u.normalize();
+        Vector3D vNorm = v.normalize();
+        Vector3D wNorm = uNorm.cross(vNorm).normalize();
+        double originOffset = -p.dot(wNorm);
+        Vector3D projectedOrigin = calculateOrigin(wNorm, originOffset);
+        return new Plane(uNorm, vNorm, wNorm, projectedOrigin, originOffset, precision);
     }
     
     /**
@@ -144,7 +144,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      */
     public static Plane fromPoints(final Vector3D p1, final Vector3D p2, final Vector3D p3,
             final DoublePrecisionContext precision) {
-        return Plane.fromPointAndNormal(p1, p2.subtract(p1).cross(p3.subtract(p1)), precision);
+        return Plane.fromPointAndNormal(p1, p1.vectorTo(p2).cross(p1.vectorTo(p3)), precision);
     }
 
     /**
@@ -157,10 +157,13 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane plane to copy
      * @return a new plane
      */
-    public static Plane of(final Plane plane) {
+    public static Plane of(Plane plane) {
         return new Plane(plane.u, plane.v, plane.w, plane.projectedOrigin, plane.originOffset, plane.getPrecision());
     }
 
+    
+    // This should be removed after GEOMETRY-32 is done.
+    
     /**
      * Copy the instance.
      * <p>
@@ -270,7 +273,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public Line project(Line line)
     {
         Vector3D direction = line.getDirection();
-        Vector3D projection = w.multiply(direction.dot(w)).multiply(1/Math.pow(w.norm(), 2));
+        Vector3D projection = w.multiply(direction.dot(w)).multiply(1/w.normSq());
         Vector3D projectedLineDirection = direction.subtract(projection);
         Vector3D p1 = project(line.getOrigin());
         Vector3D p2 = p1.add(projectedLineDirection);
@@ -353,7 +356,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane plane to which the instance is compared
      * @return true if the planes are similar
      */
-    public boolean contains(final Plane plane) {
+    public boolean contains(Plane plane) {
         final double angle = w.angle(plane.w);
         return ((precision.eqZero(angle)) && precision.eq(originOffset, plane.originOffset))
                 || ((precision.eq(angle, Math.PI)) && precision.eq(originOffset, -plane.originOffset));
@@ -426,7 +429,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @return line at the intersection of the instance and the other plane (really
      *         a {@link Line Line} instance)
      */
-    public Line intersection(final Plane other) {
+    public Line intersection(Plane other) {
         final Vector3D direction = w.cross(other.w);
         if (precision.eqZero(direction.norm())) {
             return null;
@@ -443,7 +446,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane3 third plane2
      * @return intersection point of three planes, null if some planes are parallel
      */
-    public static Vector3D intersection(final Plane plane1, final Plane plane2, final Plane plane3) {
+    public static Vector3D intersection(Plane plane1, Plane plane2, Plane plane3) {
 
         // coefficients of the three planes linear equations
         final double a1 = plane1.w.getX();
@@ -558,7 +561,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      * @param plane plane to check
      * @return offset of the plane
      */
-    public double getOffset(final Plane plane) {
+    public double getOffset(Plane plane) {
         return originOffset + (sameOrientationAs(plane) ? -plane.originOffset : plane.originOffset);
     }
 


[commons-geometry] 02/16: GEOMETRY-29 replaces removes redundant method: calculateW.

Posted by er...@apache.org.
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 d8697cfb5d8e6ed05948fc5a46f2909871c04166
Author: Sven Rathgeber <sv...@dfs.de>
AuthorDate: Sun Mar 17 08:39:15 2019 +0100

    GEOMETRY-29 replaces removes redundant method: calculateW.
---
 .../org/apache/commons/geometry/euclidean/threed/Plane.java | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

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 8060a8b..f581dc1 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
@@ -21,7 +21,6 @@ import java.util.Objects;
 import org.apache.commons.geometry.core.partitioning.Embedding;
 import org.apache.commons.geometry.core.partitioning.Hyperplane;
 import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
-import org.apache.commons.geometry.euclidean.internal.Vectors;
 import org.apache.commons.geometry.euclidean.oned.Vector1D;
 import org.apache.commons.geometry.euclidean.threed.rotation.QuaternionRotation;
 import org.apache.commons.geometry.euclidean.twod.PolygonsSet;
@@ -60,7 +59,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     
     public static Plane fromNormal(final Vector3D normal, final DoublePrecisionContext precision)
             throws IllegalArgumentException {
-        Vector3D w = calculateW(normal);
+        Vector3D w = normal.normalize();
         double originOffset = 0;
         Vector3D origin = calculateOrigin(w, originOffset);
         Vector3D u = w.orthogonal();
@@ -72,10 +71,6 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         return w.multiply(-originOffset);
     }
 
-    private static Vector3D calculateW(final Vector3D normal) {
-        final double norm = Vectors.checkedNorm(normal);
-        return normal.multiply(1.0 / norm);
-    }
 
     /**
      * Build a plane from a point and a normal.
@@ -87,7 +82,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
      */
     public static Plane fromPointAndNormal(final Vector3D p, final Vector3D normal, final DoublePrecisionContext precision)
             throws IllegalArgumentException {
-        Vector3D w = calculateW(normal);
+        Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
         Vector3D origin = calculateOrigin(w, originOffset);
         Vector3D u = w.orthogonal();
@@ -334,7 +329,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
         final Vector3D delta = origin.subtract(center);
         Vector3D p = center.add(rotation.apply(delta));
         Vector3D normal = rotation.apply(this.w);
-        Vector3D w = calculateW(normal);
+        Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
         Vector3D origin = calculateOrigin(w, originOffset);
         Vector3D u = rotation.apply(this.u);
@@ -354,7 +349,7 @@ public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Ve
     public Plane translate(final Vector3D translation) {
         Vector3D p = origin.add(translation);
         Vector3D normal = this.w;
-        Vector3D w = calculateW(normal);
+        Vector3D w = normal.normalize();
         double originOffset = -p.dot(w);
         Vector3D origin = calculateOrigin(w, originOffset);
         return new Plane(this.u, this.v, w, origin, originOffset, this.precision);