Formula for procedural Sphere from the cube?

Hello! Sorry for my language (is not my native)
I need to generate a sphere for the cube. I managed to make a grid for the cube and for the plane, but I don’t understand as create the sphere and which formula use.
I found this formula but have a problem.

https://forums.unrealengine.com/filedata/fetch?filedataid=154553&type=thumb

I don’t have Z-coordinate because it zero. Therefore, I usually substituted 1 or 0 instead of the Z coordinate.

I tried to use the formula not on a cube, but on a plane (for a test), but if I use this formula for all coordinates, I get complete nonsense. If only to find the Z coordinate - the plane is simply bent by one angle.


This is my code

void ATestGenerateSphere::GenerateVertices()
{
    for (int32 X_index = 0; X_index < XSize; X_index++)
    {
        for (int32 Y_index = 0; Y_index < YSize; Y_index++)
        {
            float x = X_index * 50.0f;
            float y = Y_index * 50.0f;
            float z = 1 * 50.0f; //THIS IS COORDINATE Z 

            float xx = x * x;
            float yy = y * y;
            float zz = z * z;

            float new__z = z * sqrt(1.0f - xx / 2.0f - yy / 2.0f + xx * yy / 3.0f);

            new__z = new__z / 1000.0f; //Without division there will be a high triangle

            Vertices.Add(FVector(x, y, new__z));
        }
    }
}

Thanks for the help, but I have already managed to fix it :slight_smile:
I realized that by your formula, my only plane was simply divided into 4 parts.
Having played a little with the values I got what I wanted