package edu.berkeley.qfat.geom;
import javax.media.opengl.*;
+// FEATURE: represent a plane by the matrix that projects points onto that plane?
public class Plane implements AffineConstraint {
// ax+by+cz=d
public final float a, b, c, d;
+ public final Point p;
- public Vec norm() { return new Vec(a, b, c); }
+ public Vec norm() { return new Vec(a, b, c).norm(); }
public Plane(Point p, Vec norm) {
norm = norm.norm();
this.b = norm.y;
this.c = norm.z;
this.d = p.x*norm.x+p.y*norm.y+p.z*norm.z;
+ this.p = p;
}
- /** provided at least one of a,b,c is nonzero, return the Plane representing ax+by+cz=d */
public Plane(float a, float b, float c, float d) {
+ // FIXME, what if c==0?
+ this(a, b, c, d, new Point(0, 0, d/c));
+ }
+
+ /** provided at least one of a,b,c is nonzero, return the Plane representing ax+by+cz=d */
+ public Plane(float a, float b, float c, float d, Point p) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
+ this.p = p;
}
public Point intersect(Plane p1, Plane p2) {
return Point.ZERO.plus(v1.plus(v2).plus(v3).times(1/z));
}
- public Point getProjection(Point p) {
- throw new RuntimeException("not implemented yet");
- }
-
public AffineConstraint intersect(AffineConstraint c, float epsilon) {
if (c instanceof Plane) {
Plane p = (Plane)c;
// same plane
- if (Math.abs(p.a-this.a) <= epsilon &&
- Math.abs(p.b-this.b) <= epsilon &&
- Math.abs(p.c-this.c) <= epsilon &&
- Math.abs(p.d-this.d) <= epsilon)
+ if (Math.abs(p.a*this.d-this.a*p.d) <= epsilon &&
+ Math.abs(p.b*this.d-this.b*p.d) <= epsilon &&
+ Math.abs(p.c*this.d-this.c*p.d) <= epsilon &&
+ Math.abs(p.d*this.d-this.d*p.d) <= epsilon)
return this;
// parallel planes
}
public AffineConstraint multiply(Matrix m) {
- throw new RuntimeException("not yet implemented");
+ return new Plane( m.times(p), m.times(norm()).norm() );
+ }
+
+ public Point getProjection(Point p) {
+ Point ret = norm().times(p.minus(this.p).dot(norm())).times(-1).plus(p);
+ return ret;
+ }
+ public String toString() {
+ return "[plane "+a+"x+"+b+"y+"+c+"z="+d+"]";
}
}