public static Circle MakeCircumcircle(CustomPoint a, CustomPoint b, CustomPoint c) { // Mathematical algorithm from Wikipedia: Circumscribed circle double ox = (Math.Min(Math.Min(a.x, b.x), c.x) + Math.Max(Math.Min(a.x, b.x), c.x)) / 2; double oy = (Math.Min(Math.Min(a.y, b.y), c.y) + Math.Max(Math.Min(a.y, b.y), c.y)) / 2; double ax = a.x - ox, ay = a.y - oy; double bx = b.x - ox, by = b.y - oy; double cx = c.x - ox, cy = c.y - oy; double d = (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) * 2; if (d == 0) { return(Circle.INVALID); } double x = ((ax * ax + ay * ay) * (by - cy) + (bx * bx + by * by) * (cy - ay) + (cx * cx + cy * cy) * (ay - by)) / d; double y = ((ax * ax + ay * ay) * (cx - bx) + (bx * bx + by * by) * (ax - cx) + (cx * cx + cy * cy) * (bx - ax)) / d; CustomPoint p = new CustomPoint(ox + x, oy + y); double r = Math.Max(Math.Max(p.Distance(a), p.Distance(b)), p.Distance(c)); return(new Circle(p, r)); }
public bool Contains(CustomPoint p) { return(c.Distance(p) <= r * MULTIPLICATIVE_EPSILON); }
public static Circle MakeDiameter(CustomPoint a, CustomPoint b) { CustomPoint c = new CustomPoint((a.x + b.x) / 2, (a.y + b.y) / 2); return(new Circle(c, Math.Max(c.Distance(a), c.Distance(b)))); }