I'm trying to make a quad sphere based on an article, which shows results like this:


I can generate a cube correctly:


But when I convert all the points according to this formula (from the page linked above):


    x = x * sqrtf(1.0 - (y*y/2.0) - (z*z/2.0) + (y*y*z*z/3.0));
    y = y * sqrtf(1.0 - (z*z/2.0) - (x*x/2.0) + (z*z*x*x/3.0));
    z = z * sqrtf(1.0 - (x*x/2.0) - (y*y/2.0) + (x*x*y*y/3.0));

My sphere looks like this:


As you can see, the edges of the cube still poke out too far. The cube ranges from -1 to +1 on all axes, like the article says.

Any ideas what is wrong?

  • 1
    Does your implementation contain "x = x ..." problem too or is it just here? – snake5 Nov 14 '12 at 9:55
  • 7
    Fantastic visual aids. Thankyou for including those. – doppelgreener Nov 14 '12 at 10:04
  • 2
    To answer the question in the title, you can just normalize the vertices of the cube to make it a sphere. The distribution of the vertices will probably be different from the linked method though. – msell Nov 14 '12 at 10:09
up vote 25 down vote accepted

You've miswritten the formula.

x = x * sqrtf(1.0 - (y*y/2.0) - (z*z/2.0) + (y*y*z*z/3.0));
y = y * sqrtf(1.0 - (z*z/2.0) - (x*x/2.0) + (z*z*x*x/3.0));
z = z * sqrtf(1.0 - (x*x/2.0) - (y*y/2.0) + (x*x*y*y/3.0));

You modify the original x and overwrite it. Then you modify y based not on the original x but the modified x. Then you modify z based on the modified version of both of those.

Preserve the originals, and calculate this:

float dx = x * sqrtf(1.0 - (y*y/2.0) - (z*z/2.0) + (y*y*z*z/3.0));
float dy = y * sqrtf(1.0 - (z*z/2.0) - (x*x/2.0) + (z*z*x*x/3.0));
float dz = z * sqrtf(1.0 - (x*x/2.0) - (y*y/2.0) + (x*x*y*y/3.0));

Use dx, dy and dz from then on.

  • Whoops. Wasn't thinking. – Tom Dalling Nov 14 '12 at 10:15
  • do u have any sample source for the above program? – Vamsi Dec 8 '15 at 6:43

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.