# Ray tracer : create an uniform grid [closed]

I wrote a simple ray tracer, and now I try to implement an uniform grid. There is a lot of documentation on how to traverse the grid, but I don't know how to construct the grid.

I have my uniform grid and my triangles. How could I know, which cell(s) in the grid correspond(s) to my triangles ?

You don't have to form and store a uniform mesh explicitly since you can do arithmetic to compute cell indicies. If you know you have $N_x$ cells in the $x$ direction on a grid over $\left[0,L_x\right]$, then you know the $x$-index of the cell is $$i=\left\lfloor \frac{x N_x}{L_x}\right\rfloor$$ You can do the same for each of the three coordinates for each of the three corners of your triangle. The indices you generate uniquely define the cell than contains each corner. A cell contains an entire triangle if it contains all three corners.