circumcentreStatic static method

Coordinate circumcentreStatic(
  1. Coordinate a,
  2. Coordinate b,
  3. Coordinate c
)

Computes the circumcentre of a triangle. The circumcentre is the centre of the circumcircle, the smallest circle which encloses the triangle. It is also the common intersection point of the perpendicular bisectors of the sides of the triangle, and is the only point which has equal distance to all three vertices of the triangle.

The circumcentre does not necessarily lie within the triangle. For example, the circumcentre of an obtuse isosceles triangle lies outside the triangle.

This method uses an algorithm due to J.R.Shewchuk which uses normalization to the origin to improve the accuracy of computation. (See Lecture Notes on Geometric Robustness, Jonathan Richard Shewchuk, 1999).

@param a a vertex of the triangle @param b a vertex of the triangle @param c a vertex of the triangle @return the circumcentre of the triangle

Implementation

static Coordinate circumcentreStatic(
    Coordinate a, Coordinate b, Coordinate c) {
  double cx = c.x;
  double cy = c.y;
  double ax = a.x - cx;
  double ay = a.y - cy;
  double bx = b.x - cx;
  double by = b.y - cy;

  double denom = 2 * det(ax, ay, bx, by);
  double numx = det(ay, ax * ax + ay * ay, by, bx * bx + by * by);
  double numy = det(ax, ax * ax + ay * ay, bx, bx * bx + by * by);

  double ccx = cx - numx / denom;
  double ccy = cy + numy / denom;

  return new Coordinate(ccx, ccy);
}