All "pixels" touched by line segment

318 Views Asked by At

Say you have a line segment somewhere on the Cartesian plane that connects the points $(x_1,y_1)$ and $(x_2,y_2)$, and there are "pixels". For simplicity's sake, let's say that the pixels are 1 unit by 1 unit.

It took forever to make this picture in paint.

How could I go about finding all the pixels that the line touches? (This is part of a computer program, so I would prefer something fast)

Thanks!