commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [commons-geometry] svenrathgeber commented on a change in pull request #31: Geometry 29 2 sven
Date Sun, 31 Mar 2019 16:43:50 GMT
svenrathgeber commented on a change in pull request #31: Geometry 29 2 sven
URL: https://github.com/apache/commons-geometry/pull/31#discussion_r270674434
 
 

 ##########
 File path: commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java
 ##########
 @@ -16,174 +16,193 @@
  */
 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;
-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;
 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 class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D>
{
-
-    /** Offset of the origin with respect to the plane. */
-    private double originOffset;
+public final class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D>
{
 
-    /** Origin of the plane frame. */
-    private Vector3D origin;
+    /** First normalized vector of the plane frame (in plane). */
+    private final Vector3D u;
 
-    /** First vector of the plane frame (in plane). */
-    private Vector3D u;
+    /** Second normalized vector of the plane frame (in plane). */
+    private final Vector3D v;
 
-    /** Second vector of the plane frame (in plane). */
-    private Vector3D v;
+    /** Normalized plane normal. */
+    private final Vector3D w;
 
-    /** Third vector of the plane frame (plane normal). */
-    private 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;
 
-    /** Build a plane normal to a given direction and containing the origin.
-     * @param normal normal direction to the plane
+    /** 
+     * 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
-     * @exception IllegalArgumentException if the normal norm is too small
+     * @throws IllegalArgumentException if the provided vectors are coplanar or not normalized
      */
-    public Plane(final Vector3D normal, final DoublePrecisionContext precision)
-        throws IllegalArgumentException {
-        setNormal(normal);
+    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 coplanar.");
+        }
+        this.projectedOrigin = projectedOrigin;
+        this.originOffset = originOffset;
         this.precision = precision;
-        originOffset = 0;
-        setFrame();
     }
-
-    /** Build a plane from a point and a normal.
-     * @param p point belonging to the plane
-     * @param normal normal direction to the plane
+    
+    /**
+     * 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
-     * @exception IllegalArgumentException if the normal norm is too small
+     * @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 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 fromPointAndPlaneVectors (Vector3D p, final Vector3D u, final Vector3D
v, final DoublePrecisionContext precision)
+    {
+        Vector3D u_norm = u.normalize();
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message