X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FPlane.java;h=fe23b83903aba072c46f4aea96f999bef938ec73;hp=ed721edd16ed8c1654f2545ef1cbda4a20f3baa1;hb=00235327934dbc5ffaf5b09cbda538ee0d3686e8;hpb=8cb2aceb7c2b140b70b9955f1a0a6f2524f2314e diff --git a/src/edu/berkeley/qfat/geom/Plane.java b/src/edu/berkeley/qfat/geom/Plane.java index ed721ed..fe23b83 100644 --- a/src/edu/berkeley/qfat/geom/Plane.java +++ b/src/edu/berkeley/qfat/geom/Plane.java @@ -1,12 +1,14 @@ 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(); @@ -14,14 +16,21 @@ public class Plane implements AffineConstraint { 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) { @@ -35,19 +44,15 @@ public class Plane implements AffineConstraint { 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 @@ -84,6 +89,14 @@ public class Plane implements AffineConstraint { } 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+"]"; } }