/* Written by W. Taylor, Math Dept, University of Colorado, Boulder, CO 80309-0426, USA. wtaylor@euclid.colorado.edu. Last revised 6/3/89 */ #include #include #include "coords.h" /* The units used in this file are such that if the picture is put on an 8.5 x 8.5 window on a laser printer, then the units are inches. Printed on other devices, the units may not be real inches. */ #define SIZE 6.4 /* width = height of picture, in inches */ /* The location of the upper left corner of the picture will be as follows: */ #define H_OFFSET 1.2 /* inches from left edge of paper */ #define V_OFFSET 2 /* inches from top edge of paper */ circle(p,R) point p; double R; { #define CIRC_STEPS 100 point q,r; int k; q = p; q.x_coord+=R; for (k=1;k<=CIRC_STEPS;k++) { r = q; q.x_coord = p.x_coord + R*cos((2*PI*k)/CIRC_STEPS); q.y_coord = p.y_coord + R*sin((2*PI*k)/CIRC_STEPS); segment(r,q); } } begin_small_text() {printf("t");} end_small_text() {printf("\n");} begin_medium_text() {printf("x");} end_medium_text() {printf("\n");} begin_large_text() {printf("T");} end_large_text() {printf("\n");} set_clip_region() { point p, q; p.x_coord = H_OFFSET; p.y_coord = 8.5 - V_OFFSET - SIZE; q.x_coord = H_OFFSET + SIZE; q.y_coord = 8.5 - V_OFFSET; printf("%%Here begins the designation of the clip region.\n"); printf("r %3.3f %3.3f %3.3f %3.3f\n", p.x_coord, p.y_coord, q.x_coord, q.y_coord); printf("%%This concludes the designation of the clip region.\n"); } draw_axes(left,right,bottom,top) double left, right, bottom, top; { point p0, p1; printf("%%Here we draw the coordinate axes, if they fit.\n"); set_pen(2); if ( (left < 0.0) && (right > 0.0)) { p0.x_coord = p1.x_coord = H_OFFSET + SIZE * (left/(left - right)); p0.y_coord = 8.5 - V_OFFSET; p1.y_coord = 8.5 - V_OFFSET - SIZE; segment(p0,p1); } if ( (bottom < 0.0) && (top > 0.0)) { p0.y_coord = p1.y_coord = 8.5 - V_OFFSET - SIZE*(1.0-(bottom/(bottom - top))); p0.x_coord = H_OFFSET; p1.x_coord = H_OFFSET + SIZE; segment(p0,p1); } printf("%%This ends the laying down of the axes.\n"); } draw_frame() { point p,q,r,s; p.x_coord = q.x_coord = H_OFFSET; q.y_coord = r.y_coord = 8.5 - V_OFFSET; r.x_coord = s.x_coord = H_OFFSET + SIZE; s.y_coord = p.y_coord = 8.5 - V_OFFSET - SIZE; printf("%%Here we begin drawing a frame.\n"); set_pen(12); move_to(p); line_to(q); line_to(r); line_to(s); line_to(p); printf("%%This concludes the drawing of a frame.\n"); } print_path(start_t,stop_t,step,width,left,right,bottom,top,f) double left, right, bottom, top, start_t, stop_t; point (*f)(); int step, width; { int i,printing; double t0, t1; point lower_corner, p0, p1; point lower_corner_inches; point plus(), minus(), ttimes(); lower_corner.x_coord = left; lower_corner.y_coord = bottom; lower_corner_inches.x_coord = H_OFFSET; lower_corner_inches.y_coord = 8.5 - V_OFFSET - SIZE; printf("%%Here we begin printing a curve.\n"); set_pen(width); printing = 0; for (i=0; i<(step+1); i++) { t0 = t1; t1 = (start_t + (((double) i)/step)*(stop_t - start_t)); p0 = p1; p1 = (*f)(t1); p1 = minus(p1,lower_corner); p1.x_coord = p1.x_coord/(right-left); p1.y_coord = p1.y_coord/(top-bottom); p1 = plus(lower_corner_inches,ttimes(SIZE,p1)); if ( p0.x_coord <= H_OFFSET + SIZE && p0.x_coord >= H_OFFSET && p1.x_coord <= H_OFFSET + SIZE && p1.x_coord >= H_OFFSET && p0.y_coord <= 8.5 - V_OFFSET && p0.y_coord >= 8.5 - V_OFFSET - SIZE && p1.y_coord <= 8.5 - V_OFFSET && p1.y_coord >= 8.5 - V_OFFSET - SIZE ) { if (printing) line_to(p1); else move_to(p1); printing = 1; } else printing = 0; } printf("%%Now we have finished printing a curve.\n"); } print_path_param(start_t,stop_t,step,left,right,bottom,top,f,r) double left, right, bottom, top, start_t, stop_t; point (*f)(); int step, r; { int i,printing; double t0, t1; double test1, test2, test3, test4; point lower_corner, p0, p1; point lower_corner_inches; point plus(), minus(), ttimes(); lower_corner.x_coord = left; lower_corner.y_coord = bottom; lower_corner_inches.x_coord = H_OFFSET; lower_corner_inches.y_coord = 8.5 - SIZE - V_OFFSET; printing=0; for (i=0; i<(step+1); i++) { t0 = t1; t1 = (start_t + (((double) i)/step)*(stop_t - start_t)); test3 = test1; test4 = test2; p0 = p1; p1 = (*f)(t1,r); p1 = minus(p1,lower_corner); p1.x_coord = p1.x_coord/(right-left); p1.y_coord = p1.y_coord/(top-bottom); p1 = plus(lower_corner_inches,ttimes(SIZE,p1)); if ( p0.x_coord <= H_OFFSET + SIZE && p0.x_coord >= H_OFFSET && p1.x_coord <= H_OFFSET + SIZE && p1.x_coord >= H_OFFSET && p0.y_coord <= 8.5 - V_OFFSET && p0.y_coord >= 8.5 - V_OFFSET - SIZE && p1.y_coord <= 8.5 - V_OFFSET && p1.y_coord >= 8.5 - V_OFFSET - SIZE ) { if (printing) line_to(p1); else move_to(p1); printing = 1; } else printing = 0; } } move_to(p) point p; { printf("m %3.3f %3.3f\n",p.x_coord,p.y_coord); } line_to(p) point p; { printf("l %3.3f %3.3f\n",p.x_coord,p.y_coord); } set_pen(width) int width; { printf("W %d ---- sets the width to %d points.\n",width,width); } segment(p,q) point p, q; { move_to(p); line_to(q); } point affine(p,q,r) point p, q, r; { point z; z.x_coord = p.x_coord - q.x_coord + r.x_coord; z.y_coord = p.y_coord - q.y_coord + r.y_coord; return (z); } point convex_comb(alpha,p,q) double alpha; point p, q; { point z; z.x_coord = alpha*(p.x_coord) + (1.0 - alpha)*(q.x_coord); z.y_coord = alpha*(p.y_coord) + (1.0 - alpha)*(q.y_coord); return (z); } point plus(p,q) point p, q; { point z; z.x_coord = p.x_coord + q.x_coord; z.y_coord = p.y_coord + q.y_coord; return (z); } point minus(p,q) point p, q; { point z; z.x_coord = p.x_coord - q.x_coord; z.y_coord = p.y_coord - q.y_coord; return (z); } point ttimes(alpha,p) double alpha; point p; { point z; z.x_coord = alpha*(p.x_coord); z.y_coord = alpha*(p.y_coord); return (z); } point_3 convex_comb_3(alpha,p,q) double alpha; point_3 p, q; { point_3 z; z.coord_1 = alpha*(p.coord_1) + (1.0 - alpha)*(q.coord_1); z.coord_2 = alpha*(p.coord_2) + (1.0 - alpha)*(q.coord_2); z.coord_3 = alpha*(p.coord_3) + (1.0 - alpha)*(q.coord_3); return (z); } point_3 plus_3(p,q) point_3 p, q; { point_3 z; z.coord_1 = p.coord_1 + q.coord_1; z.coord_2 = p.coord_2 + q.coord_2; z.coord_3 = p.coord_3 + q.coord_3; return (z); } point_3 minus_3(p,q) point_3 p, q; { point_3 z; z.coord_1 = p.coord_1 - q.coord_1; z.coord_2 = p.coord_2 - q.coord_2; z.coord_3 = p.coord_3 - q.coord_3; return (z); } point_3 ttimes_3(alpha,p) double alpha; point_3 p; { point_3 z; z.coord_1 = alpha*(p.coord_1); z.coord_2 = alpha*(p.coord_2); z.coord_3 = alpha*(p.coord_3); return (z); } label_x_axis(left,right) double left, right; { point p; p.x_coord = H_OFFSET - 0.2; p.y_coord = 8.5 - V_OFFSET - SIZE - 0.22; printf("%%Here we label the x-axis.\n"); move_to(p); begin_medium_text(); printf("%4.2f",left); end_medium_text(); p.x_coord = p.x_coord + SIZE + 0.1; move_to(p); begin_medium_text(); printf("%4.2f",right); end_medium_text(); printf("%%This finishes the job of labeling the x-axis.\n"); } label_y_axis(top,bottom) double top, bottom; { point p; p.x_coord = H_OFFSET - 0.55; p.y_coord = 8.5 - V_OFFSET - .07; printf("%%Here we label the y-axis.\n"); move_to(p); begin_medium_text(); printf("%4.2f",top); end_medium_text(); p.y_coord = p.y_coord - SIZE + .1; move_to(p); begin_medium_text(); printf("%4.2f",bottom); end_medium_text(); printf("%%This finishes the job of labeling the y-axis.\n"); } window() { printf("w 0.0 0.0 8.5 8.5\n"); /* This allows us to use inches everywhere */ } position_label() { printf("%%Moving to the label position\n"); printf("m 1.1 -0.7\n"); } position_login_signature() { printf("%%Moving to the login signature position\n"); printf("m 5.5 -1.5\n"); }