/* Written by W. Taylor, Math Dept, Univ. of Colorado, Boulder,Colo 80309-0426, ...![ucbvax,allegra]!nbires!boulder!wtaylor or wtaylor@boulder (cs-net). Last revised 8/22/87 */ #include #include #include "coords.h" #define PI 3.14159 #define FOCUS 4.0 /* the joint foci are at +/- this number. */ #define BB 1.0 /* a parameter that determines the minor axes of the ellipses. */ #define HYPS 10 #define STEP 250 /* Number of divisions of the time interval. Here you can experiment for the best value. Too small and you'll see the corners. Too large and you'll get undesired effects which come from overloading the memory of the printer. */ /* The curve will be defined parametrically with a parameter t which ranges between two real numbers, which are as follows. Edit these to suit the case at hand. */ #define START_T 0.0 /* This, and others, must be written as double */ #define STOP_T (2*PI) /* The next four numbers give the values of the x and y co-ordinates at the sides of the window which will be printed. These also can be changed to suit the case at hand. */ #define LEFT -7.10 /* value of u at left of window */ #define RIGHT 7.10 #define BOTTOM -7.10 /* value of v at bottom of window */ #define TOP 7.10 point f(t,r) int r; double t; { point p; double b = r*BB; double c = FOCUS; double a = sqrt(c*c + b*b); p.x_coord = a*cos(t); p.y_coord = b*sin(t); return (p); } point h(t,r) int r; double t; { point p; double u; double c = FOCUS; double a = (((double) r)/HYPS)*c; double b = sqrt(c*c - a*a); u = 5*(t-PI); p.x_coord = a*cosh(u); p.y_coord = b*sinh(u); return (p); } main() { int r; point p, f(), h(), g(); char *login, *getlogin(); open_tek(); draw_frame(); for (r=1;r<=6;r+=1) { tek_print_path_param(START_T,STOP_T,STEP,LEFT,RIGHT,BOTTOM,TOP,f,r); } for (r=(-HYPS+1);r #include #include "coords.h" #define PI 3.14159 #define STEP 50 /* Number of divisions of the time interval. Here you can experiment for the best value. Too small and you'll see the corners. Too large and you'll get undesired effects which come from overloading the memory of the printer. */ /* The curve will be defined parametrically with a parameter t which ranges between two real numbers, which are as follows. Edit these to suit the case at hand. */ #define START_T 0.0 /* This, and others, must be written as double */ #define STOP_T (2*PI) /* The next four numbers give the values of the x and y co-ordinates at the sides of the window which will be printed. These also can be changed to suit the case at hand. */ #define LEFT -1.10 /* value of u at left of window */ #define RIGHT 1.10 #define BOTTOM -1.10 /* value of v at bottom of window */ #define TOP 1.10 /* Here is where we declare the actual function we are graphing. You can make the right hand sides here (the x and y co-ordinates of the curve) any legal C-expressions. `Point' by the way is merely a defined data type which has two double co-ordinates. Its defininiton resides in the header file coords.h which you need to have in the same directory for this to compile. Feel free here to declare auxiliary variables and add extra lines of calculations to get the desired result. */ point f(t,r) int r; double t; { point p; p.x_coord = r*0.1*cos(t); p.y_coord = r*0.1*sin(t); return (p); } point g(t) double t; { point p; double u; u = PI/2 + t/4; p.x_coord = cos(u) + 1.0; p.y_coord = sin(u); return (p); } main() { int r; point p, f(); char *login, *getlogin(); open_tek(); draw_frame(); for (r=2;r<=6;r+=2) { tek_print_path_param(START_T,STOP_T,STEP,LEFT,RIGHT,BOTTOM,TOP,f,r); } tek_print_path(START_T,STOP_T,STEP,LEFT,RIGHT,BOTTOM,TOP,g); alpha_mode(); small_type(); label_x_axis(LEFT,RIGHT); label_y_axis(TOP,BOTTOM); large_type(); /*TELL WHERE YOU WANT THE LABEL TO BE*/ p.x_coord = 1.1; /* inches from left of paper */ p.y_coord = 0.5; /* inches from bottom of paper */ set_abs_vh(p); alpha_mode(); /* TEXT */ printf("A circle"); small_type(); p.x_coord += 6.0; p.y_coord -= 0.15; set_abs_vh(p); alpha_mode(); printf("login name: %s",getlogin()); end_tek(); /* Comment this out when sending to a tektronix screen */ } /* Written by W. Taylor, Math Dept, Univ. of Colorado, Boulder,Colo 80309-0426, ...![ucbvax,allegra]!nbires!boulder!wtaylor or wtaylor@boulder (cs-net). Last revised 8/22/87 */ #include #include #include "coords.h" #define LAMBDA 1.5 #define PI 3.14159 #define K 5.0 /* a parameter that determines the location of of the directrix. */ #define ECC 0.1 /* a parameter that determines the steps of the eccentricity */ #define STEP 50 /* Number of divisions of the time interval. Here you can experiment for the best value. Too small and you'll see the corners. Too large and you'll get undesired effects which come from overloading the memory of the printer. */ /* The curve will be defined parametrically with a parameter t which ranges between two real numbers, which are as follows. Edit these to suit the case at hand. */ #define START_T 0.0 /* This, and others, must be written as double */ #define STOP_T (2*PI) /* The next four numbers give the values of the x and y co-ordinates at the sides of the window which will be printed. These also can be changed to suit the case at hand. */ #define LEFT -6.00 /* value of u at left of window */ #define RIGHT 10.00 #define BOTTOM -6.00 /* value of v at bottom of window */ #define TOP 6.00 point crunch(p) point p; { point q; q = p; q.x_coord = LAMBDA*p.x_coord; q.y_coord = p.y_coord/LAMBDA; return(q); } point f(t,e) int e; double t; { point p; double denominator; denominator = 1 - e*ECC*cos(t); if ((denominator>0.00001) || (denominator<-0.00001)) { p.x_coord = e*ECC*K*cos(t)/denominator; p.y_coord = e*ECC*K*sin(t)/denominator; } else { p.x_coord = 10000; p.y_coord = 10000; } p=crunch(p); return (p); } point h(t) double t; { point p; p.x_coord = -K; p.y_coord = (t-PI)*1.7; p=crunch(p); return (p); } main() { int e; point p, f(), h(), g(); char *login, *getlogin(); open_tek(); draw_frame(); for (e=1;e<=10;e+=1) { tek_print_path_param(START_T,STOP_T,STEP,LEFT,RIGHT,BOTTOM,TOP,f,e); } tek_print_path(START_T,STOP_T,STEP,LEFT,RIGHT,BOTTOM,TOP,h); alpha_mode(); small_type(); label_x_axis(LEFT,RIGHT); label_y_axis(TOP,BOTTOM); large_type(); /*TELL WHERE YOU WANT THE LABEL TO BE*/ p.x_coord = 1.1; /* inches from left of paper */ p.y_coord = 0.5; /* inches from bottom of paper */ set_abs_vh(p); alpha_mode(); /* TEXT */ printf("Directrix at x = -5; eccentricity 0.1, 0.2, ... , 1.6"); small_type(); p.x_coord += 6.0; p.y_coord -= 0.15; set_abs_vh(p); alpha_mode(); printf("login name: %s",getlogin()); end_tek(); } /* Here is a crude version of a `seeworld' program. Actually you can use it more or less as is, except you have to throw away the `display()' routine at the end, and put in a display routine that does something more interesting. (There are a number of possibilities, but mostly we want it as projected from a point in space.) Studying this file should also show you how to read data from a file. The file DATAFILE just below can of course be changed to any other file you might want to read data from. Sometimes for the purposes of testing and development it is handy to take data from a smaller file. Looking at the pictures generated here will help you get some idea of how finely spaced the points are in this data base. (Some coordinates are suggested below.) You will notice that this program puts its output on two separate channels. All the printing of `segments' is output on `stdout,' and can hence be redirected to a file. On the other hand, remarks to the user, such as `what latitude do we want' are output on `stderr,' the standard error output. This latter also goes to the screen, but goes to the screen even after a redirect. Therefore if you do a.out > file you will still get the interactive features, but then the file can be sent to the printer. DO NOT FORGET `end_tek()' if you want to print; right now it is commented away. You are free to take copies of the continents.data file, but please let us not have everyone storing a private copy on spot, since spot is having its perpetual scarcity of disk space. Download it to a PC diskette if you want to keep a copy for yourself. For the purposes of the class, it will work just fine for everyone to read it from the same file. */ #include #include #include "coords.h" #define DATAFILE "/users/stf_math/wtaylor/1/427/data/continents.data" #define ERRORFILE stderr main() { char in_filename[50], out_filename[50]; double latitude, longitude; FILE *fp_in, *get_data_file(), fclose(); int printing, N, Q; point p, q; fp_in = get_data_file(in_filename); read_coordinates(&latitude,&longitude); open_tek(); N=0; while (1) { q = p; Q = fscanf(fp_in,"%d",&printing); if (Q <= 0) {error_1(N,in_filename); break;} if ((printing!=0)&&(printing!=1)) {error_4(N,in_filename); break;} Q = fscanf(fp_in,"%lf",&p.y_coord); if (Q <= 0) {error_2(N,in_filename); break;} Q = fscanf(fp_in,"%lf",&p.x_coord); if (Q <= 0) {error_3(N,in_filename); break;} N++; if (printing==1) display(p,q,latitude,longitude); } label_picture(); /* at present this does nothing .... */ end_tek(); fclose(fp_in); } read_coordinates(lat,longi) double *lat; double *longi; { fprintf(ERRORFILE,"\nWhat latitude should we use? "); scanf("%lf",lat); fprintf(ERRORFILE,"\n"); fprintf(ERRORFILE,"\nAnd what longitude should we use? "); scanf("%lf",longi); } FILE *get_data_file(in_filename) char in_filename[]; { FILE *fp_in, *fopen(); strcpy(in_filename,DATAFILE); fp_in = fopen(in_filename,"r"); if (fp_in==NULL) { fprintf(ERRORFILE,"\nI can't find the input file?\n\n"); } return(fp_in); } error_1(N,in_filename) int N; char in_filename[]; { fprintf(ERRORFILE,"\nSuccessfully read "); fprintf(ERRORFILE,"%d lines of data from \"%s\"\n",N,in_filename); } error_2(N,in_filename) int N; char in_filename[]; { fprintf(ERRORFILE,"\nInput terminated; cannot read first coor"); fprintf(ERRORFILE,"dinates of line %d of %s\n",N+1,in_filename); } error_3(N,in_filename) { fprintf(ERRORFILE,"\nInput terminated; cannot read second coor"); fprintf(ERRORFILE,"dinates of line %d of %s\n",N+1,in_filename); } error_4(N,in_filename) { fprintf(ERRORFILE,"\nInput terminated; incorrect first "); fprintf(ERRORFILE,"entry of line %d of %s:\n",N+1,in_filename); fprintf(ERRORFILE,"\n >>> First entry of each line "); fprintf(ERRORFILE,"must be 0 or 1. <<<\n\n"); } /* The display function here was prepared ad hoc, and does nothing more than plot coordinates as if the world were a Euclidean plane. Right now the parameters have been chosen so that about half the Mediterranean will show up if you happen to take latitude=41,longitude=14 (these are the coordinates of Naples). Some other interesting coordinates to try are 52 3 (Ireland, England and much of northern Europe) 8 79 (southern India and Sri Lanka) 16 122 (much of the Philippines, coast of China, island of Taiwan and one corner of Borneo) The `3.0' seen below was chosen just because it seemed to make reasonable pictures. */ display(p,q,latitude,longitude) double latitude, longitude; point p, q; { point ttimes(), minus(), plus(); point land_center, paper_center; land_center.x_coord = longitude; land_center.y_coord = latitude; paper_center.x_coord = 5.0; paper_center.y_coord = 4.0; p = plus(ttimes(3.0/10,minus(p,land_center)),paper_center); q = plus(ttimes(3.0/10,minus(q,land_center)),paper_center); if ( (p.x_coord < 9) && (p.x_coord > 1) && (p.y_coord < 7) && (p.y_coord > 1) && (q.x_coord < 9) && (q.x_coord > 1) && (q.y_coord < 7) && (q.y_coord > 1) ) tek_segment(p,q); } label_picture() { } #define PI 3.14159 #define DPI 300 /* working with inches */ #define MESH 300 /* dots per inch */ #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 */ typedef struct { double x_coord; double y_coord; } point; typedef struct { double coord_1; double coord_2; double coord_3; } point_3; typedef struct { double coord_1; double coord_2; double coord_3; double coord_4; } point_4; typedef struct { double a_11; double a_12; double a_21; double a_22; } matrix_2_2; typedef struct { double a_11; double a_12; double a_13; double a_21; double a_22; double a_23; double a_31; double a_32; double a_33; } matrix_3_3; typedef struct { double a_11; double a_12; double a_13; double a_14; double a_21; double a_22; double a_23; double a_24; double a_31; double a_32; double a_33; double a_34; double a_41; double a_42; double a_43; double a_44; } matrix_4_4; typedef struct { double a_11; double a_12; double a_13; double a_14; double a_21; double a_22; double a_23; double a_24; double a_31; double a_32; double a_33; double a_34; } matrix_3_4; typedef struct { double a_11; double a_12; double a_13; double a_21; double a_22; double a_23; double a_31; double a_32; double a_33; double a_41; double a_42; double a_43; } matrix_4_3; typedef point_4 Projective_point_3; typedef point_3 Projective_point_2;