The problem:
Given a non-empty set of points in the Cartesian plane, find the smallest circle that encloses them all (Wikipedia link).
This problem is trivial if the number of points is three or less (if there's one point, the circle has a radius of zero; if there are two points, the line segment that joins the points is the diameter of the circle; if there are three (non-colinear) points, it's possible to get the equation of a circle that touches them all if they form a non-obtuse triangle, or a circle that touches only two points and encloses the third if the triangle is obtuse). So, for the sake of this challenge, the number of points should be greater than three.
The challenge:
- Input: A list of 4 or more non-colinear points. The points should have X and Y coordinates; coordinates can be floats. To ease the challenge, no two points should share the same X coordinate.
For example:[(0,0), (2,1), (5,3), (-1,-1)]
- Output: A tuple of values,
(h,k,r)
, such that \$(x-h)^2 + (y-k)^2 = r^2\$ is the equation of the smallest circle that encloses all points.
Rules:
- You can choose whatever input method suits your program.
- Output should be printed to
STDOUT
or returned by a function. - "Normal", general-purpose, languages are preferred, but any esolang is acceptable.
- You can assume that the points are not colinear.
- This is code-golf, so the smallest program in bytes wins. The winner will be selected one week after the challenge is posted.
- Please include the language you used and the length in bytes as header in the first line of your answer:
# Language: n bytes
- Please include the language you used and the length in bytes as header in the first line of your answer:
Test cases:
- 1:
- Input:
[(-8,0), (3,1), (-6.2,-8), (3,9.5)]
- Output:
[-1.6, 0.75, 9.89]
- Input:
- 2:
- Input:
[(7.1,-6.9), (-7,-9), (5,10), (-9.5,-8)]
- Output:
[-1.73, 0.58, 11.58]
- Input:
- 3:
- Input:
[(0,0), (1,2), (3,-4), (4,-5), (10,-10)]
- Output:
[5.5, -4, 7.5]
- Input:
- 4:
- Input:
[(6,6), (-6,7), (-7,-6), (6,-8)]
- Output:
[0, -0.5, 9.60]
- Input:
Happy golfing!!!