Back to index

radiance  4R0+20100331
genmarble.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: genmarble.c,v 2.7 2003/11/16 10:29:38 schorsch Exp $";
00003 #endif
00004 /*
00005  *  genmarble.c - generate a marble with bubbles inside.
00006  *
00007  *     1/8/86
00008  */
00009 
00010 #include  <stdio.h>
00011 
00012 #include <stdlib.h>
00013 
00014 #include  <math.h>
00015 
00016 #include  "random.h"
00017 
00018 #define  PI   3.14159265359
00019 
00020 typedef double  FVECT[3];
00021 
00022 static double  bubble();    /* pretty cute, huh? */
00023 static void sphere_cart();
00024 
00025 int
00026 main(argc, argv)
00027 int  argc;
00028 char  **argv;
00029 {
00030        char  *cmtype, *cname;
00031        FVECT  cent;
00032        double  rad;
00033        int  nbubbles, i;
00034        double  bubrad;
00035        FVECT  v;
00036        double  brad;
00037        
00038        if (argc != 9) {
00039               fprintf(stderr,
00040                      "Usage: %s material name cent rad #bubbles bubrad\n",
00041                                     argv[0]);
00042               exit(1);
00043        }
00044        cmtype = argv[1];
00045        cname = argv[2];
00046        cent[0] = atof(argv[3]);
00047        cent[1] = atof(argv[4]);
00048        cent[2] = atof(argv[5]);
00049        rad = atof(argv[6]);
00050        nbubbles = atoi(argv[7]);
00051        bubrad = atof(argv[8]);
00052 
00053        if (bubrad >= rad) {
00054               fprintf(stderr, "%s: bubbles too big for marble\n", argv[0]);
00055               exit(1);
00056        }
00057 
00058        printf("\n%s sphere %s\n", cmtype, cname);
00059        printf("0\n0\n4 %f %f %f %f\n", cent[0], cent[1], cent[2], rad);
00060 
00061        for (i = 0; i < nbubbles; i++) {
00062               brad = bubble(v, cent, rad, bubrad);
00063               printf("\n%s bubble %s.%d\n", cmtype, cname, i);
00064               printf("0\n0\n4 %f %f %f %f\n", v[0], v[1], v[2], brad);
00065        }
00066        
00067        return(0);
00068 }
00069 
00070 
00071 static double
00072 bubble(v, cent, rad, bubrad)       /* compute location of random bubble */
00073 FVECT  v, cent;
00074 double  rad, bubrad;
00075 {
00076        double  r, ro, theta, phi;
00077 
00078        r = frandom()*bubrad;
00079        ro = sqrt(frandom())*(rad-r);
00080        theta = frandom()*(2.0*PI);
00081        phi = frandom()*PI;
00082        sphere_cart(v, ro, theta, phi);
00083        v[0] += cent[0]; v[1] += cent[1]; v[2] += cent[2];
00084        return(r);
00085 }
00086 
00087 
00088 static void
00089 sphere_cart(v, ro, theta, phi)     /* spherical to cartesian coord. conversion */
00090 FVECT  v;
00091 double  ro, theta, phi;
00092 {
00093        double  d;
00094        
00095        d = sin(phi);
00096        v[0] = ro*d*cos(theta);
00097        v[1] = ro*d*sin(theta);
00098        v[2] = ro*cos(phi);
00099 }