Open In App

LS3/NS3 sphere generation algorithm and its implementation

Last Updated : 23 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Given center of the sphere and its radius. your task is to store efficiently all the integer points required to show a sphere on the computer screen of pixels and This algorithm will generate naive sphere by creating voxels by its naive arcs. NS3 stands for naive sphere by sum of squares and LS3 stands for lattice sphere by sum of squares. 

Examples:

Input : Center(0, 0, 0) Radius 1
Output : (-1, 0, 0), (0, 0, 1), (0, 0, -1), (0, 1, 0),
(0, -1, 0), (1, 0, 0)
6(Total no. of points)
Input : Center(0, 0, 0) Radius 2
Output :(-2, 0, 0)(-1, 1, 1)(-1, -1, 1)(-1, 1, -1)
(-1, -1, -1)(0, 0, 2)(0, 0, -2)(0, 2, 0)
(0, -2, 0)(0, 1, 2)(0, 2, 1)(0, -1, 2)
(0, 1, -2)(0, -1, -2)(0, -2, 1)(0, 2, -1)
(0, -2, -1)(1, 2, 0)(1, 0, 2)(1, -2, 0)
(1, 2, 0)(1, -2, 0)(1, 0, -2)(1, 0, 2)
(1, 0, -2)(1, 1, 1)(1, -1, 1)(1, 1, -1)
(1, -1, -1)(2, 0, 0)(2, 0, 1)(2, 0, 1)
(2, 0, -1)(2, 0, -1)(2, 1, 0)(2, -1, 0)
(2, 1, 0)(2, -1, 0)
38 (Total no. of points)


I strongly suggest you that if you do not have any prerequisites in this field than go to below link. This will help you to gain some prerequisites and concepts which are required to understand the following implementation and algorithm. 

Algorithm LS3 primarily focuses on generating the voxels of prima quadraginta . prima quadraginta is formed when a discrete sphere is partitioned into 48 parts such that all 48 parts having some symmetrical relation and they all can be generated by using any one of its parts. that one part is called as prima quadraginta (see figure 2). similarly, quadraginta octant defined as same as prima qudraginta except that it is partitioned into 8 equal parts instead of 48. quadaginta octant contains 6 prima quadraginta which are clearly shown in the figure below. Q denotes to prima quadraginta (q-octant) and C denotes to quadraginta octant(c-octant).a naive arc are those set of voxels which are having same x coordinate in prima quadraginta (in above figure, the red voxels are making a naive arc). By dint of 48 symmetric property, a whole discrete sphere can be developed from its prima quadraginta. the limitation of using 48 symmetry is that some of the voxels of q-octant will be repeated because they are sharing an edge or voxels with other adjacent prima quadraginta. for example, In above figure, the voxels shown in grey belongs to two or more q-octants

Our algorithm will generate some repeated voxels therefore, we need to make some restrictions on input voxels. In order to do this, I have included some functions in my implementation which are: All these methods principally focuses on grey voxels (See above figure) expect one putpixelall() which is going to produce all voxels except grey voxels by using 48 symmetry without any restrictions. 

putpixeledge1 : This function will produce all voxels which has exactly one coordinate zero and if we proceed to find another voxel using symmetry and take an image with respect to that zero coordinate axis (this (0, 2, -1) voxel will have the same image if we take an image with respect to the x-axis) then it comes out to be the same voxel. 

putpixeledge2 : These set of voxels having x and y coordinate are same (see prima quadraginta figure 2).In order to store these voxels we have to look for a relation between q1 and q2 octants( see above table). you can achieve the general coordinate of any voxel in q2 from q1 by swapping first (x, y) and then (y, z). 

putpixelsingle : These pixels is very less in count.they are situated in the middle of quadraginta octant (c octant) and shared with all the q-octants which are lying in the same c-octant. to obtained these voxels we can see the above table and write all the voxels corresponding to its c-octant. 

putpixeldouble : These set of voxels having y and z coordinate are same (see prima qudraginta figure 2).In order to store these voxels we need to find a relation between q1 and q6 octants( see table). you can achieve the general coordinate of any voxel in q6 from q1 by swapping first (y, z) and then (x, y). 

putpixelmiddle : These set of voxels are located in those points where exactly two coordinate value is NULL which can help us to find to obtain the coordinates of these voxels( you can write the coordinates of these voxels manually). We need an efficient storage of all the integer points (voxels) which will be formed by this algorithm. In order to store these points, we will use hashmap and key value of hashmap will be x coordinate of point and data value will be linked list of pair of y and z coordinate. 

CPP
#include <iostream>
#include <cmath>

// this header file contains get<0> and get<1> function
#include <utility>

#include <list>
#include <map>
using namespace std;

// map to store the voxels
map<int, list<pair<int, int> > > mymap;
map<int, list<pair<int, int> > >::iterator itr;

// this function will store single voxel
void putpixelone(int m, int n, int p)
{
    mymap[m].push_back(make_pair(n, p));
}

// function to store some particular type of voxel
void putpixelmiddle(int a, int b, int c, int x, int y, int z)
{
    putpixelone(a + x, b + y, c + z);
    putpixelone(a + x, b + y, -c + z);
    putpixelone(a + x, c + y, b + z);
    putpixelone(a + x, -c + y, b + z);
    putpixelone(c + x, a + y, b + z);
    putpixelone(-c + x, a + y, b + z);
}

// This program will generate 24 voxels
void putpixeldouble(int a, int b, int c, int x, int y, int z)
{
    for (int j = 0; j < 3; j++) {
        putpixelone(a + x, b + y, c + z);
        swap(b, c);
        swap(a, b);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(-a + x, b + y, c + z);
        swap(b, c);
        swap(a, b);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(a + x, -b + y, c + z);
        swap(b, c);
        swap(a, b);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(-a + x, -b + y, c + z);
        swap(b, c);
        swap(a, b);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(a + x, b + y, -c + z);
        swap(b, c);
        swap(a, b);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(-a + x, b + y, -c + z);
        swap(b, c);
        swap(a, b);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(a + x, -b + y, -c + z);
        swap(b, c);
        swap(a, b);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(-a + x, -b + y, -c + z);
        swap(b, c);
        swap(a, b);
    }
}

