编程时.I.J是圆弧起点到圆心的差值,怎样算出差值是正是正负
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/02 16:37:30
编程时.I.J是圆弧起点到圆心的差值,怎样算出差值是正是正负
编程时.I.J是圆弧起点到圆心的差值,怎样算出差值是正是正负
编程时.I.J是圆弧起点到圆心的差值,怎样算出差值是正是正负
void RoundBre(int x1,int y1,int R,CDC pDC)
{
//圆心(x1,y1),当前像素I(xi,yi),右像素H(xi+1,y),右下像素D(xi+1,yi-1),下像素V(xi,yi-1)
int xi,yi,dd,m,n;
//圆心距差值平方dh=(xi+1)*(xi+1)+yi*yi-R*R; dd=(xi+1)*(xi+1)+(yi-1)*(yi-1)-R*R; dv=xi*xi+(yi-1)*(yi-1)-R*R;
xi=0; //起点(0,R)
yi=R;
dd=2-2*R; //起点的右下像素(1,R-1)的圆心距差值dd=1+(R-1)*(R-1)-R*R
pDC.SetPixel(x1,y1,RGB(0,0,255)); //画圆心,证明圆心必须占用一个像素
while(yi>=xi) //循环到八分之一圆;yi>=0即可以画出四分圆
{
pDC.SetPixel(xi+x1,yi+y1,RGB(255,0,0)); //2区,坐标平移(x1,y1)画圆
pDC.SetPixel(yi+x1,xi+y1,RGB(255,0,0)); //1区
pDC.SetPixel(-xi+x1,yi+y1,RGB(255,0,0)); //3区
pDC.SetPixel(-yi+x1,xi+y1,RGB(255,0,0)); //4区
pDC.SetPixel(-yi+x1,-xi+y1,RGB(255,0,0)); //5区
pDC.SetPixel(-xi+x1,-yi+y1,RGB(255,0,0)); //6区
pDC.SetPixel(xi+x1,-yi+y1,RGB(255,0,0)); //7区
pDC.SetPixel(yi+x1,-xi+y1,RGB(255,0,0)); //8区
if(dd<0) //D在圆内;H在圆上或圆外;选择H或D,dh>=0,dd<0,m=|dh|-|dd|=2*(dd+yi)-1;
{
m=2*(dd+yi)-1;
if(m<=0) //取右像素H(xi+1,yi);m=0时 取右点
{
dd=dd+2*xi+3; //求H的右下像素(xi+2,yi-1),dd=(xi+2)*(xi+2)+(yi-1)*(yi-1)-R*R
xi=xi+1;
}
else //取右下像素D(xi+1,yi-1)
{
dd=dd+2*(xi-yi+3); //求D的右下像素(xi+2,yi-2),dd=(xi+2)*(xi+2)+(yi-2)*(yi-2)-R*R
xi=xi+1;
yi=yi-1;
}
}
else if(dd>0) //D在圆外;V在圆外或圆上;选择D或V;dd>0,dv<=0,n=|dd|-|dv|=2*(dd-xi)-1;
{
n=2*(dd-xi)-1;
if(n<=0) //取右下像素D(xi+1,yi-1);n=0时取
{
dd=dd+2*(xi-yi+3); //求D的右下像素(xi+2,yi-2),dd=(xi+2)*(xi+2)+(yi-2)*(yi-2)-R*R
xi=xi+1;
yi=yi-1;
}
else //取下像素V(xi,yi-1)
{
dd=dd-2*yi+3; //求V的右下像素(xi+1,yi-2)dd=(xi+1)*(xi+1)+(yi-2)*(yi-2)-R*R
yi=yi-1;
}
}
else if(dd==0) //D在圆上,取D(xi+1,yi-1)
{
dd=dd+2*(xi-yi+3); //求D的右下像素(xi+2,yi-2),dd=(xi+2)*(xi+2)+(yi-2)*(yi-2)-R*R
xi=xi+1;
yi=yi-1;
}
}
}
CDC中的SetPixel方法别忘记改哦
······································
说行天下 是非常不错的小说网站大全,值得拥有.