checkpoint autogen tile
[anneal.git] / src / edu / berkeley / qfat / geom / Plane.java
diff --git a/src/edu/berkeley/qfat/geom/Plane.java b/src/edu/berkeley/qfat/geom/Plane.java
new file mode 100644 (file)
index 0000000..1f79b06
--- /dev/null
@@ -0,0 +1,24 @@
+package edu.berkeley.qfat.geom;
+import javax.media.opengl.*;
+
+public class Plane {
+
+    public final Vec norm;
+    public final float dvalue;
+
+    public Plane(Point p, Vec norm) {
+        this.norm = norm.norm();
+        this.dvalue = p.x*this.norm.x+p.y*this.norm.y+p.z*this.norm.z;
+    }
+
+    public Point intersect(Plane p1, Plane p2) {
+        Plane p3 = this;
+        float z = p1.norm.dot(p2.norm.cross(p3.norm));
+        if (Math.abs(z) == 0) return null;  // planes do not intersect at a point
+        Vec v1 = p2.norm.cross(p3.norm).times(-1 * p1.dvalue);
+        Vec v2 = p3.norm.cross(p1.norm).times(-1 * p2.dvalue);
+        Vec v3 = p1.norm.cross(p2.norm).times(-1 * p3.dvalue);
+        return Point.ORIGIN.plus(v1.plus(v2).plus(v3).times(1/z));
+    }
+
+}