/* bezier.c This is a shell file only. It does some of the tedious in/out for you, but all the real mathematics is missing. */ #include #include #include "coords.h" #define ERRORFILE stderr #define CONTROL_SIZE 200 /* maximum number of control points in one curve */ #define STEP 10 /* the number of t steps for each Bezier segment */ #define POWER_LIMIT 10 /* how far we calculate the geometric series on page 176 */ point wind_low = {0,0}; point wind_high = {1,1}; main() { int no_input_errors = 1; int N,Q,BBB=1,III=1,BB=1,M; point B_controls[CONTROL_SIZE]; /* for B-spline control points Ai */ point I_controls[CONTROL_SIZE]; /* for Interpolant control points Gi */ point current_point; char in_filename[50], out_filename[50]; char text[100]; char current_line[100]; FILE *fp_in; int inside_Bspline = 0; int inside_interpolant = 0; int show_polygon = 0; fp_in = stdin; strcpy(in_filename,"standard input"); N=0; while (no_input_errors) { if (N>0) { Q = fscanf(fp_in,"\n"); } Q = fscanf(fp_in,"%[^\n]",current_line); if (Q <= 0) {error_1(N,in_filename); break;} if (inside_Bspline) {switch(current_line[0]) { case 'E': /*End B-spline */ inside_Bspline=0; B_spline(B_controls,M,show_polygon); fprintf(ERRORFILE,"Line %d ends %d-th spline.\n", N+1,BBB); printf("%% End %d-th B-spline: %.45s\n", BBB,text); strcpy(text,""); /* clears the string `text' */ BBB++; show_polygon=0; break; case 'c': /* control point */ Q = sscanf(current_line,"c%F%F", &B_controls[M].x_coord,&B_controls[M].y_coord); if (Q <= 1) {error_a(N+1,in_filename); no_input_errors=0; break;} M += 1; break; case 's'/*show control poygon */: show_polygon=1; break; case '%'/*comment*/: case 'N'/*Name of picture*/: case 'z'/* insert comment in log file */: case '\\'/*Escape*/: /* escape saved for later */ case 'W'/*Width*/: printf("%s\n",current_line); break; default: error_A(N+1,in_filename); no_input_errors=0; break; }} else if (inside_interpolant) {switch(current_line[0]) { case 'F'/*End Interpolating curve*/: inside_interpolant=0; Interpolating_curve(I_controls,M,show_polygon); fprintf(ERRORFILE,"Line %d ends %d-th Interpolant.\n", N+1,III); printf("%% End %d-th Interpolating curve: %.45s\n", III,text); strcpy(text,""); /* clears the string `text' */ III++; show_polygon=0; break; case 'c': /* control point */ /* now */ Q = sscanf(current_line,"c%F%F", &I_controls[M].x_coord,&I_controls[M].x_coord); if (Q <= 1) {error_a(N+1,in_filename); no_input_errors=0; break;} M += 1; break; case '%'/*comment*/: case 'N'/*Name of picture*/: case 'z'/* insert comment in log file */: case '\\'/*Escape*/: /* escape saved for later */ case 'W'/*Width*/: printf("%s\n",current_line); break; default: error_B(N+1,in_filename); no_input_errors=0; break; }} else {switch(current_line[0]) { case 'B'/*Begin B-spline*/: fprintf(ERRORFILE,"Line %d begins %d-th ",N+1,BBB); fprintf(ERRORFILE,"B-spline.\n"); Q = sscanf(current_line,"B%[^\n]",text); printf("%% Begin %d-th B-spline: %.45s\n", BBB,text); inside_Bspline = 1; M = 0; break; case 'A'/*Begin interpolant*/: fprintf(ERRORFILE,"Line %d begins %d-th ",N+1,III); fprintf(ERRORFILE,"interpolating curve.\n"); Q = sscanf(current_line,"A%[^\n]",text); printf("%% Begin %d-th interpolating curve:",III); printf(" %.45s\n", text); inside_interpolant = 1; M = 0; break; case 'E'/*End B-spline*/: error_E(N+1,in_filename); no_input_errors=0; break; case 'F'/*End interpolating curve*/: error_F(N+1,in_filename); no_input_errors=0; break; case 'c': /* control point */ error_a1(N+1,in_filename); no_input_errors=0; break; case '%'/*comment*/: case 'N'/*Name of picture*/: case 'z'/* insert comment in log file */: case '\\'/*Escape*/: /* escape saved for later */ case 'm'/*move*/: case 'l'/*line*/: case 'P': /* path (to be filled) */ case 'L': /* point in path */ case 'q': /* terminate and fill path */ case 'Q': /* terminate, fill path, and stroke */ case 'w'/*window*/: case 'W'/*Width*/: case 't'/*text, small*/: case 'x'/*text, medium*/: case 'T'/*text, large*/: case 'd'/*dot*/: case 'g'/*gray_level*/: case 'C'/*color */: printf("%s\n",current_line); break; default: fprintf(ERRORFILE,"Data of unknown type in line "); fprintf(ERRORFILE,"%d; ignored up to newline.\n",N+1); break; }} N++; } fclose(fp_in); } Interpolating_curve(I_controls,M,show_polygon) int M,show_polygon; point_3 I_controls[]; /*I_controls = G_i in the notes */ { point_3 B_controls[CONTROL_SIZE]; /* for B-spline control points Ai */ if (M<3) { fprintf(ERRORFILE, "At least three control points needed. Spline disregarded."); return; } /* Calculation of B_controls (Ai) from I_controls (Gi) as on pages 174-176 */ /* Many lines deleted, winding up with something like : for(i=1;i