// Explained above
void putpixelsingle(int a, int b, int c, int x,
                    int y, int z)
{
    putpixelone(a + x, b + y, c + z);
    putpixelone(-a + x, b + y, c + z);
    putpixelone(a + x, -b + y, c + z);
    putpixelone(-a + x, -b + y, c + z);
    putpixelone(a + x, b + y, -c + z);
    putpixelone(-a + x, b + y, -c + z);
    putpixelone(a + x, -b + y, -c + z);
    putpixelone(-a + x, -b + y, -c + z);
}
// This program will generate 24 voxels.
void putpixeledge2(int a, int b, int c, int x,
                int y, int z)
{

    for (int j = 0; j < 3; j++) {
        putpixelone(a + x, b + y, c + z);
        swap(a, b);
        swap(b, c);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(-a + x, b + y, c + z);
        swap(a, b);
        swap(b, c);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(a + x, -b + y, c + z);
        swap(a, b);
        swap(b, c);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(-a + x, -b + y, c + z);
        swap(a, b);
        swap(b, c);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(a + x, b + y, -c + z);
        swap(a, b);
        swap(b, c);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(-a + x, b + y, -c + z);
        swap(a, b);
        swap(b, c);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(a + x, -b + y, -c + z);
        swap(a, b);
        swap(b, c);
    }
    for (int j = 0; j < 3; j++) {
        putpixelone(-a + x, -b + y, -c + z);
        swap(a, b);
        swap(b, c);
    }
}
// after excluding the repeated pixels from the set all 48
// pixels we will left with only 24 pixels so, we have
// defined all the voxels given below.
void putpixeledge1(int a, int b, int c, int x, int y, int z)
{
    putpixelone(a + x, b + y, c + z);
    putpixelone(a + x, c + y, b + z);
    putpixelone(a + x, -b + y, c + z);
    putpixelone(a + x, b + y, -c + z);
    putpixelone(a + x, -b + y, -c + z);
    putpixelone(a + x, -c + y, b + z);
    putpixelone(a + x, c + y, -b + z);
    putpixelone(a + x, -c + y, -b + z);
    putpixelone(b + x, c + y, a + z);
    putpixelone(b + x, a + y, c + z);
    putpixelone(b + x, -c + y, a + z);
    putpixelone(b + x, c + y, -a + z);
    putpixelone(b + x, -c + y, -a + z);
    putpixelone(b + x, a + y, -c + z);
    putpixelone(b + x, -a + y, c + z);
    putpixelone(b + x, -a + y, -c + z);
    putpixelone(c + x, a + y, b + z);
    putpixelone(c + x, -a + y, b + z);
    putpixelone(c + x, a + y, -b + z);
    putpixelone(c + x, -a + y, -b + z);
    putpixelone(c + x, b + y, a + z);
    putpixelone(c + x, -b + y, a + z);
    putpixelone(c + x, b + y, -a + z);
    putpixelone(c + x, -b + y, -a + z);
}

// voxel formation by 48 symmetry.
void putpixelall(int a, int b, int c, int x,
                int y, int z)
{
    putpixelone(a + x, b + y, c + z);
    putpixelone(b + x, a + y, c + z);
    putpixelone(c + x, b + y, a + z);
    putpixelone(a + x, c + y, b + z);
    putpixelone(c + x, a + y, b + z);
    putpixelone(b + x, c + y, a + z);
    putpixelone(-a + x, -b + y, c + z);
    putpixelone(-b + x, -a + y, c + z);
    putpixelone(c + x, -b + y, -a + z);
    putpixelone(-a + x, c + y, -b + z);
    putpixelone(c + x, -a + y, -b + z);
    putpixelone(-b + x, c + y, -a + z);
    putpixelone(a + x, -b + y, -c + z);
    putpixelone(-b + x, a + y, -c + z);
    putpixelone(-c + x, -b + y, a + z);
    putpixelone(a + x, -c + y, -b + z);
    putpixelone(-c + x, a + y, -b + z);
    putpixelone(-b + x, -c + y, a + z);
    putpixelone(-a + x, b + y, -c + z);
    putpixelone(b + x, -a + y, -c + z);
    putpixelone(-c + x, b + y, -a + z);
    putpixelone(-a + x, -c + y, b + z);
    putpixelone(-c + x, -a + y, b + z);
    putpixelone(b + x, -c + y, -a + z);
    putpixelone(-a + x, b + y, c + z);
    putpixelone(b + x, -a + y, c + z);
    putpixelone(c + x, b + y, -a + z);
    putpixelone(-a + x, c + y, b + z);
    putpixelone(c + x, -a + y, b + z);
    putpixelone(b + x, c + y, -a + z);
    putpixelone(a + x, -b + y, c + z);
    putpixelone(-b + x, a + y, c + z);
    putpixelone(c + x, -b + y, a + z);
    putpixelone(a + x, c + y, -b + z);
    putpixelone(c + x, a + y, -b + z);
    putpixelone(-b + x, c + y, a + z);
    putpixelone(a + x, b + y, -c + z);
    putpixelone(b + x, a + y, -c + z);
    putpixelone(-c + x, b + y, a + z);
    putpixelone(a + x, -c + y, b + z);
    putpixelone(-c + x, a + y, b + z);
    putpixelone(b + x, -c + y, a + z);
    putpixelone(-a + x, -b + y, -c + z);
    putpixelone(-b + x, -a + y, -c + z);
    putpixelone(-c + x, -b + y, -a + z);
    putpixelone(-a + x, -c + y, -b + z);
    putpixelone(-c + x, -a + y, -b + z);
    putpixelone(-b + x, -c + y, -a + z);
}

