inCentreStatic static method

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

Computes the incentre of a triangle. The inCentre of a triangle is the point which is equidistant from the sides of the triangle. It is also the point at which the bisectors of the triangle's angles meet. It is the centre of the triangle's incircle, which is the unique circle that is tangent to each of the triangle's three sides.

The incentre always lies within the triangle.

@param a a vertex of the triangle @param b a vertex of the triangle @param c a vertex of the triangle @return the point which is the incentre of the triangle

Implementation

static Coordinate inCentreStatic(Coordinate a, Coordinate b, Coordinate c) {
  // the lengths of the sides, labelled by their opposite vertex
  double len0 = b.distance(c);
  double len1 = a.distance(c);
  double len2 = a.distance(b);
  double circum = len0 + len1 + len2;

  double inCentreX = (len0 * a.x + len1 * b.x + len2 * c.x) / circum;
  double inCentreY = (len0 * a.y + len1 * b.y + len2 * c.y) / circum;
  return new Coordinate(inCentreX, inCentreY);
}