示例#1
0
  public double slope() {
    double x1 = c1.x();
    double x2 = c2.x();
    double y1 = c1.y();
    double y2 = c2.y();

    return (y2 - y1) / (x2 - x1);
  }
示例#2
0
 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);
 }
示例#3
0
  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;
  }
示例#4
0
 double distance(XY a, XY b) {
   a = new XY(a);
   a.subtract(b);
   return a.length();
 }
示例#5
0
 public String toString() {
   return "Line from " + c1.toString() + " to " + c2.toString();
 }
示例#6
0
 public Line(XY start, XY end) {
   c1 = start;
   c2 = end;
   hasZ = start.hasZ() && end.hasZ();
 }
示例#7
0
 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);
 }
示例#8
0
 public XY getEnd() {
   if (hasZ) return c2;
   else return c2.ignoreZ();
 }
示例#9
0
 public XY getStart() {
   if (hasZ) return c1;
   else return c1.ignoreZ();
 }
示例#10
0
 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));
 }
示例#11
0
 /** Constructs a circle with the specified properties */
 public Circle(XY p, double radius) {
   this(p.x(), p.y(), radius);
 }