javamath3dprocedural

Sorting 3D Grid Points into 3D Grid Cells


I'm kind of at a roadblock while trying to assign 3D grid points as vertices to Cells. The Cells should just contain 8 points as corner vertices.

I have created the grid without any issues, but cant seem to figure out how to sort the points to their according cells.

This sketch illustrates how the points are indexed:

enter image description here

One cube with 8 corner points would correspond to a Cell (ex. Cell0 would include points 0,1,3,4,6,7,9,10 as corner points).

The code should be something like this:

public class Cell
    {
        public int[] Index =new int[8];
    }

public void makeCells()
    {
        numCells = (xSize - 1) * (zSize - 1) * (ySize - 1);
        Cells = new Cell[numCells];

        for ( int i = 0, j = 0; i < numCells; i++)
        {
            Cells[i] = new Cell();
            for ( int k = 0; k <8; k++, j ++)
            {
                Cells[i].Index[k] = j;
            }
        }
    }

I can't seem to get how to increment the indices properly so that they coordinate with the correct points. Any form of help would be appreciated!


Solution

  • enter image description here

    I managed to index all of my vertices using the algorithm above. If anyone needs any further explanation please feel free to ask.