Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Mathematical Algorithm
  • Mathematical Algorithms
  • Pythagorean Triplet
  • Fibonacci Number
  • Euclidean Algorithm
  • LCM of Array
  • GCD of Array
  • Binomial Coefficient
  • Catalan Numbers
  • Sieve of Eratosthenes
  • Euler Totient Function
  • Modular Exponentiation
  • Modular Multiplicative Inverse
  • Stein's Algorithm
  • Juggler Sequence
  • Chinese Remainder Theorem
  • Quiz on Fibonacci Numbers
Open In App
Next Article:
How to Highlight Groups with Convex Hull in ggplot2 in R?
Next article icon

Minimum Enclosing Circle

Last Updated : 07 Jan, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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. 
 

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:
 

CPP




// C++ program to find the minimum enclosing
// circle for N integer points in a 2-D plane
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
 
// Defining infinity
const double INF = 1e18;
 
// Structure to represent a 2D point
struct Point {
    double X, Y;
};
 
// Structure to represent a 2D circle
struct Circle {
    Point C;
    double R;
};
 
// Function to return the euclidean distance
// between two points
double dist(const Point& a, const Point& b)
{
    return sqrt(pow(a.X - b.X, 2) + pow(a.Y - b.Y, 2));
}
 
// Function to check whether a point lies inside
// or on the boundaries of the circle
bool is_inside(const Circle& c, const Point& p)
{
    return dist(c.C, p) <= c.R;
}
 
 
// The following two functions are the functions used
// To find the equation of the circle when three
// points are given.
 
// Helper method to get a circle defined by 3 points
Point get_circle_center(double bx, double by,
                        double cx, double cy)
{
    double B = bx * bx + by * by;
    double C = cx * cx + cy * cy;
    double D = bx * cy - by * cx;
    return { (cy * B - by * C) / (2 * D),
             (bx * C - cx * B) / (2 * D) };
}
 
// Function to return a unique circle that intersects
// three points
Circle circle_from(const Point& A, const Point& B,
                   const Point& C)
{
    Point I = get_circle_center(B.X - A.X, B.Y - A.Y,
                                C.X - A.X, C.Y - A.Y);
    I.X += A.X;
    I.Y += A.Y;
    return { I, dist(I, A) };
}
 
// Function to return the smallest circle
// that intersects 2 points
Circle circle_from(const Point& A, const Point& B)
{
    // Set the center to be the midpoint of A and B
    Point C = { (A.X + B.X) / 2.0, (A.Y + B.Y) / 2.0 };
 
    // Set the radius to be half the distance AB
    return { C, dist(A, B) / 2.0 };
}
 
// Function to check whether a circle encloses the given points
bool is_valid_circle(const Circle& c, const vector<Point>& P)
{
 
    // Iterating through all the points to check
    // whether the points lie inside the circle or not
    for (const Point& p : P)
        if (!is_inside(c, p))
            return false;
    return true;
}
 
// Function to return find the minimum enclosing
// circle from the given set of points
Circle minimum_enclosing_circle(const vector<Point>& P)
{
 
    // To find the number of points
    int n = (int)P.size();
 
    if (n == 0)
        return { { 0, 0 }, 0 };
    if (n == 1)
        return { P[0], 0 };
 
    // Set initial MEC to have infinity radius
    Circle mec = { { 0, 0 }, INF };
 
    // Go over all pair of points
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
 
            // Get the smallest circle that
            // intersects P[i] and P[j]
            Circle tmp = circle_from(P[i], P[j]);
 
            // Update MEC if tmp encloses all points
            // and has a smaller radius
            if (tmp.R < mec.R && is_valid_circle(tmp, P))
                mec = tmp;
        }
    }
 
    // Go over all triples of points
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
 
                // Get the circle that intersects P[i], P[j], P[k]
                Circle tmp = circle_from(P[i], P[j], P[k]);
 
                // Update MEC if tmp encloses all points
                // and has smaller radius
                if (tmp.R < mec.R && is_valid_circle(tmp, P))
                    mec = tmp;
            }
        }
    }
    return mec;
}
 
// Driver code
int main()
{
 
    Circle mec = minimum_enclosing_circle({ { 0, 0 },
                                            { 0, 1 },
                                            { 1, 0 } });
 
    cout << "Center = { " << mec.C.X << ", " << mec.C.Y
         << " } Radius = " << mec.R << endl;
 
    Circle mec2 = minimum_enclosing_circle({ { 5, -2 },
                                             { -3, -2 },
                                             { -2, 5 },
                                             { 1, 6 },
                                             { 0, 2 } });
 
    cout << "Center = { " << mec2.C.X << ", " << mec2.C.Y
         << " } Radius = " << mec2.R << endl;
 
    return 0;
}
 
 

