三次Bezier曲线

#include 
#include 
#include 
#include 

char msg[1];
float px[10]={30,60,90,120,150,190,220,250,280,310};
float py[10]={150,200,200,170,100,100,170,200,200,180};

main()
{
	float a0,a1,a2,a3,b0,b1,b2,b3;
	int k,m,y,w;
	float i,t,dt,n=10;
	int gdriver=DETECT,gmode;
	initgraph(&gdriver,&gmode," ");
	setbkcolor(5);
	setcolor(7);
	dt=1/n;

	for(k=0;k<10-1;k++)
	{
		moveto(px[k],py[k]);
		lineto(px[k+1],py[k+1]);
	}

	setlinestyle(0,0,3);
	for(k=0;k<10-3;k+=3)
	{
		a0=px[k];
		a1=-3*px[k]+3*px[k+1];
		a2=3*px[k]-6*px[k+1]+3*px[k+2];
		a3=-px[k]+3*px[k+1]-3*px[k+2]+px[k+3];
		b0=py[k];
		b1=-3*py[k]+3*py[k+1];
		b2=3*py[k]-6*py[k+1]+3*py[k+2];
		b3=-py[k]+3*py[k+1]-3*py[k+2]+py[k+3];

		for(i=0;i<=n;i+=0.1)
		{
			t=i*dt;
			m=a0+a1*t+a2*pow(t,2)+a3*pow(t,3);
			y=b0+b1*t+b2*pow(t,2)+b3*pow(t,3);

			if(i==0)
				moveto(m,y);
			lineto(m,y);
			delay(10000);
		}
	}

	getch();
	closegraph();

}

你可能感兴趣的:(基础图形算法)