Bresenham中点画圆法与二阶差分算法

void Bresenham(int radius, int r,COLORREF color, CDC* pDC)
{
    int x = 0;
    int y = radius;
    int m = d - radius;
    CirclePoints(x, -y, r, color, pDC);
    CirclePoints(y, -x, r, color, pDC);
    CirclePoints(x, y, r, color, pDC);
    CirclePoints(-y, -x, r, color, pDC);
    while (y > x) {
        if (m < 0) { /* Select E */
            m = 2 * x + 3 * d + m;
        }
        else { /* Select SE */
            m = 2 * (x-y) + 5 * d + m;
            y = y - d;
        }
        x = x + d;
        CirclePoints(x, -y, r, color, pDC);
        CirclePoints(y, -x, r, color, pDC);
        CirclePoints(x, y, r, color, pDC);
        CirclePoints(y, x, r, color, pDC);
        CirclePoints(-x, -y, r, color, pDC);
        CirclePoints(-y, -x, r, color, pDC);
        CirclePoints(-y, x, r, color, pDC);
        CirclePoints(-x, y, r, color, pDC);
    }
}

void dSE(int radius, int r, COLORREF color, CDC* pDC)
{
    int x = 0;
    int y = radius;
    int m = d - radius;
    int dE = 3*d;
    int dSE = -2 * radius + 5*d;
    CirclePoints(x, -y, r, color, pDC);
    CirclePoints(y, -x, r, color, pDC);
    CirclePoints(x, y, r, color, pDC);
    CirclePoints(-y, -x, r, color, pDC);
    while (y > x) {
        if (m < 0) { /* Select E */
            m = dE + m;
            dE = dE + 2 * d;
            dSE = dSE + 2 * d;
        }
        else { /* Select SE */
            m = dSE + m;
            dE = dE + 2 * d;
            dSE = dSE + 4 * d;
            y = y - d;
        }
        x = x + d;
        CirclePoints(x, -y, r , color, pDC);
        CirclePoints(y, -x, r, color, pDC);
        CirclePoints(x, y, r, color, pDC);
        CirclePoints(y, x, r, color, pDC);
        CirclePoints(-x, -y, r, color, pDC);
        CirclePoints(-y, -x, r, color, pDC);
        CirclePoints(-y, x, r, color, pDC);
        CirclePoints(-x, y, r, color, pDC);
    }
}

 

posted @ 2016-06-20 15:45  13070030李晓东  阅读(615)  评论(0编辑  收藏  举报