日期:2014-05-17 浏览次数:21013 次
 List<int> x = new List<int>();
            List<int> y = new List<int>(); 
            if (mypoints.Count > 0)
            {
                foreach (Point p in mypoints)
                {
                    x.Add(p.X);
                    y.Add(p.Y);
                }
            }
            x.Sort();
            y.Sort();
            Point pcontent = new Point(x[x.Count / 2],y[y.Count / 2]);
            int radius = (x[x.Count - 1] - x[1]) / 2;
                using (Graphics g = this.CreateGraphics())
                {
                    Pen mypen = new Pen(Color.Black);
                    g.DrawEllipse(mypen,new Rectangle(pcontent.X - radius,pcontent.Y - radius,radius * 2,radius * 2));
                }
------解决方案--------------------
上面是算法图像说明:
1,根据你得到的圆周上的点,先找出他们的最小外接矩形,如红色矩形所示;
2,根据红色矩形,可以得出圆心所在的范围,可以设定一个阈值,这个范围,如黄色矩形所示;
3,遍历黄色区域的每一个像素,计算该像素位置与每个圆周点位置的距离之和Sum;
4,当Sum最小时的那个像素点的位置,就是你要找的圆心位置;
5,如果你有几个点的误差,那么求和之后完全不影响结果,而黄色区域的选择则是为了减少计算量!!
------解决方案--------------------