首先定义一个简单的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