6a938a3a079b7c600bc75e9da1e88cdd8e351c49
[anneal.git] / src / edu / berkeley / qfat / geom / Triangle.java
1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
3
4 public abstract class Triangle {
5     public abstract Point p1();
6     public abstract Point p2();
7     public abstract Point p3();
8
9     public Vec norm() {
10         return p2().minus(p1()).cross(p3().minus(p1())).norm();
11     }
12     public float area() {
13         return
14             (float)Math.abs(0.5*p1().distance(p2())
15                             * new Vec(p1(), p2()).norm().dot(new Vec(p2(), p3())));
16     }
17     public void glVertices(GL gl) {
18         p1().glVertex(gl);
19         p2().glVertex(gl);
20         p3().glVertex(gl);
21     }
22     public Point centroid() {
23         return new Point((p1().x+p2().x+p3().x)/3,
24                          (p1().y+p2().y+p3().y)/3, 
25                          (p1().z+p2().z+p3().z)/3);
26     }
27     public float diameter() {
28         // FIXME: what is this supposed to be?
29         return Math.max(Math.max(p1().distance(p2()),
30                                  p2().distance(p3())),
31                         p3().distance(p1())) / 2;
32     }
33
34     public float aspect() {
35         float max = Math.max(Math.max(p1().distance(p2()),
36                                       p2().distance(p3())),
37                              p3().distance(p1())) / 2;
38         return 1/(1+area()/(max*max));
39     }
40     public float aspect0() {
41         float max = Math.max(Math.max(p1().distance(p2()),
42                                       p2().distance(p3())),
43                              p3().distance(p1())) / 2;
44         return (area()/(max*max));
45     }
46
47 }