Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

Does your implementation contain "x = x ..." problem too or is it just here? –  snake5 Nov 14 '12 at 9:55
Fantastic visual aids. Thankyou for including those. –  doppelgreener Nov 14 '12 at 10:04
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
Related: gamedev.stackexchange.com/questions/7189/… –  Byte56 Nov 14 '12 at 16:16
+1 for exceptional question. :) –  Md. Mahbubur R. Aaman Nov 15 '12 at 9:09

1 Answer 1

up vote 23 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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