// detailed explanation of this algorithm is
// given in above link.
void drawsphere(int x, int y, int z, int r)
{
    int i = 0, j = 0;
    int k0 = r;
    int k = k0;
    int s0 = 0;
    int s = s0;
    int v0 = r - 1;
    int v = v0;
    int l0 = 2 * v0;
    int l = l0;

    // this while loop will form naive arcs
    while (i <= k) {

        // this while will form voxels in naive arcs
        while (j <= k) {
            if (s > v) {
                k = k - 1;
                v = v + l;
                l = l - 2;
            }
            if ((j <= k) && ((s != v) || (j != k))) {

                // this if, else and else if condition
                // can easily build using figure 2, 3
                if (i == 0 && j != 0)

                    // First naive arc pixels and each
                    // pixel is shared with two q-octants
                    putpixeledge1(i, j, k, x, y, z);

                // voxels shared between q1 and q2
                else if (i == j && j != k && i != 0)
                    putpixeledge2(i, j, k, x, y, z);

                // center voxel of c-octants
                else if (i == j && j == k)
                    putpixelsingle(i, j, k, x, y, z);

                // voxels shared between q1 and q6
                else if (j == k && i < k && i < j)
                    putpixeldouble(i, j, k, x, y, z);

                // starting voxel of q-octant
                else if (i == 0 && j == 0)
                    putpixelmiddle(i, j, k, x, y, z);

                // voxels inside the q-octant
                else
                    putpixelall(i, j, k, x, y, z);
            }
            s = s + 2 * j + 1;
            j = j + 1;
        }
        s0 = s0 + 4 * i + 2;
        i = i + 1;

        while ((s0 > v0) && (i <= k0)) {
            k0 = k0 - 1;
            v0 = v0 + l0;
            l0 = l0 - 2;
        }
        j = i;
        k = k0;
        v = v0;
        l = l0;
        s = s0;
    }
}
// Print out all the voxels of discrete sphere
void showallpoints(map<int, list<pair<int, int> > >& mymap)
{
    int count = 0;

    for (itr = mymap.begin(); itr != mymap.end(); ++itr) {
        list<pair<int, int> > l = itr->second;
        list<pair<int, int> >::iterator it;
        for (it = l.begin(); it != l.end(); ++it) {
            cout << itr->first << ", " << get<0>(*it)
                << ", " << get<1>(*it) << endl;
            count += 1;
        }
    }
    cout << endl;
    cout << count << endl;
}
// Driver program
int main()
{
    int cx, cy, cz;
    cin >> cx >> cy >> cz;
    int r;
    cin >> r;
    drawsphere(cx, cy, cz, r);
    showallpoints(mymap);
}
Java
import java.util.*;

public class Main {
    // Map to store the voxels
    static Map<Integer, List<Pair<Integer, Integer>>> mymap = new HashMap<>();

    // Class to represent a pair of integers
    static class Pair<F, S> {
        public F first;
        public S second;

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }

    // This function will store single voxel
    static void putpixelone(int m, int n, int p) {
        if (!mymap.containsKey(m)) {
            mymap.put(m, new ArrayList<>());
        }
        mymap.get(m).add(new Pair<>(n, p));
    }

    // Function to store some particular type of voxel
    static void putpixelmiddle(int a, int b, int c, int x, int y, int z) {
        putpixelone(a + x, b + y, c + z);
        putpixelone(a + x, b + y, -c + z);
        putpixelone(a + x, c + y, b + z);
        putpixelone(a + x, -c + y, b + z);
        putpixelone(c + x, a + y, b + z);
        putpixelone(-c + x, a + y, b + z);
    }

    // This program will generate 24 voxels
    static void putpixeldouble(int a, int b, int c, int x, int y, int z) {
        for (int j = 0; j < 3; j++) {
            putpixelone(a + x, b + y, c + z);
            int temp = b;
            b = c;
            c = a;
            a = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(-a + x, b + y, c + z);
            int temp = b;
            b = c;
            c = a;
            a = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(a + x, -b + y, c + z);
            int temp = b;
            b = c;
            c = a;
            a = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(-a + x, -b + y, c + z);
            int temp = b;
            b = c;
            c = a;
            a = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(a + x, b + y, -c + z);
            int temp = b;
            b = c;
            c = a;
            a = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(-a + x, b + y, -c + z);
            int temp = b;
            b = c;
            c = a;
            a = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(a + x, -b + y, -c + z);
            int temp = b;
            b = c;
            c = a;
            a = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(-a + x, -b + y, -c + z);
            int temp = b;
            b = c;
            c = a;
            a = temp;
        }
    }

    // Explained above
    static void putpixelsingle(int a, int b, int c, int x, int y, int z) {
        putpixelone(a + x, b + y, c + z);
        putpixelone(-a + x, b + y, c + z);
        putpixelone(a + x, -b + y, c + z);
        putpixelone(-a + x, -b + y, c + z);
        putpixelone(a + x, b + y, -c + z);
        putpixelone(-a + x, b + y, -c + z);
        putpixelone(a + x, -b + y, -c + z);
        putpixelone(-a + x, -b + y, -c + z);
    }

    // This program will generate 24 voxels.
    static void putpixeledge2(int a, int b, int c, int x, int y, int z) {
        for (int j = 0; j < 3; j++) {
            putpixelone(a + x, b + y, c + z);
            int temp = a;
            a = b;
            b = c;
            c = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(-a + x, b + y, c + z);
            int temp = a;
            a = b;
            b = c;
            c = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(a + x, -b + y, c + z);
            int temp = a;
            a = b;
            b = c;
            c = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(-a + x, -b + y, c + z);
            int temp = a;
            a = b;
            b = c;
            c = temp;
        }
                for (int j = 0; j < 3; j++) {
            putpixelone(a + x, b + y, -c + z);
            int temp = a;
            a = b;
            b = c;
            c = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(-a + x, b + y, -c + z);
            int temp = a;
            a = b;
            b = c;
            c = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(a + x, -b + y, -c + z);
            int temp = a;
            a = b;
            b = c;
            c = temp;
        }
        for (int j = 0; j < 3; j++) {
            putpixelone(-a + x, -b + y, -c + z);
            int temp = a;
            a = b;
            b = c;
            c = temp;
        }
    }

    // After excluding the repeated pixels from the set all 48
    // pixels we will left with only 24 pixels so, we have
    // defined all the voxels given below.
    static void putpixeledge1(int a, int b, int c, int x, int y, int z) {
        putpixelone(a + x, b + y, c + z);
        putpixelone(a + x, c + y, b + z);
        putpixelone(a + x, -b + y, c + z);
        putpixelone(a + x, b + y, -c + z);
        putpixelone(a + x, -b + y, -c + z);
        putpixelone(a + x, -c + y, b + z);
        putpixelone(a + x, c + y, -b + z);
        putpixelone(a + x, -c + y, -b + z);
        putpixelone(b + x, c + y, a + z);
        putpixelone(b + x, a + y, c + z);
        putpixelone(b + x, -c + y, a + z);
        putpixelone(b + x, c + y, -a + z);
        putpixelone(b + x, -c + y, -a + z);
        putpixelone(b + x, a + y, -c + z);
        putpixelone(b + x, -a + y, c + z);
        putpixelone(b + x, -a + y, -c + z);
        putpixelone(c + x, a + y, b + z);
        putpixelone(c + x, -a + y, b + z);
        putpixelone(c + x, a + y, -b + z);
        putpixelone(c + x, -a + y, -b + z);
        putpixelone(c + x, b + y, a + z);
        putpixelone(c + x, -b + y, a + z);
        putpixelone(c + x, b + y, -a + z);
        putpixelone(c + x, -b + y, -a + z);
    }

