X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FLine.java;h=cafa081ff6e6e236996c4e6dad5f8c8fde0c71dc;hp=a4dd2a09b5eb2e5bad23f30603ac68b7c77eb8d9;hb=eabe4f7acd947415f183290dc3269b2502a25a1c;hpb=64c6939d78acfa06e7bc380cb713e3800bf16be5 diff --git a/src/edu/berkeley/qfat/geom/Line.java b/src/edu/berkeley/qfat/geom/Line.java index a4dd2a0..cafa081 100644 --- a/src/edu/berkeley/qfat/geom/Line.java +++ b/src/edu/berkeley/qfat/geom/Line.java @@ -10,12 +10,18 @@ public class Line implements AffineConstraint { /** the line passing through two points */ public Line(Point p1, Point p2) { + // FIXME: division by zero? this.m = (p2.y-p1.y)/(p2.x-p1.x); this.n = (p2.z-p1.z)/(p2.x-p1.x); this.c = p1.y - m * p1.x; this.d = p1.z - n * p1.x; } + /** the line passing through p1 with direction v */ + public Line(Point p1, Vec v) { + this(p1, v.plus(p1)); + } + public int hashCode() { return Float.floatToIntBits(m) ^ @@ -43,13 +49,13 @@ public class Line implements AffineConstraint { /** returns the point on this line which is closest to p */ public Point getProjection(Point p) { - /* Point p1 = new Point(0, c, d); Point p2 = new Point(1, m+c, n+d); Vec w = p.minus(p1); - return getUnit().times(w.dot(getUnit())); - */ + return p1.plus(getUnit().times(w.dot(getUnit()))); + /* throw new RuntimeException("test this before using; may not be correct"); + */ } public AffineConstraint intersect(AffineConstraint con, float epsilon) { @@ -67,7 +73,10 @@ public class Line implements AffineConstraint { } public AffineConstraint multiply(Matrix m) { - throw new RuntimeException("not yet implemented"); + // FIXME: ugly + Point p1 = new Point(0, c, d); + Point p2 = new Point(1, this.m+c, n+d); + return new Line(m.times(p1), m.times(p2)); } }