math - How to determine the maximal number of voxels a ray may pass in a voxel volume? -


assuming volume of voxels (x, y, z have same size => cube) , ray passing through voxel volume, how determine maximal number of voxels ray may pass?

if consider plane , 2d square pixels (chess board), can see ray can pass through @ 2*n-1 pixels, if count true intersections (for example, starting point 0, -.5 , direction pi/4) , 3*n-2, if count touched (by corner) cells.

it rather hard imagine 3d case in head :), suspect ray parallel main diagonal, can intersect 3 * n - 2 cells, when ray pass cells in order (0,0,0)-(1,0,0)-(1,1,0)-(1,1,1) etc

addition. quick silly ray-tracing modeling shows 3 * n - 2 value possible:

var   sx, sy, sz: double;   x, y, z: double;   ox, oy, oz, nx, ny, nz, cnt: integer; begin   // starting point coordinate   sx := 0;   sy := 0.7;   sz := 0.7;   // current coordinates   x := sx;   y := sy;   z := sz;   // previous cell indexes   ox := floor(x);   oy := floor(y);   oz := floor(z);   cnt := 1;   memo1.lines.add(format('%d: (%d, %d, %d)', [cnt, ox, oy, oz]));   repeat     // new cell indexes     nx := floor(x);     ny := floor(y);     nz := floor(z);     // if cell changes     if (nx > ox) or (ny > oy) or (nz > oz) begin       inc(cnt);       memo1.lines.add(format('%d: (%d, %d, %d)', [cnt, nx, ny, nz]));     end;     ox := nx;     oy := ny;     oz := nz;     // small step in main diagonal direction     x := x + 0.03;     y := x + 0.03;     z := z + 0.03;   until (x > 4) or (y > 4) or (z > 4); 

gives output 4 * 3 - 2 intersected voxels:

1: (0, 0, 0) 2: (0, 0, 1) 3: (0, 1, 1) 4: (1, 1, 1) 5: (1, 1, 2) 6: (1, 2, 2) 7: (2, 2, 2) 8: (2, 2, 3) 9: (2, 3, 3) 10: (3, 3, 3) 

Comments