correct clockwiseness of normal next/prev
authoradam <adam@megacz.com>
Mon, 26 Nov 2007 05:31:15 +0000 (21:31 -0800)
committeradam <adam@megacz.com>
Mon, 26 Nov 2007 05:31:15 +0000 (21:31 -0800)
darcs-hash:20071126053115-5007d-7183c6ebb5d25eb06e1715ca2ed0d2278928ed63.gz

src/Geom.java

index a30b9a7..dafdfa2 100644 (file)
@@ -31,11 +31,12 @@ public class Geom implements Iterable<Geom.T> {
         return e;
     }
 
+    /** ensures that e1.cross(e2).norm()==e2.cross(e3).norm()==e3.cross(e1).norm()==t.norm() */
     public T newT(E e1, E e2, E e3, V norm) {
-        P p1 = e1.shared(e2);
-        P p2 = e2.shared(e3);
-        P p3 = e3.shared(e1);
-        V norm2 = p2.minus(p1).cross(p3.minus(p1));
+        P p12 = e1.shared(e2);
+        P p23 = e2.shared(e3);
+        P p31 = e3.shared(e1);
+        V norm2 = p31.minus(p12).cross(p23.minus(p12));
         float dot = norm.dot(norm2);
         if (Math.abs(dot) < EPSILON) throw new Error("dot products within epsilon of each other: "+norm+" "+norm2);
         if (dot < 0) { E t = e1; e1 = e3; e2 = e2; e3 = t; }
@@ -76,7 +77,7 @@ public class Geom implements Iterable<Geom.T> {
             V norm = new V(0, 0, 0);
             do {
                 norm = norm.plus(ti.norm().times((float)ti.angle(this)));
-                ti = ti.next(this);
+                ti = ti.nextT(this);
             } while(ti != t);
             return norm.norm();
         }
@@ -189,18 +190,20 @@ public class Geom implements Iterable<Geom.T> {
             return Math.max(Math.max(e1.length(), e2.length()), e3.length()) / 2;
         }
 
-        // FIXME: ambiguity firstEdge or secondEdge?
-        /** returns the next triangle walking "around" shared vertex p */
-        public T next(P p) { return secondEdge(p).other(this); }
+        /** returns the next triangle walking clockwise around the vertex normal */
+        public T nextT(P p) { return prevE(p).other(this); }
+        public T prevT(P p) { return nextE(p).other(this); }
 
-        public E firstEdge(P p) {
+        /** edge "after" this point, moving clockwise around the normal */
+        public E nextE(P p) {
             if      (p == e1.shared(e2)) return e1;
             else if (p == e2.shared(e3)) return e2;
             else if (p == e3.shared(e1)) return e3;
             else throw new Error("triangle " + this + " does not own point " + p);
         }
 
-        public E secondEdge(P p) {
+        /** edge "before" this point, moving clockwise around the normal */
+        public E prevE(P p) {
             if      (p == e1.shared(e2)) return e2;
             else if (p == e2.shared(e3)) return e3;
             else if (p == e3.shared(e1)) return e1;