This repository has been created using the cradle cli.
We compute the smallest enclosing circle/ball for a set of points.
# create a numpy array where each row corresponds to a point
# Each row should have the same number of elements and they
# can be higher than 2... :-)
points = np.array([[2.0, 4.0], [0, 0], [2.5, 2.0]])
circle = min_circle_cvx(points, solver="CLARABEL")
# display the points & the circle
fig = create_figure()
fig.add_trace(circle.scatter())
fig.add_trace(Cloud(points).scatter())
fig.show()
We are solving the convex optimization problem:
subject to the constraint that for each point
Where:
-
$p_i$ are the points in$\mathbb{R}^d$ . -
$\text{center}$ is the center of the circle we are trying to find. -
$r$ is the radius of the circle.
The goal is to minimize the radius
The constraint
If we define the distance from the center to each point as:
Then, the radius
Thus, the optimization problem becomes:
This is a min-max problem, where we want to
minimize the maximum distance from the center to any of the points.
In other words, we are looking for the smallest possible radius
Geometrically, the problem is about finding the smallest enclosing circle (or ball in higher dimensions) that contains all the given points. The center of the circle is positioned in such a way that the radius is minimized, but all points still lie inside or on the boundary of the circle.
-
Convexity: The objective function
$r = \min \max_i d_i$ is convex, as the maximum of a set of convex functions is convex. Minimizing a convex function over a convex set is a convex optimization problem. -
Center and Radius: The solution involves determining both the center and the radius of the circle. The optimal center minimizes the maximum distance to any of the points, and the optimal radius ensures all points are inside or on the boundary of the circle.