    // Voxel formation by 48 symmetry.
    static void putpixelall(int a, int b, int c, int x, int y, int z) {
        putpixelone(a + x, b + y, c + z);
        putpixelone(b + x, a + y, c + z);
        putpixelone(c + x, b + y, a + z);
        putpixelone(a + x, c + y, b + z);
        putpixelone(c + x, a + y, b + z);
        putpixelone(b + x, c + y, a + z);
        putpixelone(-a + x, -b + y, c + z);
        putpixelone(-b + x, -a + y, c + z);
        putpixelone(c + x, -b + y, -a + z);
        putpixelone(-a + x, c + y, -b + z);
        putpixelone(c + x, -a + y, -b + z);
        putpixelone(-b + x, c + y, -a + z);
        putpixelone(a + x, -b + y, -c + z);
        putpixelone(-b + x, a + y, -c + z);
        putpixelone(-c + x, -b + y, a + z);
        putpixelone(a + x, -c + y, b + z);
        putpixelone(-c + x, a + y, b + z);
        putpixelone(b + x, -c + y, a + z);
        putpixelone(-a + x, b + y, -c + z);
        putpixelone(b + x, -a + y, -c + z);
        putpixelone(c + x, b + y, -a + z);
        putpixelone(-a + x, -c + y, b + z);
        putpixelone(-c + x, -a + y, b + z);
        putpixelone(b + x, -c + y, -a + z);
        putpixelone(-a + x, b + y, c + z);
        putpixelone(b + x, -a + y, c + z);
        putpixelone(c + x, b + y, -a + z);
        putpixelone(-a + x, c + y, b + z);
        putpixelone(c + x, -a + y, b + z);
        putpixelone(b + x, c + y, -a + z);
        putpixelone(a + x, -b + y, c + z);
        putpixelone(-b + x, a + y, c + z);
        putpixelone(c + x, -b + y, a + z);
        putpixelone(a + x, c + y, -b + z);
        putpixelone(c + x, a + y, -b + z);
        putpixelone(-b + x, c + y, a + z);
        putpixelone(a + x, b + y, -c + z);
        putpixelone(b + x, a + y, -c + z);
        putpixelone(-c + x, b + y, a + z);
        putpixelone(a + x, -c + y, b + z);
        putpixelone(-c + x, a + y, b + z);
        putpixelone(b + x, -c + y, a + z);
        putpixelone(-a + x, -b + y, -c + z);
        putpixelone(-b + x, -a + y, -c + z);
        putpixelone(-c + x, -b + y, -a + z);
        putpixelone(-a + x, -c + y, -b + z);
        putpixelone(-c + x, -a + y, -b + z);
        putpixelone(-b + x, -c + y, -a + z);
    }

    // Detailed explanation of this algorithm is given in above link.
    static void drawsphere(int x, int y, int z, int r) {
        int i = 0, j = 0;
        int k0 = r;
        int k = k0;
        int s0 = 0;
        int s = s0;
        int v0 = r - 1;
        int v = v0;
        int l0 = 2 * v0;
        int l = l0;

        // This while loop will form naive arcs
        while (i <= k) {

            // This while will form voxels in naive arcs
            while (j <= k) {
                if (s > v) {
                    k = k - 1;
                    v = v + l;
                    l = l - 2;
                }
                if ((j <= k) && ((s != v) || (j != k))) {

                    // This if, else and else if condition
                    // can easily build using figure 2, 3
                    if (i == 0 && j != 0)

                        // First naive arc pixels and each
                        // pixel is shared with two q-octants
                        putpixeledge1(i, j, k, x, y, z);

                    // Voxels shared between q1 and q2
                    else if (i == j && j != k && i != 0)
                        putpixeledge2(i, j, k, x, y, z);

                    // Center voxel of c-octants
                    else if (i == j && j == k)
                        putpixelsingle(i, j, k, x, y, z);

                    // Voxels shared between q1 and q6
                    else if (j == k && i < k && i < j)
                        putpixeldouble(i, j, k, x, y, z);

                    // Starting voxel of q-octant
                    else if (i == 0 && j == 0)
                        putpixelmiddle(i, j, k, x, y, z);

                    // Voxels inside the q-octant
                    else
                        putpixelall(i, j, k, x, y, z);
                        }
                        s = s + 2 * j + 1;
                        j = j + 1;
                    }
                    s0 = s0 + 4 * i + 2;
                    i = i + 1;

                    while ((s0 > v0) && (i <= k0)) {
                        k0 = k0 - 1;
                        v0 = v0 + l0;
                        l0 = l0 - 2;
                    }
                    j = i;
                    k = k0;
                    v = v0;
                    l = l0;
                    s = s0;
                    }
                    }

        // Print out all the voxels of discrete sphere
        static void showallpoints(Map<Integer, List<Pair<Integer, Integer>>> mymap) {
            int count = 0;

            for (Map.Entry<Integer, List<Pair<Integer, Integer>>> entry : mymap.entrySet()) {
                List<Pair<Integer, Integer>> l = entry.getValue();
                for (Pair<Integer, Integer> pair : l) {
                    System.out.println(entry.getKey() + ", " + pair.first + ", " + pair.second);
                    count += 1;
                }
            }
            System.out.println();
            System.out.println(count);
        }

        // Driver program
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int cx = scanner.nextInt();
            int cy = scanner.nextInt();
            int cz = scanner.nextInt();
            int r = scanner.nextInt();
            drawsphere(cx, cy, cz, r);
            showallpoints(mymap);
        }
}
C#
using System;
using System.Collections.Generic;

class Program
{
    // Dictionary to store the voxels
    static Dictionary<int, List<(int, int)>> mymap = new Dictionary<int, List<(int, int)>>();

    // Method to store single voxel
    static void PutPixelOne(int m, int n, int p)
    {
        if (!mymap.ContainsKey(m))
        {
            mymap[m] = new List<(int, int)>();
        }
        mymap[m].Add((n, p));
    }

