# Line Drawing Algorithms - Bresenham / Mid Point Algorithms

The line is drawn between two points (*x*_{0}, *y*_{0}) and (*x*_{1}, *y*_{1}), where these pairs indicate column and row, respectively, increasing in the down and right directions. We will initially assume that our line goes down and to the right, and that the horizontal distance *x*_{1}-*x*_{0} exceeds the vertical distance *y*_{1}-*y*_{0} (that is, the line has a slope less than 1.) Our goal is, for each column *x* between *x*_{0} and *x*_{1}, to identify the row *y* in that column which is closest to the line and plot a pixel at (x,y).
Now, how do we figure out which pixel is closest to the line for a given column? The general formula for the line between the two points is given by:
Since we know the column, *x*, the pixel's row, *y*, is given by rounding this quantity to the nearest integer:
However, explicitly calculating this value for each column, *x*, is silly; we need only note that *y* starts at *y*_{0}, and each time we add 1 to *x*, we add the fixed value (*y*_{1}-*y*_{0})/(*x*_{1}-*x*_{0}), which we can precalculate, to the exact *y*. Moreover, since this is the slope of the line, by assumption it is between 0 and 1; in other words, after rounding, in each column we either use the same *y* as in the previous column, or we add one to it.