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