ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/gencat.c
Revision: 2.2
Committed: Mon Aug 2 14:23:02 1993 UTC (30 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +4 -0 lines
Log Message:
added conditional declaration of atof()

File Contents

# User Rev Content
1 greg 2.1 /* Copyright (c) 1993 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*****************************************************************************
8     This program is to make series of right triangles forming hyperbolic cosin
9     (ie, cosh) curve in between of 2 points.
10     ^
11     f(h)|
12     |
13     | 0\ pc:(hc, fc)
14     | | \
15     | | \
16     | | \
17     | pa:(ha, fa) 0-------------0 pb:(hb, fb)
18     |
19     0------------------------------------------------> h
20    
21     Given arguments:
22     material
23     name
24     (x0, y0, z0), (x1, y1, z1)
25     k const. value K
26     d distant length desired between 2 points
27    
28     ******************************************************************************/
29    
30     #include <stdio.h>
31     #include <math.h>
32    
33 greg 2.2 #ifdef DCL_ATOF
34     extern double atof();
35     #endif
36    
37 greg 2.1 char *cmtype, *cname;
38     double z0, z1;
39     double k, D;
40     double d;
41     double z, h;
42    
43     #ifdef notdef
44     double Newton( b)
45     double b;
46     {
47     if (fabs(cosh(k*D+b)-cosh(b)-(z1-z0)/k) < .001)
48     return (b);
49     else {
50     b = b - (cosh(k*D+b)-cosh(b)-(z1-z0)/k)/(sinh(k*D+b)-sinh(b));
51     Newton (b);
52     }
53     }
54     #endif
55    
56     double Newton(bl)
57     double bl;
58     {
59     double b;
60     int n = 10000;
61    
62     while (n--) {
63     b = bl- (cosh(k*D+bl)-cosh(bl)-(z1-z0)/k)/(sinh(k*D+bl)-sinh(bl));
64     if (fabs(b-bl) < .00001)
65     return(b);
66     bl = b;
67     }
68     fprintf(stderr, "Interation limit exceeded -- invalid K value\n");
69     exit(1);
70     }
71    
72    
73     main (argc, argv)
74     int argc;
75     char *argv[];
76     {
77     double x0, y0;
78     double x1, y1;
79     double b;
80     double delh;
81     double f, fprim;
82     double hb, hc, fb, fc;
83     int n;
84    
85     if (argc != 11) {
86     fprintf(stderr, "Usage: gencat material name x0 y0 z0 x1 y1 z1 k d\n");
87     exit(1);
88     }
89    
90     cmtype = argv[1];
91     cname = argv[2];
92     x0 = atof(argv[3]); y0 = atof(argv[4]); z0 = atof(argv[5]);
93     x1 = atof(argv[6]); y1 = atof(argv[7]); z1 = atof(argv[8]);
94     k = atof(argv[9]); d = atof(argv[10]);
95     D = sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
96     b = Newton(0.0);
97     z = z0 - k * cosh(b);
98     printhead(argc, argv);
99    
100     n = 0;
101     for (h=0; h<=D; ) {
102     f = k * cosh(k*h+b) + z;
103     fprim = k* k * sinh(k*h+b);
104     delh = d / sqrt(1+fprim*fprim);
105     fprim = k * k * sinh(k*(h+delh/2)+b);
106     hb = sqrt(.01*fprim*fprim/(1+fprim*fprim));
107     fb = sqrt(.01/(1+(fprim*fprim)));
108     hc = sqrt(.04/(1+fprim*fprim));
109     fc = sqrt(.04*fprim*fprim/(1+fprim*fprim));
110    
111     printf("\n%s polygon %s.%d\n", cmtype, cname, ++n);
112     printf("0\n0\n9\n");
113     printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f);
114     if (fprim < 0)
115     {
116     printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f-fc);
117     printf("%f %f %f\n", (h+hb)*(x1-x0)/D+x0, (h+hb)*(y1-y0)/D+y0, f+fb);
118     }
119     else if (fprim > 0)
120     {
121     printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f+fc);
122     printf("%f %f %f\n", (h-hb)*(x1-x0)/D+x0, (h-hb)*(y1-y0)/D+y0, f+fb);
123     }
124     else
125     {
126     printf("%f %f %f\n", (h+.2)*(x1-x0)/D+x0, (h+.2)*(y1-y0)/D+y0, f);
127     printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f+.1);
128     }
129     h += delh;
130     }
131     }
132    
133    
134     printhead(ac, av) /* print command header */
135     register int ac;
136     register char **av;
137     {
138     putchar('#');
139     while (ac--) {
140     putchar(' ');
141     fputs(*av++, stdout);
142     }
143     putchar('\n');
144     }