    // Method to store some particular type of voxel
    static void PutPixelMiddle(int a, int b, int c, int x, int y, int z)
    {
        PutPixelOne(a + x, b + y, c + z);
        PutPixelOne(a + x, b + y, -c + z);
        PutPixelOne(a + x, c + y, b + z);
        PutPixelOne(a + x, -c + y, b + z);
        PutPixelOne(c + x, a + y, b + z);
        PutPixelOne(-c + x, a + y, b + z);
    }

    // This program will generate 24 voxels
    static void PutPixelDouble(int a, int b, int c, int x, int y, int z)
    {
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(a + x, b + y, c + z);
            b = c;
            c = b;
            a = b;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(-a + x, b + y, c + z);
            b = c;
            c = b;
            a = b;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(a + x, -b + y, c + z);
            b = c;
            c = b;
            a = b;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(-a + x, -b + y, c + z);
            b = c;
            c = b;
            a = b;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(a + x, b + y, -c + z);
            b = c;
            c = b;
            a = b;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(-a + x, b + y, -c + z);
            b = c;
            c = b;
            a = b;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(a + x, -b + y, -c + z);
            b = c;
            c = b;
            a = b;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(-a + x, -b + y, -c + z);
            b = c;
            c = b;
            a = b;
        }
    }

    // Explained above
    static void PutPixelSingle(int a, int b, int c, int x, int y, int z)
    {
        PutPixelOne(a + x, b + y, c + z);
        PutPixelOne(-a + x, b + y, c + z);
        PutPixelOne(a + x, -b + y, c + z);
        PutPixelOne(-a + x, -b + y, c + z);
        PutPixelOne(a + x, b + y, -c + z);
        PutPixelOne(-a + x, b + y, -c + z);
        PutPixelOne(a + x, -b + y, -c + z);
        PutPixelOne(-a + x, -b + y, -c + z);
    }

    // This program will generate 24 voxels.
    static void PutPixelEdge2(int a, int b, int c, int x, int y, int z)
    {
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(a + x, b + y, c + z);
            a = b;
            b = a;
            b = a;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(-a + x, b + y, c + z);
            a = b;
            b = a;
            b = a;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(a + x, -b + y, c + z);
            a = b;
            b = a;
            b = a;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(-a + x, -b + y, c + z);
            a = b;
            b = a;
            b = a;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(a + x, b + y, -c + z);
            a = b;
            b = a;
            b = a;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(-a + x, b + y, -c + z);
            a = b;
            b = a;
            b = a;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(a + x, -b + y, -c + z);
            a = b;
            b = a;
            b = a;
        }
        for (int j = 0; j < 3; j++)
        {
            PutPixelOne(-a + x, -b + y, -c + z);
            a = b;
            b = a;
            b = a;
        }
    }

    // After excluding the repeated pixels from the set all 48
    // pixels we will left with only 24 pixels so, we have
    // defined all the voxels given below.
    static void PutPixelEdge1(int a, int b, int c, int x, int y, int z)
    {
        PutPixelOne(a + x, b + y, c + z);
        PutPixelOne(a + x, c + y, b + z);
        PutPixelOne(a + x, -b + y, c + z);
        PutPixelOne(a + x, b + y, -c + z);
        PutPixelOne(a + x, -b + y, -c + z);
        PutPixelOne(a + x, -c + y, b + z);
        PutPixelOne(a + x, c + y, -b + z);
        PutPixelOne(a + x, -c + y, -b + z);
        PutPixelOne(b + x, c + y, a + z);
        PutPixelOne(b + x, a + y, c + z);
        PutPixelOne(b + x, -c + y, a + z);
        PutPixelOne(b + x, c + y, -a + z);
        PutPixelOne(b + x, -c + y, -a + z);
        PutPixelOne(b + x, a + y, -c + z);
        PutPixelOne(b + x, -a + y, c + z);
        PutPixelOne(b + x, -a + y, -c + z);
        PutPixelOne(c + x, a + y, b + z);
        PutPixelOne(c + x, -a + y, b + z);
        PutPixelOne(c + x, a + y, -b + z);
        PutPixelOne(c + x, -a + y, -b + z);
        PutPixelOne(c + x, b + y, a + z);
        PutPixelOne(c + x, -b + y, a + z);
        PutPixelOne(c + x, b + y, -a + z);
        PutPixelOne(c + x, -b + y, -a + z);
    }

    // Voxel formation by 48 symmetry.
    static void PutPixelAll(int a, int b, int c, int x, int y, int z)
    {
        PutPixelOne(a + x, b + y, c + z);
        PutPixelOne(b + x, a + y, c + z);
        PutPixelOne(c + x, b + y, a + z);
        PutPixelOne(a + x, c + y, b + z);
        PutPixelOne(c + x, a + y, b + z);
        PutPixelOne(b + x, c + y, a + z);
        PutPixelOne(-a + x, -b + y, c + z);
        PutPixelOne(-b + x, -a + y, c + z);
        PutPixelOne(c + x, -b + y, -a + z);
        PutPixelOne(-a + x, c + y, -b + z);
        PutPixelOne(c + x, -a + y, -b + z);
        PutPixelOne(-b + x, c + y, -a + z);
        PutPixelOne(a + x, -b + y, -c + z);
        PutPixelOne(-b + x, a + y, -c + z);
        PutPixelOne(-c + x, -b + y, a + z);
        PutPixelOne(a + x, -c + y, -b + z);
        PutPixelOne(-c + x, a + y, -b + z);
        PutPixelOne(-b + x, -c + y, a + z);
        PutPixelOne(-a + x, b + y, -c + z);
        PutPixelOne(b + x, -a + y, -c + z);
        PutPixelOne(-c + x, b + y, -a + z);
        PutPixelOne(-a + x, -c + y, b + z);
        PutPixelOne(-c + x, -a + y, b + z);
        PutPixelOne(b + x, -c + y, -a + z);
        PutPixelOne(-a + x, b + y, c + z);
        PutPixelOne(b + x, -a + y, c + z);
        PutPixelOne(c + x, b + y, -a + z);
        PutPixelOne(-a + x, c + y, b + z);
        PutPixelOne(c + x, -a + y, b + z);
        PutPixelOne(b + x, c + y, -a + z);
        PutPixelOne(a + x, -b + y, c + z);
        PutPixelOne(-b + x, a + y, c + z);
        PutPixelOne(c + x, -b + y, a + z);
        PutPixelOne(a + x, c + y, -b + z);
        PutPixelOne(c + x, a + y, -b + z);
        PutPixelOne(-b + x, c + y, a + z);
        PutPixelOne(a + x, b + y, -c + z);
        PutPixelOne(b + x, a + y, -c + z);
        PutPixelOne(-c + x, b + y, a + z);
        PutPixelOne(a + x, -c + y, b + z);
        PutPixelOne(-c + x, a + y, b + z);
        PutPixelOne(b + x, -c + y, a + z);
        PutPixelOne(-a + x, -b + y, -c + z);
        PutPixelOne(-b + x, -a + y, -c + z);
        PutPixelOne(-c + x, -b + y, -a + z);
        PutPixelOne(-a + x, -c + y, -b + z);
        PutPixelOne(-c + x, -a + y, -b + z);
        PutPixelOne(-b + x, -c + y, -a + z);
    }

    // Detailed explanation of this algorithm is 
    // given in the above link.
    static void DrawSphere(int x, int y, int z, int r)
    {
        int i = 0;
        int j = 0;
        int k0 = r;
        int k = k0;
        int s0 = 0;
        int s = s0;
        int v0 = r - 1;
        int v = v0;
        int l0 = 2 * v0;
        int l = l0;

        // This while loop will form naive arcs
        while (i <= k)
        {
            // This while will form voxels in naive arcs
            while (j <= k)
            {
                if (s > v)
                {
                    k = k - 1;
                    v = v + l;
                    l = l - 2;
                }
                if (j <= k && (s != v || j != k))
                {
                    // This if, else, and else-if condition
                    // can easily build using figures 2, 3
                    if (i == 0 && j != 0)
                    {
                        // First naive arc pixels and each
                        // pixel is shared with two q-octants
                        PutPixelEdge1(i, j, k, x, y, z);
                    }

                    // Voxels shared between q1 and q2
                    else if (i == j && j != k && i != 0)
                    {
                        PutPixelEdge2(i, j, k, x, y, z);
                    }

                    // Center voxel of c-octants
                    else if (i == j && j == k)
                    {
                        PutPixelSingle(i, j, k, x, y, z);
                    }

                    // Voxels shared between q1 and q6
                    else if (j == k && i < k && i < j)
                    {
                        PutPixelDouble(i, j, k, x, y, z);
                    }

                    // Starting voxel of q-octant
                    else if (i == 0 && j == 0)
                    {
                        PutPixelMiddle(i, j, k, x, y, z);
                    }

                    // Voxels inside the q-octant
                    else
                    {
                        PutPixelAll(i, j, k, x, y, z);
                    }
                }
                s = s + 2 * j + 1;
                j = j + 1;
            }
            s0 = s0 + 4 * i + 2;
            i = i + 1;

            while (s0 > v0 && i <= k0)
            {
                k0 = k0 - 1;
                v0 = v0 + l0;
                l0 = l0 - 2;
            }
            j = i;
            k = k0;
            v = v0;
            l = l0;
            s = s0;
        }
    }

    // Print out all the voxels of the discrete sphere
    static void ShowAllPoints(Dictionary<int, List<(int, int)>> mymap)
    {
        int count = 0;
        foreach (var entry in mymap)
        {
            foreach (var value in entry.Value)
            {
                Console.WriteLine($"{entry.Key}, {value.Item1}, {value.Item2}");
                count++;
            }
        }
        Console.WriteLine();
        Console.WriteLine(count);
    }

    // Driver program
    static void Main()
    {
        int cx, cy, cz, r;
        Console.WriteLine("Enter the center coordinates (X Y Z) and radius of the sphere:");
        string[] input = Console.ReadLine().Split();
        cx = int.Parse(input[0]);
        cy = int.Parse(input[1]);
        cz = int.Parse(input[2]);
        r = int.Parse(input[3]);

        DrawSphere(cx, cy, cz, r);
        ShowAllPoints(mymap);
    }
}
Javascript
// Initialize a map to store the voxels
let mymap = new Map();
// Function to store a single voxel
function putpixelone(m, n, p) {
    if (!mymap.has(m)) {
        mymap.set(m, []);
    }
    mymap.get(m).push([n, p]);
}
// Function to generate 48 voxels by symmetry
function putpixelall(a, b, c, x, y, z) {
    // All possible permutations of a, b, c and their negatives
    let permutations = [
        [a, b, c], [b, a, c], [c, b, a], [a, c, b], [c, a, b], [b, c, a],
        [-a, -b, c], [-b, -a, c], [c, -b, -a], [-a, c, -b], [c, -a, -b], [-b, c, -a],
        [a, -b, -c], [-b, a, -c], [-c, -b, a], [a, -c, -b], [-c, a, -b], [b, -c, a],
        [-a, b, -c], [b, -a, -c], [-c, b, a], [-a, -c, b], [-c, -a, b], [b, -c, -a],
        [-a, b, c], [b, -a, c], [c, b, -a], [-a, c, b], [c, -a, b], [b, c, -a],
        [a, -b, c], [-b, a, c], [c, -b, a], [a, c, -b], [c, a, -b], [-b, c, a],
        [-a, -b, -c], [-b, -a, -c], [-c, -b, -a], [-a, -c, -b], [-c, -a, -b], [-b, -c, -a]
    ];
    for (let perm of permutations) {
        putpixelone(perm[0] + x, perm[1] + y, perm[2] + z);
    }
}
// Function to draw a sphere
function drawsphere(x, y, z, r) {
    let i = 0, j = 0, k0 = r, k = k0, s0 = 0, s = s0, v0 = r - 1, v = v0, l0 = 2 * v0, l = l0;
    // Generate voxels for the sphere
    while (i <= k) {
        while (j <= k) {
            if (s > v) {
                k = k - 1;
                v = v + l;
                l = l - 2;
            }
            if (j <= k && (s != v || j != k)) {
                putpixelall(i, j, k, x, y, z);
            }
            s = s + 2 * j + 1;
            j = j + 1;
        }
        s0 = s0 + 4 * i + 2;
        i = i + 1;
        while (s0 > v0 && i <= k0) {
            k0 = k0 - 1;
            v0 = v0 + l0;
            l0 = l0 - 2;
        }
        j = i;
        k = k0;
        v = v0;
        l = l0;
        s = s0;
    }
}
// Function to print all the voxels
function showallpoints() {
    let count = 0;
    for (let [key, values] of mymap) {
        for (let value of values) {
            console.log(`${key}, ${value[0]}, ${value[1]}`);
            count++;
        }
    }
    console.log();
    console.log(count);
}

