2008-11-08 20:01
#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("c:\\tc\\bin\\boat1.dat","r"))==NULL)
{ printf("Error data file name! %s\n",infname);
exit(1);
}
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
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]);
}
w for(j=0;j
w { for(jj=0;jj<4;jj++)
w { x[jj]=xs[j+jj];
w y[jj]=ys[j+jj];
w }
w for (i=0;i<=10;i++)
w { t=float(i)/10.0;
w n1=(1-t)*(1-t)*(1-t)/6.0;
w n2=(3.0*t*t*t-6.0*t*t+4.0)/6.0;
w n3=(3.0*t*(1.0+t-t*t)+1.0)/6,0;
w n4=t*t*t/6.0;
w ixx=n1*x[0]+n2*x[1]+n3*x[2]+n4*x[3];
w iyy=n1*y[0]+n2*y[1]+n3*y[2]+n4*y[3];
w if(j==0&&i==0)
w { setcolor(15);
w smoveto(ixx,iyy);
w }
w else
w slineto(ixx,iyy);
w }
w }
w fscanf(fp,"%d;\n",&points);
w for(j=0;j
w { fscanf(fp,"%d %d %d;",&jj,&xs[j],&ys[j]);
w }
w setcolor(1);
w smoveto(xs[0],ys[0]);
w for(i=1;i
w slineto(xs[i],ys[i]);
w for(i=0;i
w { yss=ys[i]-10;
w smoveto(xs[i],yss);
w itoa(i+1,stri,10);
w setcolor(15);
w outtext(stri);
w }
w getch();
w closegraph();
w }
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;