public double slope() { double x1 = c1.x(); double x2 = c2.x(); double y1 = c1.y(); double y2 = c2.y(); return (y2 - y1) / (x2 - x1); }
public XY get(double fractionAlongLine) { double deltaX = c2.x() - c1.x(); double deltaY = c2.y() - c1.y(); double deltaZ = c2.z() - c1.z(); double newX = c1.x() + fractionAlongLine * deltaX; double newY = c1.y() + fractionAlongLine * deltaY; double newZ = c1.z() + fractionAlongLine * deltaZ; return new XY(newX, newY, newZ); }
public static double interpolateY(Line line, double xValue) { // if point1.x() == point2.x(), is a vertical line, will produce an infinity value XY point1 = line.getStart(); XY point2 = line.getEnd(); double x1 = point1.x(); double x2 = point2.x(); double y1 = point1.y(); double y2 = point2.y(); return (y2 - y1) / (x2 - x1) * (xValue - x1) + y1; }
double distance(XY a, XY b) { a = new XY(a); a.subtract(b); return a.length(); }
public String toString() { return "Line from " + c1.toString() + " to " + c2.toString(); }
public Line(XY start, XY end) { c1 = start; c2 = end; hasZ = start.hasZ() && end.hasZ(); }
public Vector toVector() { double deltaX = c2.x() - c1.x(); double deltaY = c2.y() - c1.y(); double deltaZ = c2.z() - c1.z(); return new Vector(deltaX, deltaY, deltaZ); }
public XY getEnd() { if (hasZ) return c2; else return c2.ignoreZ(); }
public XY getStart() { if (hasZ) return c1; else return c1.ignoreZ(); }
private void checkPoint(XY actual, XY expected) { assertThat(actual.getX()).isEqualTo(expected.getX(), offset(0.000001)); assertThat(actual.getY()).isEqualTo(expected.getY(), offset(0.000001)); }
/** Constructs a circle with the specified properties */ public Circle(XY p, double radius) { this(p.x(), p.y(), radius); }