无敌黑枪.txt下载:B样条曲线C语言实现

来源:百度文库 编辑:中财网 时间:2024/05/04 08:45:47
B样条曲线C语言实现 

#include
#include
#include
#include
#include
#define smoveto(x,y) moveto(50+x,50+y)
#define slineto(x,y) lineto(50+x,50+y)
#define MAX 100
main()
{  
 int xs[MAX],ys[MAX],ii,points,k,ixx,iyy,yss;
 int gdriver=DETECT,gmode,errorcode,i,j,jj;
 float x[4],y[4],deltat,t,n1,n2,n3,n4;
 char ms[20],stri[4],msg[]="B-spline",infname[10];
 FILE *fp;
 /*printf("INPUT filename of dara for reading\n");
 scanf("%s",infname);*/
 if((fp=fopen("boat1.dat","r"))==NULL)
 {    printf("Error data file name! %s\n",infname);
 exit(1);
 }
 initgraph(&gdriver, &gmode, "d:\\tc");
 errorcode = graphresult();
 if(errorcode != grOk) /* an error occurred */
 {      printf("Graphics error: %s\n", grapherrormsg(errorcode));
 printf("Press any key to halt:");
 getch();
 exit(1);             /* return with error code */
 }
 /*printf("max X,Y is %d,%d",getmaxx(),getmaxy());
 getch();*/
 cleardevice();
 settextstyle(0,0,1);
 settextjustify(LEFT_TEXT,CENTER_TEXT);
 moveto(300,300);
 outtext(msg);
 fscanf(fp,"%d;\n",&points);
 for(j=0;j {    fscanf(fp,"%d %d %d;",&jj,&xs[j],&ys[j]);
 }
 for(j=0;j {    for(jj=0;jj<4;jj++)
 {    x[jj]=xs[j+jj];
 y[jj]=ys[j+jj];
 }
 for (i=0;i<=10;i++)
 {    t=(float)i/10.0;
 n1=(1-t)*(1-t)*(1-t)/6.0;
 n2=(3.0*t*t*t-6.0*t*t+4.0)/6.0;
 n3=(3.0*t*(1.0+t-t*t)+1.0)/6.0;
 n4=t*t*t/6.0;
 ixx=n1*x[0]+n2*x[1]+n3*x[2]+n4*x[3];
 iyy=n1*y[0]+n2*y[1]+n3*y[2]+n4*y[3];
 if(j==0&&i==0)
 {    setcolor(15);
 smoveto(ixx,iyy);
 }
 else
  slineto(ixx,iyy);
 }
 }
 fscanf(fp,"%d;\n",&points);
 for(j=0;j {    fscanf(fp,"%d %d %d;",&jj,&xs[j],&ys[j]);
 }
 setcolor(1);
 smoveto(xs[0],ys[0]);
 for(i=1;i  slineto(xs[i],ys[i]);
 for(i=0;i {    yss=ys[i]-10;
 smoveto(xs[i],yss);
 itoa(i+1,stri,10);
 setcolor(15);
 outtext(stri);
 }
 getch();
 closegraph();
}

23;

1 50 50;2 50 50;3 50 50; 4 320 120;5 540 90;6 540 90;7 530 120;8 530 120;9 510 140;10 510 140;11 500 170;12 500 170;13 320 220;14 130 180;15 130 180;16 130 160;17 130 160;18 150 160;19 150 160;20 120 100;21 50 50;22 50 50;23 50 50;

12;

1 50 50;2 320 100;3 540 90;4 530 120;5 510 140;6 500 170;7 320 220;8 130 180;9 130 160;10 150 160;11 120 100;12 50 50;