title: Sphere Drawing in Java
body: <p>For some reason, when I try to make a sphere in Java by checking the radius of points, it gives me a cube instead of a sphere.  Is the problem with my code or my formula?</p>
  
  <pre><code>for(double X = 0; X &lt; diameter; X++ )
          {
              //mcspace.logger.info("X = " + Double.toString(X));
              for(double Y = 0; Y &lt; diameter; Y++ )
              {
                  //mcspace.logger.info("Y = " + Double.toString(Y));
                  for(double Z = 0; Z &lt; diameter; Z++ )
                  {
                      //mcspace.logger.info("Z = " + Double.toString(Z));
                      int radius = diameter / 2;
  
                      double cX = X;
                      double cZ = Z;
                      double cY = Y;
  
                      if (X &gt; radius){cX -= radius;}
                      if (Y &gt; radius){cY -= radius;}
                      if (Z &gt; radius){cZ -= radius;}
  
                      double Cr = Math.sqrt(Math.sqrt(Math.pow(cX,2) + Math.pow(cY,2)) + Math.pow(cZ,2));
  
                      if(Cr &lt;= radius)
                      {
                          SetInShere(X,Y,Z);
                          // This is just a function that is in my code but the problem is that almost all the points are in the sphere, I almost always get a cube instead of a sphere...
                      }
                  }
           }
  }
  </code></pre>