Solution

ID: past-exam-of-the-computer-science-course-of-the-university-of-oxford/2015/computer-graphics/1/b/solution

By exchanging axes, reversing endpoint order and reflecting coordinate signs where necessary, reduce a general line segment to the first octant:
The vertical case is handled by exchanging axes. In this octant, increasing by one requires increasing by either zero or one. Thus, from the currently plotted pixel the candidates are and .
Use the implicit equation of the line
At a fixed , means that lies below the exact line. The midpoint line decision evaluates , halfway between the two candidate pixel centres. If , the exact line lies below , so choose ; if , choose . At equality either candidate is equally near, but a fixed tie rule is essential. We choose on a tie throughout these solutions:
This chooses the closest vertical-grid pixel centre in each column, with ties rounded upward. Since , the result has one pixel per column and consecutive pixels share an edge or a corner.

New to topics? Read the docs here!