// Driver program
let cx = parseInt(prompt("Enter cx: "));
let cy = parseInt(prompt("Enter cy: "));
let cz = parseInt(prompt("Enter cz: "));
let r = parseInt(prompt("Enter r: "));
drawsphere(cx, cy, cz, r);
showallpoints();
Python3
#Python code
from typing import List, Tuple
from collections import defaultdict
import math

# defaultdict to store the voxels
mymap = defaultdict(list)

# this function will store single voxel
def putpixelone(m, n, p):
    mymap[m].append((n, p))
    
# function to store some particular type of voxel
def putpixelmiddle(a, b, c, x, y, z):
    putpixelone(a + x, b + y, c + z)
    putpixelone(a + x, b + y, -c + z)
    putpixelone(a + x, c + y, b + z)
    putpixelone(a + x, -c + y, b + z)
    putpixelone(c + x, a + y, b + z)
    putpixelone(-c + x, a + y, b + z)

# This program will generate 24 voxels
def putpixeldouble(a, b, c, x, y, z):
    for j in range(3):
        putpixelone(a + x, b + y, c + z)
        b, c = c, b
        a, b = b, a
    for j in range(3):
        putpixelone(-a + x, b + y, c + z)
        b, c = c, b
        a, b = b, a
    for j in range(3):
        putpixelone(a + x, -b + y, c + z)
        b, c = c, b
        a, b = b, a
    for j in range(3):
        putpixelone(-a + x, -b + y, c + z)
        b, c = c, b
        a, b = b, a
    for j in range(3):
        putpixelone(a + x, b + y, -c + z)
        b, c = c, b
        a, b = b, a
    for j in range(3):
        putpixelone(-a + x, b + y, -c + z)
        b, c = c, b
        a, b = b, a
    for j in range(3):
        putpixelone(a + x, -b + y, -c + z)
        b, c = c, b
        a, b = b, a
    for j in range(3):
        putpixelone(-a + x, -b + y, -c + z)
        b, c = c, b
        a, b = b, a

