I have three points on the circumference of a circle:
pt A = (A.x, A.y);
pt B = (B.x, B.y);
pt C = (C.x, C.y);
How do I calculate the cente
I am sorry my answer is late. Any solution using "slope" will fail when two of the points form a vertical line, because the slope will be infinite.
Here is a simple robust solution for 2019 that always works correctly:
public static boolean circleCenter(double[] p1, double[] p2, double[] p3, double[] center) {
double ax = (p1[0] + p2[0]) / 2;
double ay = (p1[1] + p2[1]) / 2;
double ux = (p1[1] - p2[1]);
double uy = (p2[0] - p1[0]);
double bx = (p2[0] + p3[0]) / 2;
double by = (p2[1] + p3[1]) / 2;
double vx = (p2[1] - p3[1]);
double vy = (p3[0] - p2[0]);
double dx = ax - bx;
double dy = ay - by;
double vu = vx * uy - vy * ux;
if (vu == 0)
return false; // Points are collinear, so no unique solution
double g = (dx * uy - dy * ux) / vu;
center[0] = bx + g * vx;
center[1] = by + g * vy;
return true;
}
The above code will return "false" if and only if the 3 points are collinear.