# Returning a List of coords for a sphere in order of inside to outside

I'm looking for any algorithm that can return a list of Vector3 coordinates that form a sphere. If you read the list from the beginning it would appear the sphere was expanding.

The only algorithms I've found are for circles, the algorithm doesn't have to make a sphere of a particular radius, just a number of coordinates would be fine.

If anyone could point me in the right direction for such an algorithm that would be great. Any language or even just sudo code for a basic algorithm would be appreciated.

• Can you explain in more detail what you're trying to achieve (or possibly point us to one of the algorithms you've found fir circles)? As the question stands now I'm not sure I understand what you're looking for. – bornander Nov 3 '15 at 7:24
• I'm looking for an algorithm that will generate a sphere built out of cubes. The algorithm should start in the center and add cubes from the inside out to form a sphere. I'm looking for an algorithm that could add those coordinates of the cubes, in order (from the center of the sphere to outside of the sphere) to a List. – user3475821 Nov 3 '15 at 7:34
• The thing is I don't want the list to add coordinates that would build the sphere from bottom to top or left to right, I need the list to be in order of proximity to the center of the sphere. – user3475821 Nov 3 '15 at 7:36
• The order the algorithm works in doesn't matter then, I guess, as you can always sort the list it produces by the distance from the center of the sphere? – bornander Nov 3 '15 at 7:40
• I could do that however couldn't that put limitations on it's efficiency? – user3475821 Nov 3 '15 at 7:48

If I understood what you're asking , you can start from Spherical coordinate system

Very pseudo code to "list" a sphere from top to bottom:

Let PI = 3.14...

Let's use degrees.

For theta =0..180
For phi =0..360


Where PolarToCartesian:

x=r * sin(toRad(theta)) * cos(toRad(phi))