Examples

Problem: Find the smallest enclosing circle of a planar set of points

G# uses a randomized incremental algorithm to compute the smallest circle that encloses a planar set of points. With an expected running time of O(n), it is very fast.

Solution using G#

  1. public static void Minidisk()
  2. {
  3.     SmallestEnclosingCircle miniDisk = new SmallestEnclosingCircle();
  4.     miniDisk.InitialPoints = SamplePoints.RandomInRectangle(100, 1, 1);
  5.  
  6.     //Compute the smallest enclosing circle
  7.     Circle smallestEnclosingCircle = miniDisk.ComputeCircle();
  8.  
  9.     //Visualize
  10.     Scene sc = new Scene();
  11.     sc.PointSize = 0.01;
  12.     Scene.Layer cLayer = new Scene.Layer("miniDisk", 1);
  13.     Scene.Layer pLayer = new Scene.Layer("points", 3);
  14.     sc.Add(smallestEnclosingCircle, cLayer);
  15.     sc.Add(miniDisk.InitialPoints, pLayer);
  16.     sc.WriteDxf(@"c:\minidisk.dxf");
  17. }
  18.  

Output

Smallest enclosing circle (red) and corresponding points (green).

<<back