X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FLine.java;h=a4dd2a09b5eb2e5bad23f30603ac68b7c77eb8d9;hp=7fb9b86fe113ef5ec9dd17bb743f48bb69e9386b;hb=64c6939d78acfa06e7bc380cb713e3800bf16be5;hpb=de2400d58116bd995e73baf7a429e22def1e4067 diff --git a/src/edu/berkeley/qfat/geom/Line.java b/src/edu/berkeley/qfat/geom/Line.java index 7fb9b86..a4dd2a0 100644 --- a/src/edu/berkeley/qfat/geom/Line.java +++ b/src/edu/berkeley/qfat/geom/Line.java @@ -2,7 +2,7 @@ package edu.berkeley.qfat.geom; import javax.media.opengl.*; /** an infinitely long line in 3-space */ -public class Line { +public class Line implements AffineConstraint { // y=mx+c // z=nx+d @@ -33,10 +33,16 @@ public class Line { return "[line: y="+m+"x+"+c+" z="+n+"x+"+d+"]"; } - public double distance(Point p) { return projection(p).distance(p); } + public double distance(Point p) { return getProjection(p).distance(p); } + + public Vec getUnit() { + Point p1 = new Point(0, c, d); + Point p2 = new Point(1, m+c, n+d); + return p2.minus(p1).norm(); + } /** returns the point on this line which is closest to p */ - public Point projection(Point p) { + public Point getProjection(Point p) { /* Point p1 = new Point(0, c, d); Point p2 = new Point(1, m+c, n+d); @@ -46,10 +52,22 @@ public class Line { throw new RuntimeException("test this before using; may not be correct"); } - public Vec getUnit() { - Point p1 = new Point(0, c, d); - Point p2 = new Point(1, m+c, n+d); - return p2.minus(p1).norm(); + public AffineConstraint intersect(AffineConstraint con, float epsilon) { + if (!(con instanceof Line)) return con.intersect(this, epsilon); + Line line = (Line)con; + if (Math.abs(this.m-line.m) <= epsilon && + Math.abs(this.n-line.n) <= epsilon && + Math.abs(this.c-line.c) <= epsilon && + Math.abs(this.d-line.d) <= epsilon) + return this; + float x = (line.c-this.c)/(this.m-line.m); + if (Math.abs( (m*x+c)-(line.m*x+line.c) ) > epsilon ) return null; + if (Math.abs( (n*x+d)-(line.n*x+line.d) ) > epsilon ) return null; + return new Point(x, m*x+c, n*x+d); + } + + public AffineConstraint multiply(Matrix m) { + throw new RuntimeException("not yet implemented"); } }