VOOZH about

URL: https://www.geeksforgeeks.org/dsa/minimum-enclosing-circle/

⇱ Minimum Enclosing Circle - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Minimum Enclosing Circle

Last Updated : 12 Jul, 2025

Prerequisites: Equation of circle when three points on the circle are given, Convex Hull
Given an array arr[][] containing N points in a 2-D plane with integer coordinates. The task is to find the centre and the radius of the minimum enclosing circle(MEC). A minimum enclosing circle is a circle in which all the points lie either inside the circle or on its boundaries.
Examples:

Input: arr[][] = {{0, 0}, {0, 1}, {1, 0}} 
Output: Center = {0.5, 0.5}, Radius = 0.7071 
Explanation:
On plotting the above circle with radius 0.707 and center (0.5, 0.5), it can be observed clearly that all the mentioned points lie either inside or on the circle. 

👁 Image


Input: arr[][] = {{5, -2}, {-3, -2}, {-2, 5}, {1, 6}, {0, 2}} 
Output: Center = {1.0, 1.0}, Radius = 5.000 



Naive Approach: This problem can be solved by making a few observations. 

  • The first observation which can be made is that the MEC intersects at least one point. That's because if the MEC does not intersect at any point, then the circle could be further shrunk until it intersects at one of the points.
  • The second observation which can be made is that given a circle that encloses all the points and intersects at a single point, the circle can further be shrunk by moving the centre towards that point while keeping the point on the circle boundary until the circle intersects one or more additional points.
  • If the circle intersects at two points(A and B) and the distance AB is equal to the circle diameter, then the circle cannot be shrunk anymore. Else, the centre of the circle can be moved towards the midpoint of AB until the circle intersects a third point(at which the circle cannot be shrunk anymore).


From the above observations, it can be concluded that the MEC either: 

  1. Intersects 2 points A and B, where AB = circle diameter. For this case, the circle's centre would be the midpoint of A and B and the radius would be half of the distance AB.
  2. Intersects 3 or more points. The approach to find the center and radius has been discussed in this article.


Thus, the solution to this problem is trivial for N <= 3. For other cases, a simple idea can be formed to solve this problem. The idea is to use all pairs and triples of points to obtain the circle defined those points. After obtaining the circle, test to see if the other points are enclosed by that circle and return the smallest valid circle found.
Below is the implementation of the above approach:


Output
Center = { 0.5, 0.5 } Radius = 0.707107
Center = { 1, 1 } Radius = 5

Time Complexity: The time complexity for this solution would be of O(N4). That's because there are N3 triples of points. And for each triple, we check if all the points are enclosed by the circle.
Approach 2: A solution with the application of convex hull concept can also be used for this problem. The idea is to first form a convex hull on the given set of points. Once the convex hull is performed and the new set of points is returned, then the above-mentioned solution can be used on the new set of points to find the MEC.
The code for this approach would be the same as above except that we would also need to get the convex hull first. Please refer to this article for an efficient algorithm to get the convex hull.
Time Complexity: One observation that needs to be made that if the input already represents some vertices of a convex polygon, then this solution would have the same time complexity of the above naive approach. 
Therefore, the worst-case complexity of this approach is still O(N4).
However, if the number of vertices of the convex hull is considerably smaller than N, then the complexity would be O(H4 + NLog(N)) where H represents the number of vertices of the convex hull, and the NLog(N) factor is for finding the convex hull assuming Graham Scan algorithm is used.
Finally, if the number of vertices, H, of the convex hull, is very small, then it can be considered as a constant factor and thus the time complexity would be O(NLog(N)).

Comment
Article Tags:
Article Tags: