I'm trying to solve a very simple problem but I'm unable to come-up with an efficient solution so far. What I'm really trying to do is voxelize triangles in a three dimensional environment but I'll give a 2D example of my problem.
I have a point P and a direction d. P is somewhere inside a cell in the grid. I can easily calculate which cell.
My questions is. When I trace a line from P in direction d what are the coordinates of the first cell I will encounter, and at what location will I enter it? Or, in other words, at what edge and where on that edge will I exit the cell?
As a picture says a thousand words:
I'll also place the broader context here to see if I'm going about this the right way. My idea is to voxelize the triangle with vertices t0,t1,t2 by first voxelizing the edge t0-t1 and then filling in the triangle by tracing multiple edges along the line t0-t1 towards t1-t2. This way I can create the shell of the mesh after which In can start filling it in