圆和椭圆的扫描转换

c/c++ code
voidCMy1400801119View::OnDraw(CDC* pDC)
{
  CMy1400801119Doc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  // TODO: add draw code for native data here
  int R=100;
  int x0=0,y0=R;
  int x,y,e;
  e=1-R;
  x=x0;
  y=y0;
  while(y>=x){
     pDC->SetPixel(x+300,y+300,RGB(20,180,29));
     pDC->SetPixel(x+300,-y+300,RGB(20,180,29));
     pDC->SetPixel(-x+300,y+300,RGB(20,180,29));
     pDC->SetPixel(-x+300,-y+300,RGB(20,180,29));
     pDC->SetPixel(y+300,x+300,RGB(20,180,29));
     pDC->SetPixel(y+300,-x+300,RGB(20,180,29));
     pDC->SetPixel(-y+300,x+300,RGB(20,180,29));
     pDC->SetPixel(-y+300,-x+300,RGB(20,180,29));
     if(e<0){
       e=e+2*x+3;
       x=x+1;
     }
     else{
       e=e+2*(x-y)+5;
       x=x+1;
       y=y-1;
     }
  }
  float RR=100;
  float xx0=0,yy0=RR;
  float xx,yy;
  xx=xx0;
  yy=yy0;
  float a2=150*150,b=100,b2=100*100;floatee1,ee2;
  ee1=b2+a2*(-b+0.25);
  while(b2*(xx+1)<a2*(yy-0.5)){
     pDC->SetPixel(xx+600,yy+300,RGB(20,180,29));
     pDC->SetPixel(xx+600,-yy+300,RGB(20,180,29));
     pDC->SetPixel(-xx+600,yy+300,RGB(20,180,29));
     pDC->SetPixel(-xx+600,-yy+300,RGB(20,180,29));
     if(ee1<0){
       ee1=ee1+b2*(2*xx+3);
       xx=xx+1;
     }
     else{
       ee1=ee1+b2*(2*xx+3)+a2*(-2*yy+2);
       xx=xx+1;
       yy=yy-1;
     }
  }
  ee2=b2*(xx+0.5)*(xx+0.5)+a2*(yy-1)*(yy-1)-a2*b2;
  while(yy>=0){
     pDC->SetPixel(xx+600,yy+300,RGB(20,180,29));
     pDC->SetPixel(xx+600,-yy+300,RGB(20,180,29));
     pDC->SetPixel(-xx+600,yy+300,RGB(20,180,29));
     pDC->SetPixel(-xx+600,-yy+300,RGB(20,180,29));
     if(ee2<0){
       ee2=ee2+b2*(2*xx+2)+a2*(-2*yy+3);
       xx=xx+1;
       yy=yy-1;
     }
     else{
       ee2=ee2+a2*(-2*yy+3);
       yy=yy-1;
     }
  }
 
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值