Java




import java.util.ArrayList;
 
public class Main {
 
    // Defining infinity
    private static final double INF = 1e18;
 
    // Structure to represent a 2D point
    static class Point {
        double X, Y;
 
        Point(double X, double Y) {
            this.X = X;
            this.Y = Y;
        }
    }
 
    // Structure to represent a 2D circle
    static class Circle {
        Point C;
        double R;
 
        Circle(Point C, double R) {
            this.C = C;
            this.R = R;
        }
    }
 
    // Function to return the euclidean distance between two points
    private static double dist(Point a, Point b) {
        return Math.sqrt(Math.pow(a.X - b.X, 2) + Math.pow(a.Y - b.Y, 2));
    }
 
    // Function to check whether a point lies inside or on the boundaries of the circle
    private static boolean isInside(Circle c, Point p) {
        return dist(c.C, p) <= c.R;
    }
 
    // Helper method to get a circle defined by 3 points
    private static Point getCircleCenter(double bx, double by, double cx, double cy) {
        double B = bx * bx + by * by;
        double C = cx * cx + cy * cy;
        double D = bx * cy - by * cx;
        return new Point((cy * B - by * C) / (2 * D), (bx * C - cx * B) / (2 * D));
    }
 
    // Function to return a unique circle that intersects three points
    private static Circle circleFrom(Point A, Point B, Point C) {
        Point I = getCircleCenter(B.X - A.X, B.Y - A.Y, C.X - A.X, C.Y - A.Y);
        I.X += A.X;
        I.Y += A.Y;
        return new Circle(I, dist(I, A));
    }
 
    // Function to return the smallest circle that intersects 2 points
    private static Circle circleFrom(Point A, Point B) {
        // Set the center to be the midpoint of A and B
        Point C = new Point((A.X + B.X) / 2.0, (A.Y + B.Y) / 2.0);
 
        // Set the radius to be half the distance AB
        return new Circle(C, dist(A, B) / 2.0);
    }
 
    // Function to check whether a circle encloses the given points
    private static boolean isValidCircle(Circle c, ArrayList<Point> P) {
        // Iterating through all the points to check whether the points lie inside
        // the circle or not
        for (Point p : P) {
            if (!isInside(c, p)) {
                return false;
            }
        }
        return true;
    }
 
    // Function to find the minimum enclosing circle from the given set of points
    private static Circle minimumEnclosingCircle(ArrayList<Point> P) {
        // To find the number of points
        int n = P.size();
 
        if (n == 0) {
            return new Circle(new Point(0, 0), 0);
        }
        if (n == 1) {
            return new Circle(P.get(0), 0);
        }
 
        // Set initial MEC to have infinity radius
        Circle mec = new Circle(new Point(0, 0), INF);
 
        // Go over all pairs of points
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                // Get the smallest circle that intersects P[i] and P[j]
                Circle tmp = circleFrom(P.get(i), P.get(j));
 
                // Update MEC if tmp encloses all points and has a smaller radius
                if (tmp.R < mec.R && isValidCircle(tmp, P)) {
                    mec = tmp;
                }
            }
        }
 
        // Go over all triples of points
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    // Get the circle that intersects P[i], P[j], P[k]
                    Circle tmp = circleFrom(P.get(i), P.get(j), P.get(k));
 
                    // Update MEC if tmp encloses all points and has a smaller radius
                    if (tmp.R < mec.R && isValidCircle(tmp, P)) {
                        mec = tmp;
                    }
                }
            }
        }
        return mec;
    }
 
    // Driver code
    public static void main(String[] args) {
 
        ArrayList<Point> points1 = new ArrayList<>();
        points1.add(new Point(0, 0));
        points1.add(new Point(0, 1));
        points1.add(new Point(1, 0));
 
        Circle mec1 = minimumEnclosingCircle(points1);
 
        System.out.print("Center = { " + mec1.C.X + ", " + mec1.C.Y);
        System.out.printf(" } Radius = %.6f%n", mec1.R);
        ArrayList<Point> points2 = new ArrayList<>();
        points2.add(new Point(5, -2));
        points2.add(new Point(-3, -2));
        points2.add(new Point(-2, 5));
        points2.add(new Point(1, 6));
        points2.add(new Point(0, 2));
 
        Circle mec2 = minimumEnclosingCircle(points2);
 
        System.out.print("Center = { " + mec2.C.X + ", " + mec2.C.Y);
        System.out.printf(" } Radius = %.0f%n", mec2.R);
    }
}
 
 

