From 64c6939d78acfa06e7bc380cb713e3800bf16be5 Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 6 Jul 2008 17:21:23 -0700 Subject: [PATCH] checkpoint darcs-hash:20080707002123-5007d-c4ce1fb25eb174864117db302e1c0445407e4cb4.gz --- src/edu/berkeley/qfat/Main.java | 2 +- src/edu/berkeley/qfat/geom/AffineConstraint.java | 3 +++ src/edu/berkeley/qfat/geom/BindingGroup.java | 20 ++++++++++++--- src/edu/berkeley/qfat/geom/HalfSpace.java | 2 +- src/edu/berkeley/qfat/geom/HasBindingGroup.java | 6 ----- src/edu/berkeley/qfat/geom/Line.java | 4 +++ src/edu/berkeley/qfat/geom/Matrix.java | 2 +- src/edu/berkeley/qfat/geom/Plane.java | 29 ++++++++++++++-------- src/edu/berkeley/qfat/geom/Point.java | 1 + src/edu/berkeley/qfat/geom/Polygon.java | 4 +-- 10 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index ac40acc..910c35c 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -106,7 +106,7 @@ public class Main extends InteractiveMeshViewer { polygons.add(new Polygon(hs)); } for(Polygon p : polygons) { - System.out.println(p.plane.norm + " " + p.plane.dvalue); + System.out.println(p.plane.norm() + " " + p.plane.d); for(HalfSpace hs : halfSpaces) { if (p.plane==hs) continue; p = p.intersect(hs); diff --git a/src/edu/berkeley/qfat/geom/AffineConstraint.java b/src/edu/berkeley/qfat/geom/AffineConstraint.java index a6fb01c..0ac6f03 100644 --- a/src/edu/berkeley/qfat/geom/AffineConstraint.java +++ b/src/edu/berkeley/qfat/geom/AffineConstraint.java @@ -6,15 +6,18 @@ public interface AffineConstraint { public Point getProjection(Point p); public AffineConstraint intersect(AffineConstraint c, float epsilon); + public AffineConstraint multiply(Matrix m); public static class All implements AffineConstraint { public Point getProjection(Point p) { return p; } public AffineConstraint intersect(AffineConstraint c, float epsilon) { return c; } + public AffineConstraint multiply(Matrix m) { return this; } } public static class Nothing implements AffineConstraint { public Point getProjection(Point p) { return null; } public AffineConstraint intersect(AffineConstraint c, float epsilon) { return this; } + public AffineConstraint multiply(Matrix m) { return this; } } } diff --git a/src/edu/berkeley/qfat/geom/BindingGroup.java b/src/edu/berkeley/qfat/geom/BindingGroup.java index 4df8cc4..e64cc17 100644 --- a/src/edu/berkeley/qfat/geom/BindingGroup.java +++ b/src/edu/berkeley/qfat/geom/BindingGroup.java @@ -5,8 +5,9 @@ import java.util.*; /** tracks an equivalence class of geometric objects which are related to each other by transformation matrices */ public class BindingGroup implements Iterable { - private T master = null; - private HashMap matrices = new HashMap(); + private T master = null; + private AffineConstraint constraint = new AffineConstraint.All(); + private HashMap matrices = new HashMap(); public BindingGroup(T master) { this.master = master; @@ -16,13 +17,20 @@ public class BindingGroup implements Iterable { public int size() { return matrices.size(); } public void merge(BindingGroup bg, Matrix m) { - if (bg==this) throw new Error(); + if (bg==this) { + if (m.equalsModuloEpsilon(Matrix.ONE, 0.001f)) return; + System.err.println(m.getAffineConstraint(0.001f)); + return; + } + for(HasBindingGroup hbg : bg.matrices.keySet()) { matrices.put((T)hbg, bg.matrices.get(hbg).times(m)); hbg.bindingGroup = this; } - Matrix v = getMatrix(bg.master, master); + // FIXME: what if points do not fall on the merged constraint-line? + AffineConstraint ac = bg.constraint.multiply(getMatrix(master, bg.master)); + constraint = constraint.intersect(ac, 0.001f); HashSet stuff = new HashSet(); for(HasBindingGroup hbg : bg.matrices.keySet()) @@ -45,6 +53,10 @@ public class BindingGroup implements Iterable { return getMatrix(t1).times(getMatrix(t2).inverse()); } + public AffineConstraint getConstraint(T t) { + return constraint.multiply(matrices.get(t)); + } + public void unbind(T trem) { if (trem != master) { matrices.remove(trem); diff --git a/src/edu/berkeley/qfat/geom/HalfSpace.java b/src/edu/berkeley/qfat/geom/HalfSpace.java index a48a22c..8667903 100644 --- a/src/edu/berkeley/qfat/geom/HalfSpace.java +++ b/src/edu/berkeley/qfat/geom/HalfSpace.java @@ -6,7 +6,7 @@ public final class HalfSpace extends Plane { public HalfSpace(Point p, Vec norm) { super(p, norm); } public boolean contains(Point p, float epsilon) { - return p.x*norm.x+p.y*norm.y+p.z*norm.z + dvalue <= epsilon; + return p.x*norm().x+p.y*norm().y+p.z*norm().z + d <= epsilon; } } diff --git a/src/edu/berkeley/qfat/geom/HasBindingGroup.java b/src/edu/berkeley/qfat/geom/HasBindingGroup.java index ecc4f1c..16dee1c 100644 --- a/src/edu/berkeley/qfat/geom/HasBindingGroup.java +++ b/src/edu/berkeley/qfat/geom/HasBindingGroup.java @@ -16,12 +16,6 @@ public abstract class HasBindingGroup { if (bindingGroup == null) bindingGroup = new BindingGroup(this); if (other.bindingGroup == null) other.bindingGroup = new BindingGroup(other); - if (other.bindingGroup == this.bindingGroup) { - if (getBindingMatrix(other).equalsModuloEpsilon(bindingMatrix, 0.001f)) - return; - return; - } - bindingMatrix = getBindingMatrix().inverse() .times(bindingMatrix) diff --git a/src/edu/berkeley/qfat/geom/Line.java b/src/edu/berkeley/qfat/geom/Line.java index 5997130..a4dd2a0 100644 --- a/src/edu/berkeley/qfat/geom/Line.java +++ b/src/edu/berkeley/qfat/geom/Line.java @@ -66,4 +66,8 @@ public class Line implements AffineConstraint { return new Point(x, m*x+c, n*x+d); } + public AffineConstraint multiply(Matrix m) { + throw new RuntimeException("not yet implemented"); + } + } diff --git a/src/edu/berkeley/qfat/geom/Matrix.java b/src/edu/berkeley/qfat/geom/Matrix.java index 372e6c2..3713761 100644 --- a/src/edu/berkeley/qfat/geom/Matrix.java +++ b/src/edu/berkeley/qfat/geom/Matrix.java @@ -367,7 +367,7 @@ public class Matrix { } /** returns the constraint-conjunction "(forall v)Mv=v" */ - public AffineConstraint getConstraint(float epsilon) { + public AffineConstraint getAffineConstraint(float epsilon) { AffineConstraint c1 = getConstraint(a-1, b, c, d , epsilon); AffineConstraint c2 = getConstraint(e, f-1, g, h , epsilon); AffineConstraint c3 = getConstraint(i, j, k-1, l , epsilon); diff --git a/src/edu/berkeley/qfat/geom/Plane.java b/src/edu/berkeley/qfat/geom/Plane.java index 5f5d990..b3aacdd 100644 --- a/src/edu/berkeley/qfat/geom/Plane.java +++ b/src/edu/berkeley/qfat/geom/Plane.java @@ -3,29 +3,34 @@ import javax.media.opengl.*; public class Plane implements AffineConstraint { - // FIXME: could be given by // ax+by+cz=d + public final float a, b, c, d; - public final Vec norm; - public final float dvalue; + public Vec norm() { return new Vec(a, b, c); } 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; + this.a = norm.x; + this.b = norm.y; + this.c = norm.z; + this.d = p.x*norm.x+p.y*norm.y+p.z*norm.z; } /** 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) { - throw new RuntimeException("not implemented yet"); + this.a = a; + this.b = b; + this.c = c; + this.d = d; } public Point intersect(Plane p1, Plane p2) { + Vec norm = norm(); Plane p3 = this; - float z = p1.norm.dot(p2.norm.cross(p3.norm)); + float z = p1.norm().dot(p2.norm().cross(p3.norm())); if (Math.abs(z) < 0.0001) 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); + Vec v1 = p2.norm().cross(p3.norm()).times(-1 * p1.d); + Vec v2 = p3.norm().cross(p1.norm()).times(-1 * p2.d); + Vec v3 = p1.norm().cross(p2.norm()).times(-1 * p3.d); return Point.ZERO.plus(v1.plus(v2).plus(v3).times(1/z)); } @@ -36,4 +41,8 @@ public class Plane implements AffineConstraint { public AffineConstraint intersect(AffineConstraint c, float epsilon) { throw new RuntimeException("not implemented yet"); } + + public AffineConstraint multiply(Matrix m) { + throw new RuntimeException("not yet implemented"); + } } diff --git a/src/edu/berkeley/qfat/geom/Point.java b/src/edu/berkeley/qfat/geom/Point.java index 57c8667..0194ef3 100644 --- a/src/edu/berkeley/qfat/geom/Point.java +++ b/src/edu/berkeley/qfat/geom/Point.java @@ -39,5 +39,6 @@ public final class Point extends HasPoint implements HasBoundingBox, AffineConst if (c.getProjection(this).distance(this) <= epsilon) return this; return null; } + public AffineConstraint multiply(Matrix m) { return m.times(this); } } diff --git a/src/edu/berkeley/qfat/geom/Polygon.java b/src/edu/berkeley/qfat/geom/Polygon.java index 2afa144..00458b2 100644 --- a/src/edu/berkeley/qfat/geom/Polygon.java +++ b/src/edu/berkeley/qfat/geom/Polygon.java @@ -65,8 +65,8 @@ public final class Polygon { //centroid = new Point(round(centroid.x), round(centroid.y), round(centroid.z)); if (segments.size() >= 3) for(Segment s : segments) { - System.out.println("newt! " + s.p1 + " " + centroid + " " + s.p2 + " " + plane.norm.times(-1)); - mesh.newT(s.p1, centroid, s.p2, plane.norm.times(-1), 0); + System.out.println("newt! " + s.p1 + " " + centroid + " " + s.p2 + " " + plane.norm().times(-1)); + mesh.newT(s.p1, centroid, s.p2, plane.norm().times(-1), 0); } System.out.println("done"); return null; -- 1.7.10.4