- Line drawing algorithm
A line drawing algorithm is a graphical
algorithm for approximating a line segment on discrete graphical media. On discrete media, such aspixel -based displays and printers, line drawing requires such an approximation (in nontrivial cases).On continuous media, by contrast, no algorithm is necessary to draw a line. For example,
oscilloscope s use natural phenomena to draw lines and curves.A naïve line-drawing algorithm
dx = x2 - x1 dy = y2 - y1 for x from x1 to x2 { y = y1 + (dy) * (x - x1)/(dx) plot(x, y) }
It is assumed here that the points have already been ordered so that .This algorithm works just fine when , but it is quite slow on a digital computer, as it requires floating-point calculations. If , the line becomes quite sparse, and in the limiting case of , only a single point is plotted!List of line drawing algorithms
The following is a partial list of line drawing algorithms:
*Bresenham's line algorithm — optimized to use only additions (i.e. no divisions or multiplications); it also avoids floating-point computations.
*Xiaolin Wu's line algorithm — can performanti-aliasing
* [http://www.edepot.com/algorithm.html EFLA line algorithm] — A very fast implementation.
* [http://gatopeichs.pbwiki.com/gatopeich%27s-Graphic-Algorithms#LineDrawingbyIntegerOperations gatopeich's line algorithm] — Fast, simple, aesthetic. Based on pure integer operations.
Wikimedia Foundation. 2010.