Python3




# Python3 program to find the minimum enclosing
# circle for N integer points in a 2-D plane
from math import sqrt
 
# Defining infinity
INF = 10**18
 
# Function to return the euclidean distance
# between two points
def dist(a, b):
    return sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1], 2))
 
# Function to check whether a point lies inside
# or on the boundaries of the circle
def is_inside(c, p):
    return dist(c[0], p) <= c[1]
 
# The following two functions are the functions used
# To find the equation of the circle when three
# points are given.
 
# Helper method to get a circle defined by 3 points
def get_circle_center(bx, by, cx, cy):
    B = bx * bx + by * by
    C = cx * cx + cy * cy
    D = bx * cy - by * cx
    return [(cy * B - by * C) // (2 * D),
            (bx * C - cx * B) // (2 * D) ]
 
# Function to return a unique circle that intersects
# three points
def circle_frOm(A, B,C):
    I = get_circle_center(B[0] - A[0], B[1] - A[1],
                                C[0] - A[0], C[1] - A[1])
    I[0] += A[0]
    I[1] += A[1]
    return [I, dist(I, A)]
 
# Function to return the smallest circle
# that intersects 2 points
def circle_from(A, B):
     
    # Set the center to be the midpoint of A and B
    C = [ (A[0] + B[0]) / 2.0, (A[1] + B[1]) / 2.0]
 
    # Set the radius to be half the distance AB
    return [C, dist(A, B) / 2.0]
 
# Function to check whether a circle encloses the given points
def is_valid_circle(c, P):
 
    # Iterating through all the points to check
    # whether the points lie inside the circle or not
    for p in P:
        if (is_inside(c, p) == False):
            return False
    return True
 
# Function to return find the minimum enclosing
# circle from the given set of points
def minimum_enclosing_circle(P):
 
    # To find the number of points
    n = len(P)
 
    if (n == 0):
        return [[0, 0], 0]
    if (n == 1):
        return [P[0], 0]
 
    # Set initial MEC to have infinity radius
    mec = [[0, 0], INF]
 
    # Go over all pair of points
    for i in range(n):
        for j in range(i + 1, n):
 
            # Get the smallest circle that
            # intersects P[i] and P[j]
            tmp = circle_from(P[i], P[j])
 
            # Update MEC if tmp encloses all points
            # and has a smaller radius
            if (tmp[1] < mec[1] and is_valid_circle(tmp, P)):
                mec = tmp
 
    # Go over all triples of points
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
 
                # Get the circle that intersects P[i], P[j], P[k]
                tmp = circle_frOm(P[i], P[j], P[k])
 
                # Update MEC if tmp encloses all points
                # and has smaller radius
                if (tmp[1] < mec[1] and is_valid_circle(tmp, P)):
                    mec = tmp
 
    return mec
 
# Driver code
 
mec = minimum_enclosing_circle([ [ 0, 0 ],
                                [ 0, 1 ],
                                [ 1, 0 ] ])
 
print("Center = { ",mec[0][1],",",mec[0][1],
                "} Radius = ",round(mec[1],6))
 
mec2 = minimum_enclosing_circle([ [ 5, -2 ],
                                [ -3, -2 ],
                                [ -2, 5 ],
                                [ 1, 6 ],
                                [ 0, 2 ] ])
 
print("Center = {",mec2[0][0],",",mec2[0][1],
        "} Radius = ",mec2[1])
         
# This code is contributed by mohit kumar 29
 
 

C#




using System;
using System.Collections.Generic;
 
public class GFG
{
    // Defining infinity
    private static readonly double INF = 1e18;
 
    // Structure to represent a 2D point
    public class Point
    {
        public double X, Y;
 
        public Point(double X, double Y)
        {
            this.X = X;
            this.Y = Y;
        }
    }
 
    // Structure to represent a 2D circle
    public class Circle
    {
        public Point C;
        public double R;
 
        public Circle(Point C, double R)
        {
            this.C = C;
            this.R = R;
        }
    }
 
    // Function to return the Euclidean distance between two points
    private static double Dist(Point a, Point b)
    {
        return Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
    }
 
    // Function to check whether a point lies inside or on the boundaries of the circle
    private static bool IsInside(Circle c, Point p)
    {
        return Dist(c.C, p) <= c.R;
    }
 
    // Helper method to get a circle defined by 3 points
    private static Point GetCircleCenter(double bx, double by, double cx, double cy)
    {
        double B = bx * bx + by * by;
        double C = cx * cx + cy * cy;
        double D = bx * cy - by * cx;
        return new Point((cy * B - by * C) / (2 * D), (bx * C - cx * B) / (2 * D));
    }
 
    // Function to return a unique circle that intersects three points
    private static Circle CircleFrom(Point A, Point B, Point C)
    {
        Point I = GetCircleCenter(B.X - A.X, B.Y - A.Y, C.X - A.X, C.Y - A.Y);
        I.X += A.X;
        I.Y += A.Y;
        return new Circle(I, Dist(I, A));
    }
 
    // Function to return the smallest circle that intersects 2 points
    private static Circle CircleFrom(Point A, Point B)
    {
        // Set the center to be the midpoint of A and B
        Point C = new Point((A.X + B.X) / 2.0, (A.Y + B.Y) / 2.0);
 
        // Set the radius to be half the distance AB
        return new Circle(C, Dist(A, B) / 2.0);
    }
 
    // Function to check whether a circle encloses the given points
    private static bool IsValidCircle(Circle c, List<Point> P)
    {
        // Iterating through all the points to check whether the points lie inside
        // the circle or not
        foreach (Point p in P)
        {
            if (!IsInside(c, p))
            {
                return false;
            }
        }
        return true;
    }
 
    // Function to find the minimum enclosing circle from the given set of points
    private static Circle MinimumEnclosingCircle(List<Point> P)
    {
        // To find the number of points
        int n = P.Count;
 
        if (n == 0)
        {
            return new Circle(new Point(0, 0), 0);
        }
        if (n == 1)
        {
            return new Circle(P[0], 0);
        }
 
        // Set initial MEC to have infinity radius
        Circle mec = new Circle(new Point(0, 0), INF);
 
        // Go over all pairs of points
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                // Get the smallest circle that intersects P[i] and P[j]
                Circle tmp = CircleFrom(P[i], P[j]);
 
                // Update MEC if tmp encloses all points and has a smaller radius
                if (tmp.R < mec.R && IsValidCircle(tmp, P))
                {
                    mec = tmp;
                }
            }
        }
 
        // Go over all triples of points
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                for (int k = j + 1; k < n; k++)
                {
                    // Get the circle that intersects P[i], P[j], P[k]
                    Circle tmp = CircleFrom(P[i], P[j], P[k]);
 
                    // Update MEC if tmp encloses all points and has a smaller radius
                    if (tmp.R < mec.R && IsValidCircle(tmp, P))
                    {
                        mec = tmp;
                    }
                }
            }
        }
        return mec;
    }
 
    // Driver code
    public static void Main()
    {
        List<Point> points1 = new List<Point>
        {
            new Point(0, 0),
            new Point(0, 1),
            new Point(1, 0)
        };
 
        Circle mec1 = MinimumEnclosingCircle(points1);
 
        Console.Write($"Center = {{ {mec1.C.X}, {mec1.C.Y} }} Radius = {mec1.R:F6}\n");
 
        List<Point> points2 = new List<Point>
        {
            new Point(5, -2),
            new Point(-3, -2),
            new Point(-2, 5),
            new Point(1, 6),
            new Point(0, 2)
        };
 
        Circle mec2 = MinimumEnclosingCircle(points2);
 
        Console.Write($"Center = {{ {mec2.C.X}, {mec2.C.Y} }} Radius = {mec2.R:F0}\n");
    }
}
 
 

