checkpoint
[anneal.git] / src / edu / berkeley / qfat / geom / Triangle.java
index 24c90d0..0ed9d39 100644 (file)
@@ -5,4 +5,29 @@ public abstract class Triangle {
     public abstract Point p1();
     public abstract Point p2();
     public abstract Point p3();
+
+    public Vec norm() {
+        return p2().minus(p1()).cross(p3().minus(p1())).norm();
+    }
+    public float area() {
+        return
+            (float)Math.abs(0.5*p1().distance(p2())
+                            * new Vec(p1(), p2()).norm().dot(new Vec(p2(), p3())));
+    }
+    public void glVertices(GL gl) {
+        p1().glVertex(gl);
+        p2().glVertex(gl);
+        p3().glVertex(gl);
+    }
+    public Point centroid() {
+        return new Point((p1().x+p2().x+p3().x)/3,
+                         (p1().y+p2().y+p3().y)/3, 
+                         (p1().z+p2().z+p3().z)/3);
+    }
+    public float diameter() {
+        // FIXME: what is this supposed to be?
+        return Math.max(Math.max(p1().distance(p2()),
+                                 p2().distance(p3())),
+                        p3().distance(p1())) / 2;
+    }
 }
\ No newline at end of file