I have a two-dimensional unit grid and a bunch of line segments that start and end on any rational number. I need an efficient way to calculate which mesh cells pass through a line. For example, the line:
From (2.1, 3.9) to (3.8, 4.8) it passes through the grid cells with the lower left points (2, 3), (2, 4) and (3, 4).
Is there a quick and efficient way to calculate these quadrants from the endpoints of a line?
I will work in R, but a Python response or pseudo code will work too. Thanks!
source share