# Explained above
def putpixelsingle(a, b, c, x, y, z):
    putpixelone(a + x, b + y, c + z)
    putpixelone(-a + x, b + y, c + z)
    putpixelone(a + x, -b + y, c + z)
    putpixelone(-a + x, -b + y, c + z)
    putpixelone(a + x, b + y, -c + z)
    putpixelone(-a + x, b + y, -c + z)
    putpixelone(a + x, -b + y, -c + z)
    putpixelone(-a + x, -b + y, -c + z)

# This program will generate 24 voxels.
def putpixeledge2(a, b, c, x, y, z):
    for j in range(3):
        putpixelone(a + x, b + y, c + z)
        a, b = b, a
        b, c = c, b
    for j in range(3):
        putpixelone(-a + x, b + y, c + z)
        a, b = b, a
        b, c = c, b
    for j in range(3):
        putpixelone(a + x, -b + y, c + z)
        a, b = b, a
        b, c = c, b
    for j in range(3):
        putpixelone(-a + x, -b + y, c + z)
        a, b = b, a
        b, c = c, b
    for j in range(3):
        putpixelone(a + x, b + y, -c + z)
        a, b = b, a
        b, c = c, b
    for j in range(3):
        putpixelone(-a + x, b + y, -c + z)
        a, b = b, a
        b, c = c, b
    for j in range(3):
        putpixelone(a + x, -b + y, -c + z)
        a, b = b, a
        b, c = c, b
    for j in range(3):
        putpixelone(-a + x, -b + y, -c + z)
        a, b = b, a
        b, c = c, b

# after excluding the repeated pixels from the set all 48
# pixels we will left with only 24 pixels so, we have
# defined all the voxels given below.
def putpixeledge1(a, b, c, x, y, z):
    putpixelone(a + x, b + y, c + z)
    putpixelone(a + x, c + y, b + z)
    putpixelone(a + x, -b + y, c + z)
    putpixelone(a + x, b + y, -c + z)
    putpixelone(a + x, -b + y, -c + z)
    putpixelone(a + x, -c + y, b + z)
    putpixelone(a + x, c + y, -b + z)
    putpixelone(a + x, -c + y, -b + z)
    putpixelone(b + x, c + y, a + z)
    putpixelone(b + x, a + y, c + z)
    putpixelone(b + x, -c + y, a + z)
    putpixelone(b + x, c + y, -a + z)
    putpixelone(b + x, -c + y, -a + z)
    putpixelone(b + x, a + y, -c + z)
    putpixelone(b + x, -a + y, c + z)
    putpixelone(b + x, -a + y, -c + z)
    putpixelone(c + x, a + y, b + z)
    putpixelone(c + x, -a + y, b + z)
    putpixelone(c + x, a + y, -b + z)
    putpixelone(c + x, -a + y, -b + z)
    putpixelone(c + x, b + y, a + z)
    putpixelone(c + x, -b + y, a + z)
    putpixelone(c + x, b + y, -a + z)
    putpixelone(c + x, -b + y, -a + z)

