Line drawing algorithm
   HOME

TheInfoList



OR:

In
computer graphics Computer graphics deals with generating images with the aid of computers. Today, computer graphics is a core technology in digital photography, film, video games, cell phone and computer displays, and many specialized applications. A great de ...
, a line drawing algorithm is an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing ...
for approximating a
line segment In geometry, a line segment is a part of a straight line that is bounded by two distinct end points, and contains every point on the line that is between its endpoints. The length of a line segment is given by the Euclidean distance between i ...
on discrete graphical media, such as
pixel In digital imaging, a pixel (abbreviated px), pel, or picture element is the smallest addressable element in a raster image, or the smallest point in an all points addressable display device. In most digital display devices, pixels are the ...
-based displays and printers. On such media, line drawing requires an
approximation An approximation is anything that is intentionally similar but not exactly equal to something else. Etymology and usage The word ''approximation'' is derived from Latin ''approximatus'', from ''proximus'' meaning ''very near'' and the prefix ' ...
(in nontrivial cases). Basic algorithms
rasterize In computer graphics, rasterisation (British English) or rasterization (American English) is the task of taking an image described in a vector graphics format (shapes) and converting it into a raster image (a series of pixels, dots or lines, whi ...
lines in one color. A better representation with multiple color gradations requires an advanced process,
spatial anti-aliasing In digital signal processing, spatial anti-aliasing is a technique for minimizing the distortion artifacts ( aliasing) when representing a high-resolution image at a lower resolution. Anti-aliasing is used in digital photography, computer graphi ...
. On continuous media, by contrast, no algorithm is necessary to draw a line. For example, cathode-ray oscilloscopes use analog phenomena to draw lines and curves.


List of line drawing algorithms

The following is a partial list of line drawing algorithms: * Naive algorithm * Digital Differential Analyzer (graphics algorithm) — Similar to the naive line-drawing algorithm, with minor variations. *
Bresenham's line algorithm Bresenham's line algorithm is a line drawing algorithm that determines the points of an ''n''-dimensional raster that should be selected in order to form a close approximation to a straight line between two points. It is commonly used to draw li ...
— optimized to use only additions (i.e. no division Multiplications); it also avoids floating-point computations. * Xiaolin Wu's line algorithm — can perform spatial anti-aliasing, appears "ropey" from brightness varying along the length of the line, though this effect may be greatly reduced by pre-compensating the pixel values for the target display's gamma curve, e.g. out = in ^ (1/2.4). * Gupta-Sproull algorithm


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 do y = y1 + dy × (x − x1) / dx plot(x, y) It is here that the points have already been ordered so that x_2 > x_1. This algorithm works just fine when dx \geq dy (i.e., slope is less than or equal to 1), but if dx < dy (i.e., slope greater than 1), the line becomes quite sparse with many gaps, and in the limiting case of dx = 0, a division by zero exception will occur. The naive 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. Algorithms such as
Bresenham's line algorithm Bresenham's line algorithm is a line drawing algorithm that determines the points of an ''n''-dimensional raster that should be selected in order to form a close approximation to a straight line between two points. It is commonly used to draw li ...
or Xiaolin Wu's line algorithm are preferred instead.


Gupta and Sproll algorithm

The Gupta-Sproll algorithm is based on Bresenham's line algorithm but adds antialiasing. An optimized variant of the Gupta-Sproull algorithm can be written in pseudocode as follows: DrawLine(x1, x2, y1, y2) The IntensifyPixel(x,y,r) function takes a radial line transformation and sets the intensity of the pixel (x,y) with the value of a cubic polynomial that depends on the pixel's distance r from the line.


References

* Fundamentals of Computer Graphics, 2nd Edition, A.K. Peters by
Peter Shirley Peter Shirley (born 1963) is an American computer scientist and computer graphics researcher. He is a Distinguished Scientist at NVIDIA and adjunct professor at the University of Utah in computer science. He has made extensive contributions to i ...
{{DEFAULTSORT:Line Drawing Algorithm Computer graphics algorithms