A line drawing algorithm is a graphical algorithm for approximating a line segment on discrete graphical media. On discrete media, such as pixel-based displays and printers, line drawing requires such an approximation (in nontrivial cases). Basic algorithms rasterize lines in one color. A better representation with multiple color gradations requires an advanced process, spatial anti-aliasing.
Contents
On continuous media, by contrast, no algorithm is necessary to draw a line. For example, oscilloscopes use natural phenomena to draw lines and curves.
The Cartesian slope-intercept equation for a straight line is
A naive line-drawing algorithm
The simplest method of screening is the direct drawing of the equation defining the line.
dx = x2 - x1 dy = y2 - y1 for x from x1 to x2 { y = y1 + dy * (x - x1) / dx plot(x, y) }It is here that the points have already been ordered so that
The naïve line drawing algorithm is inefficient and thus, slow on a digital computer. Its inefficiency stems from the number of operations and the use of floating-point calculations. Line drawing algorithms such as Bresenham's or Wu's are preferred instead.
List of line drawing algorithms
The following is a partial list of line drawing algorithms: