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

这个程序主要的思想来自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);

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值