Breseham椭圆绘画算法演变出来的程序!

类别:VC语言 点击:0 评论:0 推荐:

这个程序主要的思想来自Breseham算法,
演变的东西就是增加了旋转!
算法描述就不写了,敲打起来很累!

把程序罗列出来吧!

Mfc 代码如下:

////////////////////////////////////////////////////////////////////////////////////

//BreEllipse

//(xc,yc)----------椭圆中心

//fla,flb----------横轴和纵轴的半径

//double-----------旋转的角度

////////////////////////////////////////////////////////////////////////////////////

void BreEllipse(CDC *pDC,float xc ,float yc,float fla,float flb,double angle)

{

int i;

float a,b,x,y;

    double dx,dy,di,aa,bb,sinA,cosA;

cosA=cos(angle);

sinA=sin(angle);

a=fla;

    b=flb;

aa=a*a;

bb=b*b;

float flX[4],flY[4];

x=0;

y=b;

dx=0;

dy=2*aa*y;

di=bb-aa*b+aa/4;

flX[0]=xc+x*cosA-y*sinA;

flX[1]=xc+x*cosA+y*sinA;

flX[2]=xc-x*cosA-y*sinA;

flX[3]=xc-x*cosA+y*sinA;

flY[0]=yc+y*cosA+x*sinA;

flY[1]=yc-y*cosA+x*sinA;

flY[2]=yc+y*cosA-x*sinA;

flY[3]=yc-y*cosA-x*sinA;

i=0;

while(dx<dy)

{

i++;

if(i==5)

{

pDC->MoveTo(flX[0],flY[0]);

pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);

pDC->MoveTo(flX[1],flY[1]);

pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);

pDC->MoveTo(flX[2],flY[2]);

pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);

pDC->MoveTo(flX[3],flY[3]);

pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);

flX[0]=xc+x*cosA-y*sinA;

flX[1]=xc+x*cosA+y*sinA;

flX[2]=xc-x*cosA-y*sinA;

flX[3]=xc-x*cosA+y*sinA;

flY[0]=yc+y*cosA+x*sinA;

flY[1]=yc-y*cosA+x*sinA;

flY[2]=yc+y*cosA-x*sinA;

flY[3]=yc-y*cosA-x*sinA;

i=0;

}

x++;

dx+=2*bb;

di+=dx+bb;

if(di>=0)

{

dy-=2*aa;

di-=dy;

y--;

}

}

pDC->MoveTo(flX[0],flY[0]);

pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);

pDC->MoveTo(flX[1],flY[1]);

pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);

pDC->MoveTo(flX[2],flY[2]);

pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);

pDC->MoveTo(flX[3],flY[3]);

pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);

 

di+=int((3*(aa-bb)-2*(dx-dy))/4+0.5);

flX[0]=xc+x*cosA-y*sinA;

flX[1]=xc+x*cosA+y*sinA;

flX[2]=xc-x*cosA-y*sinA;

flX[3]=xc-x*cosA+y*sinA;

flY[0]=yc+y*cosA+x*sinA;

flY[1]=yc-y*cosA+x*sinA;

flY[2]=yc+y*cosA-x*sinA;

flY[3]=yc-y*cosA-x*sinA;

i=0;

while(y>0)

{

i++;

if(i==5)

{

pDC->MoveTo(flX[0],flY[0]);

pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);

pDC->MoveTo(flX[1],flY[1]);

pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);

pDC->MoveTo(flX[2],flY[2]);

pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);

pDC->MoveTo(flX[3],flY[3]);

pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);

flX[0]=xc+x*cosA-y*sinA;

flX[1]=xc+x*cosA+y*sinA;

flX[2]=xc-x*cosA-y*sinA;

flX[3]=xc-x*cosA+y*sinA;

flY[0]=yc+y*cosA+x*sinA;

flY[1]=yc-y*cosA+x*sinA;

flY[2]=yc+y*cosA-x*sinA;

flY[3]=yc-y*cosA-x*sinA;

i=0;

}

y--;

dy-=2*aa;

di+=aa-dy;

if(di<0)

{

dx+=2*bb;

di+=dx;

x++;

}

}

pDC->MoveTo(flX[0],flY[0]);

pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);

pDC->MoveTo(flX[1],flY[1]);

pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);

pDC->MoveTo(flX[2],flY[2]);

pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);

pDC->MoveTo(flX[3],flY[3]);

pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);

}

 

 

本文地址:http://com.8s8s.com/it/it353.htm