最初に単純な構造体 point3D を定義します。
typedef struct {
float x;
float y;
float z;
} point3D;
グリッドを生成するためにこれを書きました:
//Compute edge sizes
float x_size = xe - xs;
float y_size = ye - ys;
float z_size = ze - zs;
//Compute steps
float x_step = x_size/n_step;
float y_step = y_size/n_step;
float z_step = z_size/n_step;
//Points per edge (including ending point)
int n = n_step + 1;
//Alloc grid (you can use malloc if you prefer)
point3D grid[n*n*n];
for (int i = 0; i < n; i++) { //move on x axis
for (int j = 0; j < n; j++) { //move on y axis
for (int k = 0; k < n; k++) { //move on z axis
point3D p;
p.x = xs + x_step * i;
p.y = ys + y_step * j;
p.z = zs + z_step * k;
grid[i+n*j+n*n*k] = point3D;
}
}
}
8 つのコーナー ポイントを使用するには、次のようにします。
point3D corner = grid[n_step*x + n*n_step*y + n*n*n_step*z];
と:
(x, y, z)
1: (0, 0, 0)
2: (0, 0, 1)
3: (0, 1, 0)
4: (0, 1, 1)
5: (1, 0, 0)
6: (1, 0, 1)
7: (1, 1, 0)
8: (1, 1, 1)