fixed vertex normals
authoradam <adam@megacz.com>
Sun, 2 Dec 2007 00:49:18 +0000 (16:49 -0800)
committeradam <adam@megacz.com>
Sun, 2 Dec 2007 00:49:18 +0000 (16:49 -0800)
darcs-hash:20071202004918-5007d-19757f664e2369cf77b9d9c77775dd383ab18e94.gz

src/Geom.java
src/Main.java

index 558332d..3a5f4a6 100644 (file)
@@ -179,17 +179,13 @@ public class Geom implements Iterable<Geom.T> {
         public String toString() { return ""+name; }
         //{ return "("+x+","+y+","+z+")"; }
         public V norm() {
-            /*
-            if (t==null) throw new Error("attempt to get vertex normal for point which does not belong to any triangles");
-            T ti = t;
             V norm = new V(0, 0, 0);
+            E e = this.e;
             do {
-                norm = norm.plus(ti.norm().times((float)ti.angle(this)));
-                ti = ti.nextT(this);
-            } while(ti != t);
+                norm = norm.plus(e.t.norm().times((float)e.prev.angle()));
+                e = e.pair.next;
+            } while(e != this.e);
             return norm.norm();
-            */
-            throw new Error();
         }
     }
 
@@ -239,6 +235,13 @@ public class Geom implements Iterable<Geom.T> {
             return t;
         }
 
+        /** angle between this half-edge and the next */
+        public double angle() {
+            V v1 = next.p2.minus(p2);
+            V v2 = this.p1.minus(p2);
+            return Math.acos(v1.norm().dot(v2.norm()));
+        }
+
         public void makeAdjacent(E e) {
             if (this.next == e) return;
             if (p2 != e.p1) throw new Error("cannot make adjacent -- no shared vertex");
@@ -415,14 +418,8 @@ public class Geom implements Iterable<Geom.T> {
             else if (p == e3.shared(e1)) return e1;
             else throw new Error("triangle " + this + " does not own point " + p);
         }
-
-        // returns the angle at point p
-        public double angle(P p) {
-            V v1 = nextE(p).other(p).minus(p);
-            V v2 = prevE(p).other(p).minus(p);
-            return Math.acos(v1.norm().dot(v2.norm()));
-        }
         */
+
     }
 
 
index e97f975..fc8d2ee 100644 (file)
@@ -217,17 +217,17 @@ public class Main implements GLEventListener {
             Geom.P centroid = t.centroid();
             gl.glBegin(GL.GL_LINES);
             gl.glColor3f(1, 1, 1);
-
+            /*
             centroid.glVertex(gl);
             centroid.plus(t.norm().times(t.diameter())).glVertex(gl);
-            /*
+            */
             t.p1().glVertex(gl);
             t.p1().plus(t.p1().norm().times(t.diameter())).glVertex(gl);
             t.p2().glVertex(gl);
             t.p2().plus(t.p2().norm().times(t.diameter())).glVertex(gl);
             t.p3().glVertex(gl);
             t.p3().plus(t.p3().norm().times(t.diameter())).glVertex(gl);
-            */
+
             gl.glEnd();
 
         }