Javascript




// JS program to find the minimum enclosing
// circle for N integer points in a 2-D plane
 
 
// Defining infinity
let INF = 1e18;
 
// Structure to represent a 2D point
class Point {
    constructor(a = 0, b = 0)
    {
        this.X = a;
        this.Y = a;
    }
};
 
// Structure to represent a 2D circle
class Circle {
    constructor(a = new Point(0, 0), b = 0)
    {
        this.C = a;
        this.R = b;
    }
};
 
// Function to return the euclidean distance
// between two points
function dist(a,  b)
{
    return Math.sqrt(Math.pow(a.X - b.X, 2) + Math.pow(a.Y - b.Y, 2));
}
 
// Function to check whether a point lies inside
// or on the boundaries of the circle
function is_inside(c, p)
{
    return dist(c.C, p) <= c.R;
}
 
 
// The following two functions are the functions used
// To find the equation of the circle when three
// points are given.
 
// Helper method to get a circle defined by 3 points
function get_circle_center(bx, by, cx, cy)
{
    let B = bx * bx + by * by;
    let C = cx * cx + cy * cy;
    let D = bx * cy - by * cx;
    return [ (cy * B - by * C) / (2 * D),
             (bx * C - cx * B) / (2 * D) ];
}
 
// Function to return a unique circle that intersects
// three points
function circle_from(A, B, C)
{
    let I = get_circle_center(B.X - A.X, B.Y - A.Y,
                                C.X - A.X, C.Y - A.Y);
    I.X += A.X;
    I.Y += A.Y;
    return [ I, dist(I, A) ];
}
 
