#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,Yis %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]);
}
wfor(j=0;j
w{for(jj=0;jj<4;jj++)
w{x[jj]=xs[j+jj];
wy[jj]=ys[j+jj];
w}
wfor (i=0;i<=10;i++)
w{t=float(i)/10.0;
wn1=(1-t)*(1-t)*(1-t)/6.0;
wn2=(3.0*t*t*t-6.0*t*t+4.0)/6.0;
wn3=(3.0*t*(1.0+t-t*t)+1.0)/6,0;
wn4=t*t*t/6.0;
wixx=n1*x[0]+n2*x[1]+n3*x[2]+n4*x[3];
wiyy=n1*y[0]+n2*y[1]+n3*y[2]+n4*y[3];
wif(j==0&&i==0)
w{setcolor(15);
wsmoveto(ixx,iyy);
w}
welse
wslineto(ixx,iyy);
w}
w}
wfscanf(fp,"%d;\n",&points);
wfor(j=0;j
w{fscanf(fp,"%d %d %d;",&jj,&xs[j],&ys[j]);
w}
wsetcolor(1);
wsmoveto(xs[0],ys[0]);
wfor(i=1;i
wslineto(xs[i],ys[i]);
wfor(i=0;i
w{yss=ys[i]-10;
wsmoveto(xs[i],yss);
witoa(i+1,stri,10);
wsetcolor(15);
wouttext(stri);
w}
wgetch();
wclosegraph();
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;