Morph Cube to Orb

I created a cube of small-sphere models that act like points. Points have coordinates:

{0 <= x <= 9, 0 <= y <= -9, 0 <= z <= -9}

The inside of the cube is empty, so points only exist on the surface of the cube. Empty spaces are represented as dots in (100, 100, 100), and when I do a drawing cycle, I ignore the dots that correspond to them, so in the code that I posted below, it will have this condition to perform certain actions or not their.

The goal is to take cube points and apply transforms to them to map them to a sphere.

This is the set of equations used to transform the points.

This is the code to create an array for cube positions, to create an array for sphere positions:

// initialize cube array
points = new Matrix[10, 10, 10];

for (int i = 0; i < 10; i++)
{
    for (int j = 0; j < 10; j++)
    {
        for (int k = 0; k < 10; k++)
        {
            points[i, j, k] = Matrix.CreateTranslation(new Vector3(100, 100, 100));
        }
    }
}

for (int i = 0; i < 10; i++)
{
    for (int j = 0; j < 10; j++)
    {
        points[i, j, 0] = Matrix.CreateTranslation(new Vector3(i, -j, 0));
        points[i, j, 9] = Matrix.CreateTranslation(new Vector3(i, -j, -9));
    }
}

for (int j = 0; j < 10; j++)
{
    for (int k = 0; k < 10; k++)
    {
        points[0, j, k] = Matrix.CreateTranslation(new Vector3(0, -j, -k));
        points[9, j, k] = Matrix.CreateTranslation(new Vector3(9, -j, -k));
    }
}

for (int i = 0; i < 10; i++)
{
    for (int k = 0; k < 10; k++)
    {
        points[i, 0, k] = Matrix.CreateTranslation(new Vector3(i, 0, -k));
        points[i, 9, k] = Matrix.CreateTranslation(new Vector3(i, -9, -k));
    }
}
// end cube array initialization

// create sphere array
double d;
double theta;
double phi;
double r = 10;

spherePoints = new Matrix[10, 10, 10];
for (int i = 0; i < 10; i++)
{
    for (int j = 0; j < 10; j++)
    {
        for (int k = 0; k < 10; k++)
        {
            if (points[i, j, k] != Matrix.CreateTranslation(new Vector3(100, 100, 100)))
            {
                d = Math.Sqrt(Math.Pow(i, 2) + Math.Pow(-j, 2) + Math.Pow(-k, 2));
                theta = Math.Acos(-k / d);
                phi = Math.Atan2(-j, i);

                spherePoints[i, j, k] = Matrix.CreateTranslation(new Vector3((float)(r * Math.Sin(theta) * Math.Cos(phi)),
                                                                            (float)(r * Math.Sin(theta) * Math.Sin(phi)),
                                                                            (float)(r * Math.Cos(theta))));
            }
            else
                spherePoints[i, j, k] = Matrix.CreateTranslation(new Vector3(100, 100, 100));
        }
    }
}
// end creation of sphere array

Cube: enter image description here

Not a sphere ...: enter image description here

, , , , , . .

+5
1

, "" (, , "" ), 1/8 .

, [0,9], [-9,0], [-9,0], .

[-5,5], [-5, 5], [-5,5], .

, :

  • , Acos (z/d), , d z ?
  • , Atan (y, x), , y , x ?

8 .

+3

All Articles