circumcenter method

Point circumcenter(
  1. int t
)

Returns the circumcenter of triangle t.

Implementation

Point circumcenter(int t) {
  final i0 = triangleIndices[t * 3];
  final i1 = triangleIndices[t * 3 + 1];
  final i2 = triangleIndices[t * 3 + 2];

  final ax = coords[i0 * 2], ay = coords[i0 * 2 + 1];
  final bx = coords[i1 * 2], by = coords[i1 * 2 + 1];
  final cx = coords[i2 * 2], cy = coords[i2 * 2 + 1];

  final dx = bx - ax, dy = by - ay;
  final ex = cx - ax, ey = cy - ay;

  final bl = dx * dx + dy * dy;
  final cl = ex * ex + ey * ey;
  final d = 0.5 / (dx * ey - dy * ex);

  final x = ax + (ey * bl - dy * cl) * d;
  final y = ay + (dx * cl - ex * bl) * d;

  return Point(x, y);
}