# Xiaolin Wu's line algorithm

**Xiaolin Wu's line algorithm**is analgorithm for lineantialiasing , which was presented in the article "An Efficient Antialiasing Technique" in the July1991 issue of "Computer Graphics ", as well as in the article "Fast Antialiasing" in the June1992 issue of "Dr. Dobb's Journal ".Bresenham's algorithm draws lines extremely quickly, but it cannot perform anti-aliasing. In addition, it cannot handle the case where the line endpoints do not lie exactly on integer points of the pixel grid. A naïve approach to anti-aliasing the line would take an extremely long time, but Wu's algorithm is quite fast (it is still slower than Bresenham's, though). The basis of the algorithm is to draw pairs of pixels straddling the line, coloured according to proximity. Pixels at the line ends are handled separately. Lines less than one pixel long should be handled as a special case.

An extension to the algorithm for circle drawing was presented by Xiaolin Wu in the book "

Graphics Gems II". Just like the line drawing algorithm is a replacement for Bresenham's line drawing algorithm, the circle drawing algorithm is a replacement for Bresenham's circle drawing algorithm.**Pseudocode implementation**Here is

pseudocode for the nearly-horizontal case ($Delta\; x\; >\; Delta\; y$). To extend the algorithm to work for all lines, swap the x and y coordinates when near-vertical lines appear (for reference, seeBresenham's line algorithm ). This implementation is only valid for x, y ≥ 0.**function**plot(x, y, c)**is**plot the pixel at (x, y) with brightness c (where 0 ≤ c ≤ 1)**function**ipart(x)**is****return**"integer part of x"**function**round(x)**is****return**ipart(x + 0.5)**function**fpart(x)**is****return**"fractional part of x"**function**rfpart(x)**is****return**1 - fpart(x)**function**drawLine(x1,y1,x2,y2)**is**dx = x2 - x1 dy = y2 - y1**if**abs(dx) > abs(dy) then "//handle "horizontal" lines"**if**x2 < x1 swap x1, x2 swap y1, y2**end if**gradient = dy / dx "// handle first endpoint" xend = round(x1) yend = y1 + gradient * (xend - x1) xg**for**x**from**xpxl1 + 1**to**xpxl2 - 1**do**plot(x, ipart(intery), rfpart(intery)) plot(x, ipart(intery) + 1, fpart(intery)) intery = intery + gradient**repeat****else**"//handle "vertical" lines same code as above but X takes the role of Y**end function****References*** cite journal

author=Abrash, Michael

url = http://www.gamedev.net/reference/articles/article382.asp

title = Fast Antialiasing (Column)

journal=Dr. Dobb's Journal

month=June | year=1992 | volume=17 | issue=6 | pages=139(7)

* cite journal

author=Wu, Xiaolin

url = http://portal.acm.org/citation.cfm?id=122734

title = An efficient antialiasing technique

journal=Computer Graphics

month=July | year=1991 | volume=25 | issue=4 | pages=143–152

id = ISBN 0-89791-436-8

doi = 10.1145/127719.122734

* cite book

author = Wu, Xiaolin

year = 1991

chapter = Fast Anti-Aliased Circle Generation

editor = James Arvo (Ed.)

title = Graphics Gems II

pages = pp. 446–?

location = San Francisco

publisher = Morgan Kaufmann

id = ISBN 0-12-064480-0**External links*** [

*http://www.ece.mcmaster.ca/~xwu/ Xiaolin Wu's homepage*]

*Wikimedia Foundation.
2010.*

### Look at other dictionaries:

**Bresenham's line algorithm**— The Bresenham line algorithm is an algorithm that determines which points in an n dimensional raster should be plotted in order to form a close approximation to a straight line between two given points. It is commonly used to draw lines on a… … Wikipedia**Line drawing algorithm**— 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).On… … Wikipedia**Digital Differential Analyzer (graphics algorithm)**— In Computer graphics, an hard or software implementation of a Digital Differential Analyzer (DDA) is used for linear interpolation of variables over an interval between start and end point. DDAs are used for rasterization of lines, triangles and… … Wikipedia**Digital differential analyzer (graphics algorithm)**— This article is about a graphics algorithm. For the digital implementation of a Differential Analyzer, see Digital Differential Analyzer. In computer graphics, a hardware or software implementation of a digital differential analyzer (DDA) is used … Wikipedia**Algorithme de tracé de segment de Xiaolin Wu**— L algorithme de tracé de segment de Xiaolin Wu est un algorithme permettant de tracer des courbes non crénelées qui a été présenté dans l article An Efficient Antialiasing Technique de Juillet 1991 issue de Computer Graphics ainsi que dans l… … Wikipédia en Français**List of algorithms**— The following is a list of the algorithms described in Wikipedia. See also the list of data structures, list of algorithm general topics and list of terms relating to algorithms and data structures.If you intend to describe a new algorithm,… … Wikipedia**Spatial anti-aliasing**— In digital signal processing, spatial anti aliasing is the technique of minimizing the distortion artifacts known as aliasing when representing a high resolution image at a lower resolution. Anti aliasing is used in digital photography, computer… … Wikipedia**Anti-aliasing**— In digital signal processing, anti aliasing is the technique of minimizing the distortion artifacts known as aliasing when representing a high resolution signal at a lower resolution. Anti aliasing is used in digital photography, computer… … Wikipedia**List of mathematics articles (X)**— NOTOC X X–Y–Z matrix Xiaolin Wu s line algorithm XTR … Wikipedia**Rasterung von Linien**— Die Rasterung von Linien ist eine elementare Aufgabe der Computergrafik, bei der eine Linie auf das Punktraster einer Rastergrafik oder eines Raster Grafikgeräts gezeichnet (gerastert) wird. Dazu werden diejenigen Punkte oder Pixel eingefärbt,… … Deutsch Wikipedia