ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genmarble.c
Revision: 2.5
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.4: +3 -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

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * genmarble.c - generate a marble with bubbles inside.
6 *
7 * 1/8/86
8 */
9
10 #include <stdio.h>
11
12 #include <stdlib.h>
13
14 #include <math.h>
15
16 #include "random.h"
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 char *cmtype, *cname;
30 FVECT cent;
31 double rad;
32 int nbubbles, i;
33 double bubrad;
34 FVECT v;
35 double brad;
36
37 if (argc != 9) {
38 fprintf(stderr,
39 "Usage: %s material name cent rad #bubbles bubrad\n",
40 argv[0]);
41 exit(1);
42 }
43 cmtype = argv[1];
44 cname = argv[2];
45 cent[0] = atof(argv[3]);
46 cent[1] = atof(argv[4]);
47 cent[2] = atof(argv[5]);
48 rad = atof(argv[6]);
49 nbubbles = atoi(argv[7]);
50 bubrad = atof(argv[8]);
51
52 if (bubrad >= rad) {
53 fprintf(stderr, "%s: bubbles too big for marble\n", argv[0]);
54 exit(1);
55 }
56
57 printf("\n%s sphere %s\n", cmtype, cname);
58 printf("0\n0\n4 %f %f %f %f\n", cent[0], cent[1], cent[2], rad);
59
60 for (i = 0; i < nbubbles; i++) {
61 brad = bubble(v, cent, rad, bubrad);
62 printf("\n%s bubble %s.%d\n", cmtype, cname, i);
63 printf("0\n0\n4 %f %f %f %f\n", v[0], v[1], v[2], brad);
64 }
65
66 return(0);
67 }
68
69
70 double
71 bubble(v, cent, rad, bubrad) /* compute location of random bubble */
72 FVECT v, cent;
73 double rad, bubrad;
74 {
75 double r, ro, theta, phi;
76
77 r = frandom()*bubrad;
78 ro = sqrt(frandom())*(rad-r);
79 theta = frandom()*(2.0*PI);
80 phi = frandom()*PI;
81 sphere_cart(v, ro, theta, phi);
82 v[0] += cent[0]; v[1] += cent[1]; v[2] += cent[2];
83 return(r);
84 }
85
86
87 sphere_cart(v, ro, theta, phi) /* spherical to cartesian coord. conversion */
88 FVECT v;
89 double ro, theta, phi;
90 {
91 double d;
92
93 d = sin(phi);
94 v[0] = ro*d*cos(theta);
95 v[1] = ro*d*sin(theta);
96 v[2] = ro*cos(phi);
97 }