// Function to return the smallest circle
// that intersects 2 points
function circle_from(A, B)
{
    // Set the center to be the midpoint of A and B
    let C = new Point((A.X + B.X) / 2.0, (A.Y + B.Y) / 2.0);
 
    // Set the radius to be half the distance AB
    return new Circle(C, dist(A, B) / 2.0);
}
 
// Function to check whether a circle encloses the given points
function is_valid_circle(c, P)
{
 
    // Iterating through all the points to check
    // whether the points lie inside the circle or not
    for (var p of P)
        if (!is_inside(c, p))
            return false;
    return true;
}
 
// Function to return find the minimum enclosing
// circle from the given set of points
function minimum_enclosing_circle(P)
{
 
    // To find the number of points
    let n = P.length;
 
    if (n == 0)
        return  new Circle();
    if (n == 1)
        return [P[0], 0 ];
 
    // Set initial MEC to have infinity radius
    let mec = new Circle(new Point(0, 0), INF );
 
    // Go over all pair of points
    for (var i = 0; i < n; i++) {
        for (var j = i + 1; j < n; j++) {
 
            // Get the smallest circle that
            // intersects P[i] and P[j]
            let tmp = circle_from(P[i], P[j]);
 
            // Update MEC if tmp encloses all points
            // and has a smaller radius
            if (tmp.R < mec.R && is_valid_circle(tmp, P))
                mec = tmp;
        }
    }
 
    // Go over all triples of points
    for (var i = 0; i < n; i++) {
        for (var j = i + 1; j < n; j++) {
            for (var k = j + 1; k < n; k++) {
 
                // Get the circle that intersects P[i], P[j], P[k]
                let tmp = circle_from(P[i], P[j], P[k]);
 
                // Update MEC if tmp encloses all points
                // and has smaller radius
                if (tmp.R < mec.R && is_valid_circle(tmp, P))
                    mec = tmp;
            }
        }
    }
    return mec;
}
 
// Driver code
let mec = minimum_enclosing_circle([ new Point( 0, 0 ), new Point( 0, 1 ), new Point( 1, 0 )]);
 
console.log("Center = { " + mec.C.X + ", " + mec.C.Y
         + " } Radius = " + mec.R);
 
let mec2 = minimum_enclosing_circle([ new Point( 5, -2), new Point(-3, -2), new Point(-2, 5),  new Point( 1, 6),  new Point( 0, 2)]);
 
console.log("Center = { " + mec2.C.X + ", " + mec2.C.Y
         + " } Radius = " + mec2.R);
 
 
// This code is contributed by phasing17
 
 
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)).
 



Next Article
How to Highlight Groups with Convex Hull in ggplot2 in R?

M

marwan tammam
Improve
Article Tags :
  • Algorithms
  • Competitive Programming
  • DSA
  • Geometric
  • Mathematical
  • circle
Practice Tags :
  • Algorithms
  • Geometric
  • Mathematical

