This page is adapted the algorithm from a book Computational Geometry - Algorithms and Applications, 3rd Ed by Berg et. al. You can see details in chapter 4.7 Smallest Enclosing Discs. For more information you can refer to: wiki/Smallest-circle_problem

Run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
////////////////////// Smallest Disk Functions  //////////////////////////
function miniDisc(points){
    var ps = shuffle(points);
    var lastCircle = getCenterAndRadius2(ps[0].pos, ps[1].pos);
 
    for(i=2; i<ps.length; i++)
        if(inCircle(lastCircle.center, lastCircle.radius, ps[i].pos) > 0)
            lastCircle = miniDiscWithPoint(ps.slice(0, i), ps[i])
 
    return lastCircle;
}
 
function miniDiscWithPoint(points, q){
    var ps = shuffle(points);
    var lastCircle = getCenterAndRadius2(ps[0].pos, q.pos);
 
    for(j=1; j<ps.length; j++)
        if(inCircle(lastCircle.center, lastCircle.radius, ps[j].pos) > 0)
            lastCircle = miniDiscWitTwoPoints(ps.slice(0, j), ps[j], q)
 
    return lastCircle;
}
 
function miniDiscWitTwoPoints(points, q1, q2){
    var lastCircle = getCenterAndRadius2(q1.pos, q2.pos);
 
    for(k=0; k<points.length; k++)
        if(inCircle(lastCircle.center, lastCircle.radius, points[k].pos) > 0)
            lastCircle = getCenterAndRadius3(q1.pos, q2.pos, points[k].pos);
 
    return lastCircle;
}
 
 
var points = Points.createRandom(5);
drawCircle(miniDisc(points));