ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genmarble.c
Revision: 2.3
Committed: Fri Jun 4 14:31:11 1993 UTC (30 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +2 -6 lines
Log Message:
Removed unnecessary declaration of atof()

File Contents

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