Draw a line (intro)

Drawing a line on a computer monitor is harder than on paper. Paper is analog and you can just draw a line from point a to point b. On a computer screen this is not the case. The screen is digital, made up of discreet pixels laid out in a grid. Think of the screen as a sheet of graph paper. Each pixel is like a square on the paper, and can only be one color.

Here is a line from (2,2) to (19,9). You can see that it has a bit of a wiggle to it.

Here it is magnified, and the reason for the wiggle (called the jaggies) becomes apparent.

Notice the steps, these are caused by trying to draw a diagonal with squares laid out in a coordinate system. These squares are aliased from the position of the line in that colnmn. The white squares are the centers of the pixels.

The C code that drew this line is written for the special case of lines in the first octant. A line can be draw here and then mirrored to provide generality.

The points that are plotted generated by the algorithm.

Test your knowledge


Created and Maintained by:
Aaron McClennen
http://www.cc.gatech.edu/grads/m/Aaron.E.McClennen/homepage.html
aaronm@cc.gatech.edu
Last Change: 2/14/95