/**
* @file sphere.c
* @author Robert S Laramee
* @version 1.0
* @see build_mr_v3.c, expand.c
*
* start date Sat 29 May 1999
* finish date
*
* Description This program generates an isosurface(s) in the shape of a
* sphere. It outputs the data in a format suitable for input
* for build_mr_v3.c
* compile using:
* gcc -Wall sphere.c -o sphere.exe -lm
*/
#include
#include /* for pow(), sqrt() */
double pow(double x, double y);
/* dimensions constants */
#define XROWS 65
#define YCOLUMNS 65
#define ZLAYERS 65
/**
* note:
* 8 x 8 x 8 = 512
* 9 x 9 x 9 = 729
* 16 x 16 x 16 = 4096
* 32 x 32 x 32 = 32,768
* 33 x 33 x 33 = 35,937
*/
int main(int argc, char *argv[]) {
int i = 0;
int sum = 0;
int x,y,z;
float data[XROWS * YCOLUMNS * ZLAYERS];
/* initialize the data set to 0 */
for(z = 0; z < ZLAYERS; z++) {
for(y = 0; y < YCOLUMNS; y++) {
for(x = 0; x < XROWS; x++) {
data[i] = 0.0;
i++; /* i++ --> "Bus error" */
}
}
}
i = 0;
/* populate the data set */
for(z = 0; z < ZLAYERS; z++) {
for(y = 0; y < YCOLUMNS; y++) {
for(x = 0; x < XROWS; x++) {
sum = ( (x - (XROWS /2)) * (x - (XROWS /2)) +
(y - (YCOLUMNS/2)) * (y - (YCOLUMNS/2)) +
(z - (ZLAYERS /2)) * (z - (ZLAYERS /2))
);
if ( sum < (XROWS/2)*(XROWS/2) ) {
data[i] = 1.0;
}
i++;
}
}
}
i = 0;
/* print the data set */
for(z = 0; z < ZLAYERS; z++) {
for(y = 0; y < YCOLUMNS; y++) {
for(x = 0; x < XROWS; x++) {
printf("%f\n", data[i]);
i++;
}
}
}
return 0;
}