private Circle findSec(int n, MyPoint[] p, int m, MyPoint[] b)
        {
            Circle sec = new Circle();

            // Compute the Smallest Enclosing Circle defined by B
            if (m == 1)
            {
                sec = new Circle(b[0]);
            }
            else if (m == 2)
            {
                sec = new Circle(b[0], b[1]);
            }
            else if (m == 3)
            {
                return new Circle(b[0], b[1], b[2]);
            }

            // Check if all the MyMyPoints in p are enclosed
            for (int i = 0; i < n; i++)
            {
                //if the MyMyPoint is outside the circle
                if (sec.belongsToCircle(p[i]) == -1)
                {
                    // Compute B <--- B union P[i].
                    b[m] = new MyPoint(p[i].getX(), p[i].getY());
                    // Recurse
                    sec = findSec(i, p, m + 1, b);
                }
            }

            return sec;
        }
        public Circle(MyPoint p1, MyPoint p2, MyPoint p3)
        {
            try
            {
                double x = (p3.getX() * p3.getX() * (p1.getY() - p2.getY()) + (p1.getX() * p1.getX() + (p1.getY() - p2.getY()) * (p1.getY() - p3.getY()))
                          * (p2.getY() - p3.getY()) + p2.getX() * p2.getX() * (-p1.getY() + p3.getY()))
                          / (2 * (p3.getX() * (p1.getY() - p2.getY()) + p1.getX() * (p2.getY() - p3.getY()) + p2.getX() * (-p1.getY() + p3.getY())));
                double y = (p2.getY() + p3.getY()) / 2 - (p3.getX() - p2.getX()) / (p3.getY() - p2.getY()) * (x - (p2.getX() + p3.getX()) / 2);

                Center = new MyPoint(x, y);
                radius = Center.distance(p1);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error creating circle with three MyPoints: " + e.ToString());
            }
        }
 private void MainDrawingArea_MouseClick(object sender, MouseEventArgs e)
 {
     g.DrawArc(new Pen(Color.Red), (float)e.X, (float)e.Y, (float)4.0, (float)4.0, (float)0.0, (float)360.0);
     p[n++] = new MyPoint(e.X, e.Y);
     sec = findSec(n, p, 0, b);
     using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"Log.txt", true))
     {
         file.WriteLine("Num MyMyPoints: {0}", n);
         for (int i = 0; i < n; i++)
         {
             string formatString = String.Format("Center {0} {1} MyPoint {2} {3} Radius: {4} Distance: {5}",
                 sec.getCenter().getX(), sec.getCenter().getY(), p[i].getX(), p[i].getY(), sec.getRadius(), sec.getCenter().distance(p[i]));
             file.WriteLine(formatString);
         }
         file.WriteLine("");
     }
     if (n > 1)
     {
         try
         {
             MyPoint center = sec.getCenter();
             int r = (int) sec.getRadius();
             if (prev_height > 0)
             {
                 g.DrawArc(new Pen(Color.White), (float)prev_x, (float)prev_y, (float)prev_width, (float)prev_height, 0, 360);
             }
             double x = center.getX() - r; prev_x = x;
             double y = center.getY() - r; prev_y = y;
             double width = 2 * r; prev_width = width;
             int height = 2 * r; prev_height = height;
             g.DrawArc(new Pen(Color.Blue), (float)x, (float)y, (float)width, (float)height, 0, 360);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
     }
 }
 public Circle(MyPoint first, MyPoint second)
 {
     Center = new MyPoint((first.getX() + second.getX()) / 2, (first.getY() + second.getY()) / 2);
     radius = Center.distance(first);
 }
 public Circle(MyPoint Center)
 {
     this.Center = Center;
     this.radius = 0;
 }
 // Construct a MyPoint with the same location as the specified MyPoint
 public MyPoint(MyPoint MyPoint)
 {
     x = MyPoint.x;
     y = MyPoint.y;
 }
 // Determine whether two MyPoints are equal
 public bool equals(MyPoint MyPoint)
 {
     return (x == MyPoint.x) && (y == MyPoint.y);
 }
 // Calcualte the distance between two MyPoints
 public double distance(MyPoint MyPoint)
 {
     double dx = x - MyPoint.x;
     double dy = y - MyPoint.y;
     return Math.Sqrt(dx * dx + dy * dy);
 }
 public Circle(MyPoint first, MyPoint second)
 {
     Center = new MyPoint((first.getX() + second.getX()) / 2, (first.getY() + second.getY()) / 2);
     radius = Center.distance(first);
 }
 public Circle(MyPoint Center, double radius)
 {
     this.Center = Center;
     this.radius = radius;
 }
 public Circle(MyPoint Center)
 {
     this.Center = Center;
     this.radius = 0;
 }
 /*  public static double GetDistance(MyPoint first, MyPoint second)
 {
     return Math.Sqrt((first.X - second.X) * (first.X - second.X) + (first.Y - second.Y) * (first.Y - second.Y));
 }
 */
 public Circle()
 {
     this.Center = new MyPoint(0, 0);
     radius = 0;
 }
 // Calculate the middle MyPoint between two MyPoints
 public MyPoint midMyPoint(MyPoint MyPoint)
 {
     return(new MyPoint((x + MyPoint.x) / 2, (y + MyPoint.y) / 2));
 }
 // Translate a MyPoint to the specified location
 public void translate(MyPoint MyPoint)
 {
     translate(MyPoint.x, MyPoint.y);
 }
 // Translate a MyPoint to the specified location
 public void translate(MyPoint MyPoint)
 {
     translate(MyPoint.x, MyPoint.y);
 }
 public int belongsToCircle(MyPoint other)
 {
     if ((Center.distance(other) - radius) < 0.000001) return 0;
     if (Center.distance(other) > radius) return -1;
     return 1;
 }
 // Construct a MyPoint with the same location as the specified MyPoint
 public MyPoint(MyPoint MyPoint)
 {
     x = MyPoint.x;
     y = MyPoint.y;
 }
 /*  public static double GetDistance(MyPoint first, MyPoint second)
  * {
  *    return Math.Sqrt((first.X - second.X) * (first.X - second.X) + (first.Y - second.Y) * (first.Y - second.Y));
  * }
  */
 public Circle()
 {
     this.Center = new MyPoint(0, 0);
     radius      = 0;
 }
 // Calcualte the square of the distance between two MyPoints
 public double distance2(MyPoint MyPoint)
 {
     double dx = x - MyPoint.x;
     double dy = y - MyPoint.y;
     return (dx * dx + dy * dy);
 }
 public Circle(MyPoint Center, double radius)
 {
     this.Center = Center;
     this.radius = radius;
 }
 // Calculate the middle MyPoint between two MyPoints
 public MyPoint midMyPoint(MyPoint MyPoint)
 {
     return new MyPoint((x + MyPoint.x) / 2, (y + MyPoint.y) / 2);
 }
 // Determine whether two MyPoints are equal
 public bool equals(MyPoint MyPoint)
 {
     return((x == MyPoint.x) && (y == MyPoint.y));
 }