I would like to construct a sphere by gluing unit cubes together. I'm only attempting to approximate the shape of a sphere as closely as is possible with unit cubes.
Before I get out the glue, how would I go about creating a spreadsheet that would show me the quantity and placement of cubes in each cross-sectional layer? (think of an MRI scan cross-section)
For input, the spreadsheet should ask for the radius of the sphere to be built, as well as which layer of that sphere should be displayed.
There may be more than one way to accomplish this. Any spreadsheet that will allow me to build a sphere by displaying each layer of a sphere for a given radius is considered valid.
Here is an example of output:
Hint: The formula for distance in 3 dimensions is:
Bonus question! Adjust your algorithm to display a hollow sphere (think of a ping pong ball, or a beach ball). Note: All cubes must be connected into one contiguous piece.
I have amended my post to fix the small typo that you pointed out.
As for the bonus question, I have two thoughts
a) If you are not concerned about a maximally hollow sphere, you could just color the cell as white if the center of the cube is within a sphere of radius (R - 1.5). In other words, 1.5 units less than the target radius. This results, however, in a slightly over-engineered solid, in that there are a few more interior cubes than needed to make sure that each layer is created out of contiguous cubes. The formula for cell E3 becomes:
b) If you want a maximally hollow square, I think that you need to use an iterative formula, filling in a cell if the cell that is 1 further out horizontally and vertically is filled in, but the cell that is 1 further out diagonally is not. Just to simplify this, I would probably put math formulas into just 1/4 of the spreadsheet area, and populate the other 3/4 by setting the formulas to just be mirror images of the math-calculated area.