checkpoint
[anneal.git] / src / edu / berkeley / qfat / geom / Plane.java
index ed721ed..fe23b83 100644 (file)
@@ -1,12 +1,14 @@
 package edu.berkeley.qfat.geom;
 import javax.media.opengl.*;
 
 package edu.berkeley.qfat.geom;
 import javax.media.opengl.*;
 
+// FEATURE: represent a plane by the matrix that projects points onto that plane?
 public class Plane implements AffineConstraint {
 
     // ax+by+cz=d
     public final float a, b, c, d;
 public class Plane implements AffineConstraint {
 
     // ax+by+cz=d
     public final float a, b, c, d;
+    public final Point p;
 
 
-    public Vec norm() { return new Vec(a, b, c); }
+    public Vec norm() { return new Vec(a, b, c).norm(); }
 
     public Plane(Point p, Vec norm) {
         norm = norm.norm();
 
     public Plane(Point p, Vec norm) {
         norm = norm.norm();
@@ -14,14 +16,21 @@ public class Plane implements AffineConstraint {
         this.b = norm.y;
         this.c = norm.z;
         this.d = p.x*norm.x+p.y*norm.y+p.z*norm.z;
         this.b = norm.y;
         this.c = norm.z;
         this.d = p.x*norm.x+p.y*norm.y+p.z*norm.z;
+        this.p = p;
     }
 
     }
 
-    /** provided at least one of a,b,c is nonzero, return the Plane representing ax+by+cz=d */
     public Plane(float a, float b, float c, float d) {
     public Plane(float a, float b, float c, float d) {
+        // FIXME, what if c==0?
+        this(a, b, c, d, new Point(0, 0, d/c));
+    }
+
+    /** provided at least one of a,b,c is nonzero, return the Plane representing ax+by+cz=d */
+    public Plane(float a, float b, float c, float d, Point p) {
         this.a = a;
         this.b = b;
         this.c = c;
         this.d = d;
         this.a = a;
         this.b = b;
         this.c = c;
         this.d = d;
+        this.p = p;
     }
 
     public Point intersect(Plane p1, Plane p2) {
     }
 
     public Point intersect(Plane p1, Plane p2) {
@@ -35,19 +44,15 @@ public class Plane implements AffineConstraint {
         return Point.ZERO.plus(v1.plus(v2).plus(v3).times(1/z));
     }
 
         return Point.ZERO.plus(v1.plus(v2).plus(v3).times(1/z));
     }
 
-    public Point getProjection(Point p) {
-        throw new RuntimeException("not implemented yet");
-    }
-
     public AffineConstraint intersect(AffineConstraint c, float epsilon) {
         if (c instanceof Plane) {
             Plane p = (Plane)c;
 
             // same plane
     public AffineConstraint intersect(AffineConstraint c, float epsilon) {
         if (c instanceof Plane) {
             Plane p = (Plane)c;
 
             // same plane
-            if (Math.abs(p.a-this.a) <= epsilon &&
-                Math.abs(p.b-this.b) <= epsilon &&
-                Math.abs(p.c-this.c) <= epsilon &&
-                Math.abs(p.d-this.d) <= epsilon)
+            if (Math.abs(p.a*this.d-this.a*p.d) <= epsilon &&
+                Math.abs(p.b*this.d-this.b*p.d) <= epsilon &&
+                Math.abs(p.c*this.d-this.c*p.d) <= epsilon &&
+                Math.abs(p.d*this.d-this.d*p.d) <= epsilon)
                 return this;
 
             // parallel planes
                 return this;
 
             // parallel planes
@@ -84,6 +89,14 @@ public class Plane implements AffineConstraint {
     }
 
     public AffineConstraint multiply(Matrix m) {
     }
 
     public AffineConstraint multiply(Matrix m) {
-        throw new RuntimeException("not yet implemented");
+        return new Plane( m.times(p), m.times(norm()).norm() );
+    }
+
+    public Point getProjection(Point p) {
+        Point ret = norm().times(p.minus(this.p).dot(norm())).times(-1).plus(p);
+        return ret;
+    }
+    public String toString() {
+        return "[plane "+a+"x+"+b+"y+"+c+"z="+d+"]";
     }
 }
     }
 }