C语言生成Bezier曲线程序

#include
void bezier_3(int color, double p[4][2])
{
double t,t1,t2,xt,yt;
int rate=200,x,y;
setcolor(color);
moveto(p[0][0],p[0][1]);
for (t=0;t<=1;t+=1.0/rate)
{
yt=1-t;
t1=yt*yt;
t2=3*yt*t;
xt=p[0][0]*t1*yt+p[1][0]*t2*yt+p[2][0]*t2*t+p[3][0]*t*t*t;
yt=p[0][1]*yt*t1+p[1][1]*t2*yt+p[2][1]*t2*t+p[3][1]*t*t*t;
x=(int)(xt);
y=(int)(yt);
lineto(x,y);
}
}
void main()
{
static double p[4][2]={50,400,140,20,400,40,635,420};
const NO=3; /*特征顶点数*/
int i;
int driver=DETECT,mode;
initgraph(&driver,&mode,"C://tools/tc2.0");
cleardevice();
setcolor(BLUE);
moveto(p[0][0],p[0][1]);
for (i=1;ilineto(p[i][0],p[i][1]);
bezier_3(LIGHTRED,p);
getch(); /*按ESC键退出*/
closegraph();
}

相关文档
最新文档