#include #include #include void usage() { fprintf(stderr, "Usage: paraboloid \n"); fprintf(stderr, " segments: the number of segments that " "must be attached to make the paraboloid\n"); fprintf(stderr, " radius: the radius in inches of the final shape\n"); fprintf(stderr, " fraction: the height as a fraction of the radius;\n"); fprintf(stderr, " A height of 0.5 puts the focal point " "in the plane of the top.\n"); exit(1); } #define PTS 100 void lineto(double x, double y) { printf("%g %g lineto %% %g, %g\n", x*72, y*72, x, y); } int main(int argc, char **argv) { if (argc != 4) { usage(); } else { double n = atof(argv[1]); double R0 = atof(argv[2]); double f = atof(argv[3]); double th2 = M_PI / n; /* theta / 2 */ double a = f/R0; /* paraboloid: z = ar^2 */ double TOL = 1.0e-7 * R0; double cth2 = cos(th2); double sth2 = sin(th2); double csq = cth2 * cth2; puts("%!PS-Adobe-2.0"); puts("%%Creator: paraboloid"); puts("%%Pages: 1"); puts("%%PageOrder: Ascend"); puts("%%BoundingBox: 0 0 612 792"); puts("%%EndComments"); puts("%%BeginSetup"); puts("%%EndSetup"); puts("%%Page: 1 1"); double pts[PTS][2]; int i; for (i = 0; i < PTS; i++) { double r = i * R0 / (PTS - 1); double h = r * sth2; double d = 0.5 * r * cth2 * sqrt(1. + 4.*a*a*r*r/csq) + csq * asinh(2.*a*r/cth2) / (4.*a); pts[i][0] = h; pts[i][1] = d; } printf("%g %g translate\n", 4.25*72, 0.5*72); puts("0 0 moveto"); for (i = 0; i < PTS; i++) { lineto(pts[i][0], pts[i][1]); } puts("stroke"); puts("0 0 moveto"); for (i = 0; i < PTS; i++) { lineto(-pts[i][0], pts[i][1]); } lineto(pts[PTS-1][0], pts[PTS-1][1]); puts("stroke"); puts("0 0 moveto"); for (i = 20; i < PTS; i++) { lineto(pts[i][0] + 0.25, pts[i][1] - 0.25); } lineto(pts[PTS-1][0], pts[PTS-1][1]); puts("stroke"); puts("showpage"); puts("%%EOF"); } }