checkpoint
authoradam <adam@megacz.com>
Wed, 5 Dec 2007 06:21:30 +0000 (22:21 -0800)
committeradam <adam@megacz.com>
Wed, 5 Dec 2007 06:21:30 +0000 (22:21 -0800)
darcs-hash:20071205062130-5007d-af39f9fe4cd1ddd758a737765bd326b43357c0fc.gz

src/edu/berkeley/qfat/Mesh.java
src/edu/berkeley/qfat/geom/Matrix.java
src/edu/berkeley/qfat/geom/Vec.java

index 374f012..94b4e73 100644 (file)
@@ -11,8 +11,8 @@ import edu.berkeley.qfat.geom.Point;
 
 public class Mesh implements Iterable<Mesh.T> {
 
-    public static float EPSILON = (float)0.0001;
-    public static Random random = new Random();
+    public static final float EPSILON = (float)0.0001;
+    public static final Random random = new Random();
 
     private PointSet<Vert> pointset = new PointSet<Vert>();
 
@@ -198,7 +198,6 @@ public class Mesh implements Iterable<Mesh.T> {
                 float newy = m.e*p.x + m.f*p.y + m.g*p.z + m.h;
                 float newz = m.i*p.x + m.j*p.y + m.k*p.z + m.l;
                 this.p = new Point(newx, newy, newz);
-                // FIXME: what if we move onto exactly where another point is?
                 pointset.add(this);
             } catch (Exception e) {
                 throw new RuntimeException(e);
@@ -305,6 +304,7 @@ public class Mesh implements Iterable<Mesh.T> {
         E next;  // next half-edge
         E pair;  // partner half-edge
         public BindingGroup bg = new BindingGroup(this);
+        boolean shattered = false;
 
         public int compareTo(E e) { return e.length() > length() ? 1 : -1; }
 
@@ -320,7 +320,6 @@ public class Mesh implements Iterable<Mesh.T> {
             }
         }
 
-        boolean shattered = false;
         public Point shatter() { return shatter(midpoint(), null, null); }
         public Point shatter(Point mid, BindingGroup bg1, BindingGroup bg2) {
             if (shattered) return mid;
index 751dfa1..f617376 100644 (file)
@@ -8,29 +8,36 @@ public class Matrix {
     //  [ i j k l ]   [ z ]
     //  [ 0 0 0 1 ]   [ 1 ]
     //
-    public final float a, b, c, d, e, f, g, h, i, j, k, l;
+    public final float a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p;
     public Matrix() { this(1); }
     public Matrix(float scale) {
         a = f = k = scale;
         l = h = d = e = b = i = c = j = g = 0;            
+        m = n = o = 0;
+        p = 1;
     }
     public Matrix(float scalex, float scaley, float scalez) {
         a = scalex;
         f = scaley;
         k = scalez;
         l = h = d = e = b = i = c = j = g = 0;            
+        m = n = o = 0;
+        p = 1;
     }
     public Matrix(Vec translate) {
         d = translate.x; h = translate.y; l = translate.z;
         a = f = k = 1;
         b = c = e = g = i = j = 0;
+        m = n = o = 0;
+        p = 1;
     }
-    public Matrix(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l) {
+    public Matrix(float a, float b, float c, float d, float e, float f, float g,
+                  float h, float i, float j, float k, float l, float m, float n, float o, float p) {
         this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; this.f = f; this.g = g; this.h = h; this.i = i;
-        this.j = j; this.k = k; this.l = l;
+        this.j = j; this.k = k; this.l = l; this.m = m; this.n = n; this.o = o; this.p = p;
     }
     public Matrix times(float x) {
-        return new Matrix(a*x, b*x, c*x, d*x, e*x, f*x, g*x, h*x, i*x, j*x, k*x, l*x);
+        return new Matrix(a*x, b*x, c*x, d*x, e*x, f*x, g*x, h*x, i*x, j*x, k*x, l*x, m*x, n*x, o*x, p*x);
     }
     public Matrix(Vec axis, float angle) {
         double q = Math.cos(angle);
@@ -52,8 +59,11 @@ public class Matrix {
         j = (float)(tmp1 + tmp2);
         g = (float)(tmp1 - tmp2);
         d = h = l = 0;
+        m = n = o = 0;
+        p = 1;
     }
     public Point times(Point p) {
+        // discards bottom row
         return new Point(a*p.x + b*p.y + c*p.z + d,
                          e*p.x + f*p.y + g*p.z + h,
                          i*p.x + j*p.y + k*p.z + l);
index c331d39..56b357e 100644 (file)
@@ -15,4 +15,18 @@ public final class Vec {
     public Vec times(float mag) { return new Vec(x*mag, y*mag, z*mag); }
     public Vec div(float mag) { return new Vec(x/mag, y/mag, z/mag); }
     public String toString() { return "<"+x+","+y+","+z+">"; }
+
+    /** fundamental error quadric for the plane with this normal passing through p */
+    public Matrix fundamentalQuadric(Point p) {
+        Vec n = this;
+        if (mag() != 1) n = norm();
+        float a = n.x;
+        float b = n.y;
+        float c = n.z;
+        float d = (-a * p.x) + (-b * p.y) + (-c * p.z);
+        return new Matrix(a*a, a*b, a*c, a*d,
+                          a*b, b*b, b*c, b*d,
+                          a*c, b*c, c*c, c*d,
+                          a*d, b*d, c*d, d*d);
+    }
 }