All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Constructing a Sphere (Posted on 2012-02-25) Difficulty: 3 of 5
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:

d=√[(x2-x1)2+(y2-y1)2+(z2-z1)2]

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.

No Solution Yet Submitted by Dustin    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Excel implementation of Specific Algorithm | Comment 4 of 16 |
Well, Brian, I can't be much more specific, but since you ask, here is an actual working Excel implementation of the algorithm

Cell A2: 'Radius
Cell B2: 9
Cell A3: 'Layer
Cell B3: 5

Cells E2 .. Z2:  1, 2, 3 ,4 ...21,22
Cells D3 .. D24: 1, 2, 3 ,4 ...21,22

Cell  E3:  =IF(POWER($D3-$B$2-0.5,2)+POWER(E$2-$B$2-0.5,2)+POWER($B$3-$B$2-0.5,2)<=POWER($B$2,2),"X","") 

Copy cell E3 to E3 .. Z24

This colors any included cubes with an X for a given radius and layer.

/*********************/ 
Amended 2/26 to fix a small typo noted by dustin

Edited on February 26, 2012, 6:27 pm
  Posted by Steve Herman on 2012-02-26 12:58:08

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information