ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genmarble.c
Revision: 2.1
Committed: Tue Nov 12 17:04:39 1991 UTC (32 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +0 -0 lines
Log Message:
updated revision number for release 2.0

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 "random.h"
16
17
18 #define PI 3.14159265359
19
20 typedef double FVECT[3];
21
22 double bubble(); /* pretty cute, huh? */
23
24
25 main(argc, argv)
26 int argc;
27 char **argv;
28 {
29 double atof();
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 sqrt();
77 double r, ro, theta, phi;
78
79 r = frandom()*bubrad;
80 ro = sqrt(frandom())*(rad-r);
81 theta = frandom()*(2.0*PI);
82 phi = frandom()*PI;
83 sphere_cart(v, ro, theta, phi);
84 v[0] += cent[0]; v[1] += cent[1]; v[2] += cent[2];
85 return(r);
86 }
87
88
89 sphere_cart(v, ro, theta, phi) /* spherical to cartesian coord. conversion */
90 FVECT v;
91 double ro, theta, phi;
92 {
93 double sin(), cos();
94 double d;
95
96 d = sin(phi);
97 v[0] = ro*d*cos(theta);
98 v[1] = ro*d*sin(theta);
99 v[2] = ro*cos(phi);
100 }