Similar Reads

  • Convex Hull Algorithm
    The Convex Hull Algorithm is used to find the convex hull of a set of points in computational geometry. The convex hull is the smallest convex set that encloses all the points, forming a convex polygon. This algorithm is important in various applications such as image processing, route planning, and
    8 min read
  • Convex Hull using Divide and Conquer Algorithm
    In computational geometry, a convex hull is the smallest convex polygon that contains a given set of points. It is a fundamental concept with applications in various fields such as computer graphics, robotics, and image processing. Importance of Convex Hull:Convex hulls are important in computationa
    15 min read
  • Convex Hull using Jarvis' Algorithm or Wrapping
    Given a set of points in the plane. the convex hull of the set is the smallest convex polygon that contains all the points of it. We strongly recommend to see the following post first. How to check if two given line segments intersect?The idea of Jarvis's Algorithm is simple, we start from the leftm
    14 min read
  • Convex Hull using Graham Scan
    A convex hull is the smallest convex polygon that contains a given set of points. It is a useful concept in computational geometry and has applications in various fields such as computer graphics, image processing, and collision detection. A convex polygon is a polygon in which all interior angles a
    15+ min read
  • Convex Hull | Monotone chain algorithm
    Given a set of points, the task is to find the convex hull of the given points. The convex hull is the smallest convex polygon that contains all the points. Please check this article first: Convex Hull | Set 1 (Jarvis’s Algorithm or Wrapping) Examples: Input: Points[] = {{0, 3}, {2, 2}, {1, 1}, {2,
    12 min read
  • Quickhull Algorithm for Convex Hull
    Given a set of points, a Convex hull is the smallest convex polygon containing all the given points. Input : points[] = {{0, 3}, {1, 1}, {2, 2}, {4, 4}, {0, 0}, {1, 2}, {3, 1}, {3, 3}};Output : The points in convex hull are: (0, 0) (0, 3) (3, 1) (4, 4)Input : points[] = {{0, 3}, {1, 1}Output : Not P
    14 min read
  • Problems on Convex Hull

    • Dynamic Convex hull | Adding Points to an Existing Convex Hull
      Given a convex hull, we need to add a given number of points to the convex hull and print the convex hull after every point addition. The points should be in anti-clockwise order after addition of every point. Examples: Input : Convex Hull : (0, 0), (3, -1), (4, 5), (-1, 4) Point to add : (100, 100)
      15 min read

    • Deleting points from Convex Hull
      Given a fixed set of points. We need to find convex hull of given set. We also need to find convex hull when a point is removed from the set. Example: Initial Set of Points: (-2, 8) (-1, 2) (0, 1) (1, 0) (-3, 0) (-1, -9) (2, -6) (3, 0) (5, 3) (2, 5) Initial convex hull:- (-2, 8) (-3, 0) (-1, -9) (2,
      15+ min read

    • Perimeter of Convex hull for a given set of points
      Given n 2-D points points[], the task is to find the perimeter of the convex hull for the set of points. A convex hull for a set of points is the smallest convex polygon that contains all the points. Examples: Input: points[] = {{0, 3}, {2, 2}, {1, 1}, {2, 1}, {3, 0}, {0, 0}, {3, 3}} Output: 12 Inpu
      10 min read

    • Check if the given point lies inside given N points of a Convex Polygon
      Given coordinates of the N points of a Convex Polygon. The task is to check if the given point (X, Y) lies inside the polygon. Examples: Input: N = 7, Points: {(1, 1), (2, 1), (3, 1), (4, 1), (4, 2), (4, 3), (4, 4)}, Query: X = 3, Y = 2 Below is the image of plotting of the given points: Output: YES
      15 min read

    • Tangents between two Convex Polygons
      Given two convex polygons, we aim to identify the lower and upper tangents connecting them. As shown in the figure below, TRL and TLR represent the upper and lower tangents, respectively. Examples: Input: First Polygon : [[2, 2], [3, 3], [5, 2], [4, 0], [3, 1]] Second Polygon : [[-1, 0], [0, 1], [1,
      15+ min read

    • Check if given polygon is a convex polygon or not
      Given a 2D array point[][] with each row of the form {X, Y}, representing the co-ordinates of a polygon in either clockwise or counterclockwise sequence, the task is to check if the polygon is a convex polygon or not. If found to be true, then print "Yes" . Otherwise, print "No". In a convex polygon
      9 min read

    • Check whether two convex regular polygon have same center or not
      Given two positive integers N and M which denotes the sides of the convex regular polygon where N < M, the task is to check whether polygons have the same center or not if N-sided polygon was inscribed in an M-sided polygon.Center of Polygon: Point inside a polygon which is equidistant from each
      3 min read

    • Minimum Enclosing Circle
      Prerequisites: Equation of circle when three points on the circle are given, Convex HullGiven 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 wh
      15+ min read

  • How to Highlight Groups with Convex Hull in ggplot2 in R?
    In this article, we are going to see how to highlight groups with the convex hull in ggplot2 using R Programming Language.  Convex hull polygon refers to the draw a line bounding box around the outermost points in each group. Creating scatterplot for demonstration Here we will use the iris dataset t
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences