Having a line and a grid, the aim is to discretise the line into grid lines. In the following figure, the given line is in black, its intersections with grid lines are blue, the desired is set of segments (polyline) in red.
Any idea or solution?
Note that we know Bresenham's method. However, it does not work for our case as shown in the figures. Green cells are indeed pixels not squares based on Bresenham's method. It is not easy to generate our desired polyline (red) based on those Bresenham's green pixels. Note that the figure shown is a simplistic case.
We are interested in general solution which works for any grid complexity.