# voxel formation by 48 symmetry.
def putpixelall(a, b, c, x, y, z):
    putpixelone(a + x, b + y, c + z)
    putpixelone(b + x, a + y, c + z)
    putpixelone(c + x, b + y, a + z)
    putpixelone(a + x, c + y, b + z)
    putpixelone(c + x, a + y, b + z)
    putpixelone(b + x, c + y, a + z)
    putpixelone(-a + x, -b + y, c + z)
    putpixelone(-b + x, -a + y, c + z)
    putpixelone(c + x, -b + y, -a + z)
    putpixelone(-a + x, c + y, -b + z)
    putpixelone(c + x, -a + y, -b + z)
    putpixelone(-b + x, c + y, -a + z)
    putpixelone(a + x, -b + y, -c + z)
    putpixelone(-b + x, a + y, -c + z)
    putpixelone(-c + x, -b + y, a + z)
    putpixelone(a + x, -c + y, -b + z)
    putpixelone(-c + x, a + y, -b + z)
    putpixelone(-b + x, -c + y, a + z)
    putpixelone(-a + x, b + y, -c + z)
    putpixelone(b + x, -a + y, -c + z)
    putpixelone(-c + x, b + y, -a + z)
    putpixelone(-a + x, -c + y, b + z)
    putpixelone(-c + x, -a + y, b + z)
    putpixelone(b + x, -c + y, -a + z)
    putpixelone(-a + x, b + y, c + z)
    putpixelone(b + x, -a + y, c + z)
    putpixelone(c + x, b + y, -a + z)
    putpixelone(-a + x, c + y, b + z)
    putpixelone(c + x, -a + y, b + z)
    putpixelone(b + x, c + y, -a + z)
    putpixelone(a + x, -b + y, c + z)
    putpixelone(-b + x, a + y, c + z)
    putpixelone(c + x, -b + y, a + z)
    putpixelone(a + x, c + y, -b + z)
    putpixelone(c + x, a + y, -b + z)
    putpixelone(-b + x, c + y, a + z)
    putpixelone(a + x, b + y, -c + z)
    putpixelone(b + x, a + y, -c + z)
    putpixelone(-c + x, b + y, a + z)
    putpixelone(a + x, -c + y, b + z)
    putpixelone(-c + x, a + y, b + z)
    putpixelone(b + x, -c + y, a + z)
    putpixelone(-a + x, -b + y, -c + z)
    putpixelone(-b + x, -a + y, -c + z)
    putpixelone(-c + x, -b + y, -a + z)
    putpixelone(-a + x, -c + y, -b + z)
    putpixelone(-c + x, -a + y, -b + z)
    putpixelone(-b + x, -c + y, -a + z)

# detailed explanation of this algorithm is 
# given in above link.
def drawsphere(x, y, z, r):
    i = 0
    j = 0
    k0 = r
    k = k0
    s0 = 0
    s = s0
    v0 = r - 1
    v = v0
    l0 = 2 * v0
    l = l0

    # this while loop will form naive arcs
    while i <= k:

        # this while will form voxels in naive arcs
        while j <= k:
            if s > v:
                k = k - 1
                v = v + l
                l = l - 2
            if j <= k and (s != v or j != k):

                # this if, else and else if condition
                # can easily build using figure 2, 3
                if i == 0 and j != 0:

                    # First naive arc pixels and each
                    # pixel is shared with two q-octants
                    putpixeledge1(i, j, k, x, y, z)

                # voxels shared between q1 and q2
                elif i == j and j != k and i != 0:
                    putpixeledge2(i, j, k, x, y, z)

                # center voxel of c-octants
                elif i == j and j == k:
                    putpixelsingle(i, j, k, x, y, z)

                # voxels shared between q1 and q6
                elif j == k and i < k and i < j:
                    putpixeldouble(i, j, k, x, y, z)

                # starting voxel of q-octant
                elif i == 0 and j == 0:
                    putpixelmiddle(i, j, k, x, y, z)

                # voxels inside the q-octant
                else:
                    putpixelall(i, j, k, x, y, z)
            s = s + 2 * j + 1
            j = j + 1
        s0 = s0 + 4 * i + 2
        i = i + 1

        while s0 > v0 and i <= k0:
            k0 = k0 - 1
            v0 = v0 + l0
            l0 = l0 - 2
        j = i
        k = k0
        v = v0
        l = l0
        s = s0


# Print out all the voxels of discrete sphere
def showallpoints(mymap: dict) -> None:
    count = 0
    for key, values in mymap.items():
        for value in values:
            print(f"{key}, {value[0]}, {value[1]}")
            count += 1
    print()
    print(count)

# Driver program
if __name__ == "__main__":
    cx, cy, cz = map(int, input().split())
    r = int(input())
    drawsphere(cx, cy, cz, r)
    showallpoints(mymap)
    
# This code is contributed by Utkrash

Input : Center(0, 0, 0) Radius 3 Output:

(-3, 0, 0)(-3, 1, 1)(-3, -1, 1)(-3, 1, -1)(-3, -1, -1)
(-2, 1, 2)(-2, 2, 1)(-2, -1, 2)(-2, -2, 1)(-2, 1, -2)
(-2, 2, -1)(-2, -1, -2)(-2, -2, -1)(-1, 1, 3)(-1, 3, 1)
(-1, -1, 3)(-1, -3, 1)(-1, 1, -3)(-1, 3, -1)(-1, -1, -3)
(-1, -3, -1)(-1, 2, 2)(-1, -2, 2)(-1, 2, -2)(-1, -2, -2)
(0, 0, 3)(0, 0, -3)(0, 3, 0)(0, -3, 0)(0, 1, 3)(0, 3, 1)
(0, -1, 3)(0, 1, -3)(0, -1, -3)(0, -3, 1)(0, 3, -1)
(0, -3, -1)(0, 2, 2)(0, 2, 2)(0, -2, 2)(0, 2, -2)
(0, -2, -2)(0, -2, 2)(0, 2, -2)(0, -2, -2)(1, 3, 0)
(1, 0, 3)(1, -3, 0)(1, 3, 0)(1, -3, 0)(1, 0, -3)(1, 0, 3)
(1, 0, -3)(1, 1, 3)(1, 3, 1)(1, -1, 3)(1, -3, 1)(1, 1, -3)
(1, 3, -1)(1, -1, -3)(1, -3, -1)(1, 2, 2)(1, -2, 2)(1, 2, -2)
(1, -2, -2)(2, 2, 0)(2, 0, 2)(2, -2, 0)(2, 2, 0)(2, -2, 0)
(2, 0, -2)(2, 0, 2)(2, 0, -2)(2, 0, 2)(2, 0, 2)(2, 0, -2)
(2, 0, -2)(2, 2, 0)(2, -2, 0)(2, 2, 0)(2, -2, 0)(2, 1, 2)
(2, 2, 1)(2, -1, 2)(2, -2, 1)(2, 1, -2)(2, 2, -1)(2, -1, -2)
(2, -2, -1)(3, 0, 0)(3, 0, 1)(3, 0, 1)(3, 0, -1)(3, 0, -1)
(3, 1, 0)(3, -1, 0)(3, 1, 0)(3, -1, 0)(3, 1, 1)(3, -1, 1)
(3, 1, -1)(3, -1, -1)
102 (Total no. of points)


References : http://www.sciencedirect.com/science/article/pii/S0304397515010178#tl0010 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads