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

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1986 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * genmarble.c - generate a marble with bubbles inside.
9     *
10     * 1/8/86
11     */
12    
13     #include <stdio.h>
14    
15 greg 2.3 #include <math.h>
16    
17 greg 1.1 #include "random.h"
18    
19     #define PI 3.14159265359
20    
21     typedef double FVECT[3];
22    
23     double bubble(); /* pretty cute, huh? */
24    
25 greg 2.4 #ifdef DCL_ATOF
26     extern double atof();
27     #endif
28    
29 greg 1.1
30     main(argc, argv)
31     int argc;
32     char **argv;
33     {
34     char *cmtype, *cname;
35     FVECT cent;
36     double rad;
37     int nbubbles, i;
38     double bubrad;
39     FVECT v;
40     double brad;
41    
42     if (argc != 9) {
43     fprintf(stderr,
44     "Usage: %s material name cent rad #bubbles bubrad\n",
45     argv[0]);
46     exit(1);
47     }
48     cmtype = argv[1];
49     cname = argv[2];
50     cent[0] = atof(argv[3]);
51     cent[1] = atof(argv[4]);
52     cent[2] = atof(argv[5]);
53     rad = atof(argv[6]);
54     nbubbles = atoi(argv[7]);
55     bubrad = atof(argv[8]);
56    
57     if (bubrad >= rad) {
58     fprintf(stderr, "%s: bubbles too big for marble\n", argv[0]);
59     exit(1);
60     }
61    
62     printf("\n%s sphere %s\n", cmtype, cname);
63     printf("0\n0\n4 %f %f %f %f\n", cent[0], cent[1], cent[2], rad);
64    
65     for (i = 0; i < nbubbles; i++) {
66     brad = bubble(v, cent, rad, bubrad);
67     printf("\n%s bubble %s.%d\n", cmtype, cname, i);
68     printf("0\n0\n4 %f %f %f %f\n", v[0], v[1], v[2], brad);
69     }
70    
71     return(0);
72     }
73    
74    
75     double
76     bubble(v, cent, rad, bubrad) /* compute location of random bubble */
77     FVECT v, cent;
78     double rad, bubrad;
79     {
80     double r, ro, theta, phi;
81    
82     r = frandom()*bubrad;
83     ro = sqrt(frandom())*(rad-r);
84     theta = frandom()*(2.0*PI);
85     phi = frandom()*PI;
86     sphere_cart(v, ro, theta, phi);
87     v[0] += cent[0]; v[1] += cent[1]; v[2] += cent[2];
88     return(r);
89     }
90    
91    
92     sphere_cart(v, ro, theta, phi) /* spherical to cartesian coord. conversion */
93     FVECT v;
94     double ro, theta, phi;
95     {
96     double d;
97    
98     d = sin(phi);
99     v[0] = ro*d*cos(theta);
100     v[1] = ro*d*sin(theta);
101     v[2] = ro*cos(phi);
102     }