ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/gencat.c
Revision: 2.3
Committed: Sat Feb 22 02:07:23 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.2: +2 -8 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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