如何不用Windows自带的画椭圆函数画椭圆

解决方案 »

  1.   

    /////////////////////////////////////////////////////////////////////////////
    // Draw a ellipse mid point algorthism
    /////////////////////////////////////////////////////////////////////////////
    void CGraphicsView::midleEllipse(int xCenter, int yCenter, int Rx, int Ry, HDC dc)
    {
    int Rx2 = Rx*Rx;
    int Ry2 = Ry*Ry;
    int twoRx2 = 2*Rx2;
    int twoRy2 = 2*Ry2;
    int p;
    int x=0;
    int y=Ry;
    int px = 0;
    int py = twoRx2*y;
    SetPixel(dc,xCenter+x,yCenter+y,RGB(255,0,0));
    SetPixel(dc,xCenter-x,yCenter+y,RGB(255,0,0));
    SetPixel(dc,xCenter+x,yCenter-y,RGB(255,0,0));
    SetPixel(dc,xCenter-x,yCenter-y,RGB(255,0,0));
    //Region 1
    p = (int)(Ry2-Rx2*Ry+0.25*Rx2);
    while(px<py)
    {
    x++;
    px+=twoRy2;
    if(p<0)
    p+=Ry2+px;
    else
    {
    y--;
    py-=twoRx2;
    p+=Ry2+px-py;
    }
    SetPixel(dc,xCenter+x,yCenter+y,RGB(255,0,0));
    SetPixel(dc,xCenter-x,yCenter+y,RGB(255,0,0));
    SetPixel(dc,xCenter+x,yCenter-y,RGB(255,0,0));
    SetPixel(dc,xCenter-x,yCenter-y,RGB(255,0,0));
    }
    //Region 2
    p = (int)(Ry2*(x+0.5)*(x+0.5)+Rx2*(y-1)*(y-1)-Rx2*Ry2);
    while(y>0)
    {
    y--;
    py-=twoRx2;
    if(p>0)
    p+=Rx2-py;
    else
    {
    x++;
    px+=twoRy2;
    p+=Rx2-py+px;
    }
    SetPixel(dc,xCenter+x,yCenter+y,RGB(255,0,0));
    SetPixel(dc,xCenter-x,yCenter+y,RGB(255,0,0));
    SetPixel(dc,xCenter+x,yCenter-y,RGB(255,0,0));
    SetPixel(dc,xCenter-x,yCenter-y,RGB(255,0,0));
    }}
      

  2.   

    /////////////////////////////////////////////////////////////////////////////
    // Draw a circle
    /////////////////////////////////////////////////////////////////////////////
    void circleMidpoint(int xCenter,int yCenter,int radius,HDC dc)
    {
    int x = 0;
    int y = radius;
    int p=1-radius;
    while(x<y)
    {
    x++;
    if(p<0)
    {
    p+=2*x+1;
    }
    else
    {
    y--;
    p+=2*(x-y)+1;
    }
    SetPixel(dc,xCenter+x,yCenter+y,RGB(255,0,0));
    SetPixel(dc,xCenter-x,yCenter+y,RGB(255,0,0));
    SetPixel(dc,xCenter+x,yCenter-y,RGB(255,0,0));
    SetPixel(dc,xCenter-x,yCenter-y,RGB(255,0,0)); SetPixel(dc,xCenter+y,yCenter+x,RGB(255,0,0));
    SetPixel(dc,xCenter-y,yCenter+x,RGB(255,0,0));
    SetPixel(dc,xCenter+y,yCenter-x,RGB(255,0,0));
    SetPixel(dc,xCenter-y,yCenter-x,RGB(255,0,0));
    }
    }