本文介绍一种圆形的辨认计划。

辨认流程
  1. 判断是否为关闭图形;
  2. 依据圆的方程,取输出点集中的1/6、3/6、5/6处的三个点,求得圆的方程,获取圆心及半径;
  3. 取点集中的局部点,计算点到圆心的间隔与半径的比例,与设定的阈值比拟,得出后果。~~~~
实现
public static bool IsCircle(List<Point> points, out Point center, out double radius){    int len = points.Count;    center = new Point();    radius = 0;    // 判断是否为关闭图形    if (!IsClosedFigure(points))        return false;    int judgePointNum = len * 50 / 100;    if (len < judgePointNum)        return false;    // 取链表上三个点作为判断圆的依据    Point p1 = points[len / 6];    Point p2 = points[len / 2];    Point p3 = points[len * 5 / 6];    if ((Math.Abs(p1.X - p2.X) < 100 && Math.Abs(p1.Y - p2.Y) < 100)        || (Math.Abs(p1.X - p3.X) < 100 && Math.Abs(p1.Y - p3.Y) < 100)        || (Math.Abs(p2.X - p3.X) < 100 && Math.Abs(p2.Y - p3.Y) < 100))        return false;    // 三个点确定圆的方程,获取圆心坐标及半径    GetCircle(p1, p2, p3, out center, out radius);    // 获取圆上均匀分部的多个点,判断其到圆心的间隔与半径之差是否在精度内    for (int i = 0; i < judgePointNum; ++i)    {        // 获取圆上点        Point p = points[len * i / judgePointNum];        double deviation = Math.Abs(GetDistance(center, p) - radius);        // 点在圆上的偏移量与半径的比值若大于固定值,则不为圆        if (deviation/radius > MaxRatio)            return false;    }    return true;}