checkpoint
[anneal.git] / src / edu / berkeley / qfat / geom / Plane.java
1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
3
4 public class Plane implements AffineConstraint {
5
6     // ax+by+cz=d
7     public final float a, b, c, d;
8
9     public Vec norm() { return new Vec(a, b, c); }
10
11     public Plane(Point p, Vec norm) {
12         this.a = norm.x;
13         this.b = norm.y;
14         this.c = norm.z;
15         this.d = p.x*norm.x+p.y*norm.y+p.z*norm.z;
16     }
17
18     /** provided at least one of a,b,c is nonzero, return the Plane representing ax+by+cz=d */
19     public Plane(float a, float b, float c, float d) {
20         this.a = a;
21         this.b = b;
22         this.c = c;
23         this.d = d;
24     }
25
26     public Point intersect(Plane p1, Plane p2) {
27         Vec norm = norm();
28         Plane p3 = this;
29         float z = p1.norm().dot(p2.norm().cross(p3.norm()));
30         if (Math.abs(z) < 0.0001) return null;  // planes do not intersect at a point
31         Vec v1 = p2.norm().cross(p3.norm()).times(-1 * p1.d);
32         Vec v2 = p3.norm().cross(p1.norm()).times(-1 * p2.d);
33         Vec v3 = p1.norm().cross(p2.norm()).times(-1 * p3.d);
34         return Point.ZERO.plus(v1.plus(v2).plus(v3).times(1/z));
35     }
36
37     public Point getProjection(Point p) {
38         throw new RuntimeException("not implemented yet");
39     }
40
41     public AffineConstraint intersect(AffineConstraint c, float epsilon) {
42         throw new RuntimeException("not implemented yet");
43     }
44
45     public AffineConstraint multiply(Matrix m) {
46         throw new RuntimeException("not yet implemented");
47     }
48 }