예제 #1
0
  /**
   * Computes the center of the circumscribed circle of the three input points.
   *
   * @throws ColinearPoints2DException if the 3 points are colinear
   */
  public static Point2D circumCenter(Point2D p1, Point2D p2, Point2D p3) {
    if (Point2D.isColinear(p1, p2, p3)) throw new ColinearPoints2DException(p1, p2, p3);

    // create two median lines
    StraightLine2D line12 = StraightLine2D.createMedian(p1, p2);
    StraightLine2D line23 = StraightLine2D.createMedian(p2, p3);

    // check medians are not parallel
    assert !AbstractLine2D.isParallel(line12, line23)
        : "If points are not colinear, medians should not be parallel";

    // Compute intersection of the medians, and circle radius
    Point2D center = AbstractLine2D.getIntersection(line12, line23);

    // return the center
    return center;
  }