Graphics /Discover / Drawing a line
Drawing a line
scenario
How Do You Draw a Line?
Look at a rendered scene, then imagine stripping away its surfaces until only the wireframe remains. Much of that structure is made from straight edges. On paper, drawing one seems trivial: put down a ruler and make a continuous stroke. A display gives you something very different. It contains separate pixels arranged in a grid, and each pixel can only be addressed as a discrete element.
Suppose you are given two points and the exact mathematical line joining them. The line itself can pass between pixel centres, along pixel boundaries, or through parts of several neighbouring pixels. You cannot simply turn on the mathematical line. You have to decide which discrete pixels will represent it.
That decision is the line-drawing problem hiding underneath many rendered images.
Given a continuous straight line crossing a grid of pixels, how would you decide which pixels should be turned on so that the result looks like that line?