1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
5 * an oriented triangle, defined by three points in clockwise order.
7 public abstract class Triangle implements HasBoundingBox {
8 public abstract Point p1();
9 public abstract Point p2();
10 public abstract Point p3();
12 /** the face normal vector */
14 return p2().minus(p1()).cross(p3().minus(p1())).norm();
17 /** the area of the triangle */
20 (float)Math.abs(0.5*p1().distance(p2())
21 * new Vec(p1(), p2()).norm().dot(new Vec(p2(), p3())));
24 /** issue gl.glVertex() for each of the triangle's points */
25 public void glVertices(GL gl) {
31 /** the triangle's centroid */
32 public Point centroid() {
33 return new Point((p1().x+p2().x+p3().x)/3,
34 (p1().y+p2().y+p3().y)/3,
35 (p1().z+p2().z+p3().z)/3);
38 /** ratio of the area of the triangle to that of the square formed from its longest edge */
39 public float aspect() {
40 float max = Math.max(Math.max(p1().distance(p2()),
42 p3().distance(p1())) / 2;
43 return 1/(1+area()/(max*max));
46 public float getMaxX() { return Math.max(p1().x, Math.max(p2().x, p3().x)); }
47 public float getMinX() { return Math.min(p1().x, Math.min(p2().x, p3().x)); }
48 public float getMaxY() { return Math.max(p1().y, Math.max(p2().y, p3().y)); }
49 public float getMinY() { return Math.min(p1().y, Math.min(p2().y, p3().y)); }
50 public float getMaxZ() { return Math.max(p1().z, Math.max(p2().z, p3().z)); }
51 public float getMinZ() { return Math.min(p1().z, Math.min(p2().z, p3().z)); }