for(i = 0; i < 100; i++) { t = i / 100.0;
x = (1-t)*(1-t)*(1-t)*P0[0]+(3*t)*(1-t)*(1-t)*P1[0]+3*t*t*(1-t)*P2[0]+t*t*t*P3[0]; printf("%f,", x); x = (1-t)*(1-t)*(1-t)*P0[1]+(3*t)*(1-t)*(1-t)*P1[1]+3*t*t*(1-t)*P2[1]+t*t*t*P3[1]; printf("%f/n", x);
} }
在TC3.0环境下用二次插值画的曲线:
#include #include #include #include
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int i; double t; int x; int y; int P0[2] = {1, 1}, P1[2] = {50, 50}, P2[2]={70, 1};
/* initialize graphics mode */ initgraph(&gdriver, &gmode, "c:/tc");
/* read result of initialization */ 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 */ }