All problems
Minimum Enclosing Circle
Problem
Return the smallest circle enclosing all points as [centre_x, centre_y, radius], or an empty list for no points.
The optimal circle is determined by either one point, a diameter through two points, or the circumcircle of three points, so test every one, two and three point candidate and keep the smallest that contains all points. Return floats.
Hint
Collinear triples have a zero denominator and can be skipped safely.
Test cases
case 1
in: [[[0,0],[2,0],[0,2],[2,2]]]
expected: [1,1,1.4142135623730951]
case 2
in: [[[0,0],[1,0]]]
expected: [0.5,0,0.5]
case 3
in: [[[5,5]]]
expected: [5,5,0]
case 4
in: [[[0,0],[3,0],[0,4]]]
expected: [1.5,2,2.5]
Starter codePython
def min_enclosing_circle(points):
# Your code here
pass4 test cases · run your code against them in the editor