src/dns/dnsConnectionView.js
function CalculateCircleCenter (A, B, C) {
  const aSlope = (B.y - A.y) / (B.x - A.x);
  const bSlope = (C.y - B.y) / (C.x - B.x);

  if (aSlope === 0 || bSlope === 0) {
    // rotate the points about origin to retry and then rotate the answer back.
    // this should avoid div by zero.
    // we could pick any acute angle here and be garuanteed this will take less than three tries.
    // i've discovered a clever proof for this, but I don't have room in the margin.
    const angle = Math.PI / 3;
    return rotate(CalculateCircleCenter(rotate(A, angle), rotate(B, angle), rotate(C, angle)), -1 * angle);
  }

  const center = {};

  center.x = (aSlope * bSlope * (A.y - C.y) + bSlope * (A.x + B.x) - aSlope * (B.x + C.x)) / (2 * (bSlope - aSlope));
  center.y = -1 * (center.x - (A.x + B.x) / 2) / aSlope + (A.y + B.y) / 2;

  return center;
}
function CalculateCircleCenter (A, B, C) {
  const aSlope = (B.y - A.y) / (B.x - A.x);
  const bSlope = (C.y - B.y) / (C.x - B.x);

  if (aSlope === 0 || bSlope === 0) {
    // rotate the points about origin to retry and then rotate the answer back.
    // this should avoid div by zero.
    // we could pick any acute angle here and be garuanteed this will take less than three tries.
    // i've discovered a clever proof for this, but I don't have room in the margin.
    const angle = Math.PI / 3;
    return rotate(CalculateCircleCenter(rotate(A, angle), rotate(B, angle), rotate(C, angle)), -1 * angle);
  }

  const center = {};

  center.x = (aSlope * bSlope * (A.y - C.y) + bSlope * (A.x + B.x) - aSlope * (B.x + C.x)) / (2 * (bSlope - aSlope));
  center.y = -1 * (center.x - (A.x + B.x) / 2) / aSlope + (A.y + B.y) / 2;

  return center;
}
function CalculateCircleCenter ( A , B , C ) { const aSlope = ( B . y - A . y ) / ( B . x - A . x ) ; const bSlope = ( C . y - B . y ) / ( C . x - B . x ) ; if ( aSlope === 0 || bSlope === 0 ) { // rotate the points about origin to retry and then rotate the answer back. // this should avoid div by zero. // we could pick any acute angle here and be garuanteed this will take less than three tries. // i've discovered a clever proof for this, but I don't have room in the margin. const angle = Math . PI / 3 ; return rotate ( CalculateCircleCenter ( rotate ( A , angle ) , rotate ( B , angle ) , rotate ( C , angle ) ) , - 1 * angle ) ; } const center = { } ; center . x = ( aSlope * bSlope * ( A . y - C . y ) + bSlope * ( A . x + B . x ) - aSlope * ( B . x + C . x ) ) / ( 2 * ( bSlope - aSlope ) ) ; center . y = - 1 * ( center . x - ( A . x + B . x ) / 2 ) / aSlope + ( A . y + B . y ) / 2 ; return center ; }
Given three points, A B C, find the center of a circle that goes through all three.
Given three points A B C find the center of a circle that goes through all three .