首先定義一個簡單的struct 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)
什麼是1度轉角,2度轉角,等等?你只是想識別立方體的八個角落? – Cricketer
是的,我需要確定8個角落,因爲那時我需要他們來識別立方體內的四面體...... – user2572206