While algorithms such as Wu's algorithm are also frequently used in modern computer graphics because they can support antialiasing, Bresenham's line algorithm is still important because of its speed and simplicity. The algorithm is used in hardware such as plotters and in the graphics chips of modern graphics cards. It can also be found in many softwaregraphics libraries. Because the algorithm is very simple, it is often implemented in either the firmware or the graphics hardware of modern graphics cards.
The label "Bresenham" is used today for a family of algorithms extending or modifying Bresenham's original algorithm.
History
Bresenham's line algorithm is named after Jack Elton Bresenham who developed it in 1962 at IBM. In 2001 Bresenham wrote:[1]
I was working in the computation lab at IBM's San Jose development lab. A Calcomp plotter had been attached to an IBM 1401 via the 1407 typewriter console. [The algorithm] was in production use by summer 1962, possibly a month or so earlier. Programs in those days were freely exchanged among corporations so Calcomp (Jim Newland and Calvin Hefte) had copies. When I returned to Stanford in Fall 1962, I put a copy in the Stanford comp center library.
A description of the line drawing routine was accepted for presentation at the 1963 ACM national convention in Denver, Colorado. It was a year in which no proceedings were published, only the agenda of speakers and topics in an issue of Communications of the ACM. A person from the IBM Systems Journal asked me after I made my presentation if they could publish the paper. I happily agreed, and they printed it in 1965.
Method
The following conventions will be applied:
the top-left is (0,0) such that pixel coordinates increase in the right and down directions (e.g. that the pixel at (7,4) is directly above the pixel at (7,5)), and
the pixel centers have integer coordinates.
The endpoints of the line are the pixels at and , where the first coordinate of the pair is the column and the second is the row.
The algorithm will be initially presented only for the octant in which the segment goes down and to the right ( and ), and its horizontal projection is longer than the vertical projection (the line has a positive slope less than 1).
In this octant, for each column x between and , there is exactly one row y (computed by the algorithm) containing a pixel of the line, while each row between and may contain multiple rasterized pixels.
Bresenham's algorithm chooses the integer y corresponding to the pixel center that is closest to the ideal (fractional) y for the same x; on successive columns y can remain the same or increase by 1.
The general equation of the line through the endpoints is given by:
.
Since we know the column, x, the pixel's row, y, is given by rounding this quantity to the nearest integer:
.
The slope depends on the endpoint coordinates only and can be precomputed, and the ideal y for successive integer values of x can be computed starting from and repeatedly adding the slope.
In practice, the algorithm does not keep track of the y coordinate, which increases by m = ∆y/∆x each time the x increases by one; it keeps an error bound at each
stage, which represents the negative of the distance from (a) the point where the line exits the pixel to (b) the top edge of the pixel.
This value is first set to (due to using the pixel's center coordinates), and is incremented by m each time the x coordinate is incremented by one. If the error becomes greater than 0.5, we know that the line has moved upwards
one pixel, and that we must increment our y coordinate and readjust the error to represent the distance from the top of the new pixel – which is done by subtracting one from error.[2]
Derivation
To derive Bresenham's algorithm, two steps must be taken. The first step is transforming the equation of a line from the typical slope-intercept form into something different; and then using this new equation to draw a line based on the idea of accumulation of error.
Line equation
The slope-intercept form of a line is written as
where is the slope and is the y-intercept. Because this is a function of only , it can't represent a vertical line. Therefore, it would be useful to make this equation written as a function of both and, to be able to draw lines at any angle. The angle (or slope) of a line can be stated as "rise over run", or . Then, using algebraic manipulation,
Letting this last equation be a function of and , it can be written as
where the constants are
The line is then defined for some constants , , and anywhere . That is, for any not on the line, . This form involves only integers if and are integers, since the constants , , and are defined as integers.
As an example, the line then this could be written as . The point (2,2) is on the line
and the point (2,3) is not on the line
and neither is the point (2,1)
Notice that the points (2,1) and (2,3) are on opposite sides of the line and evaluates to positive or negative. A line splits a plane into halves and the half-plane that has a negative can be called the negative half-plane, and the other half can be called the positive half-plane. This observation is very important in the remainder of the derivation.
Algorithm
The starting point is on the line
only because the line is defined to start and end on integer coordinates (though it is entirely reasonable to want to draw a line with non-integer end points).
Keeping in mind that the slope is at most , the problem now presents itself as to whether the next point should be at or . Perhaps intuitively, the point should be chosen based upon which is closer to the line at . If it is closer to the former then include the former point on the line, if the latter then the latter. To answer this, evaluate the line function at the midpoint between these two points:
If the value of this is positive then the ideal line is below the midpoint and closer to the candidate point ; i.e. the y coordinate should increase. Otherwise, the ideal line passes through or above the midpoint, and the y coordinate should stay the same; in which case the point is chosen. The value of the line function at this midpoint is the sole determinant of which point should be chosen.
The adjacent image shows the blue point (2,2) chosen to be on the line with two candidate points in green (3,2) and (3,3). The black point (3, 2.5) is the midpoint between the two candidate points.
Algorithm for integer arithmetic
Alternatively, the difference between points can be used instead of evaluating f(x,y) at midpoints. This alternative method allows for integer-only arithmetic, which is generally faster than using floating-point arithmetic. To derive the other method, define the difference to be as follows:
For the first decision, this formulation is equivalent to the midpoint method since at the starting point. Simplifying this expression yields:
Just as with the midpoint method, if is positive, then choose , otherwise choose .
If is chosen, the change in will be:
If is chosen the change in will be:
If the new D is positive then is chosen, otherwise . This decision can be generalized by accumulating the error on each subsequent point.
All of the derivation for the algorithm is done. One performance issue is the 1/2 factor in the initial value of D. Since all of this is about the sign of the accumulated difference, then everything can be multiplied by 2 with no consequence.
This results in an algorithm that uses only integer arithmetic.
plotLine(x0, y0, x1, y1)
dx = x1 - x0
dy = y1 - y0
D = 2*dy - dx
y = y0
for x from x0 to x1
plot(x, y)
if D > 0
y = y + 1
D = D - 2*dx
end if
D = D + 2*dy
Running this algorithm for from (0,1) to (6,4) yields the following differences with dx=6 and dy=3:
The result of this plot is shown to the right. The plotting can be viewed by plotting at the intersection of lines (blue circles) or filling in pixel boxes (yellow squares). Regardless, the plotting is the same.
All cases
However, as mentioned above this only works for octant zero, that is lines starting at the origin with a slope between 0 and 1 where x increases by exactly 1 per iteration and y increases by 0 or 1.
The algorithm can be extended to cover slopes between 0 and -1 by checking whether y needs to increase or decrease (i.e. dy < 0)
plotLineLow(x0, y0, x1, y1)
dx = x1 - x0
dy = y1 - y0
yi = 1
if dy < 0
yi = -1
dy = -dy
end if
D = (2 * dy) - dx
y = y0
for x from x0 to x1
plot(x, y)
if D > 0
y = y + yi
D = D + (2 * (dy - dx))
else
D = D + 2*dy
end if
By switching the x and y axis an implementation for positive or negative steep slopes can be written as
plotLineHigh(x0, y0, x1, y1)
dx = x1 - x0
dy = y1 - y0
xi = 1
if dx < 0
xi = -1
dx = -dx
end if
D = (2 * dx) - dy
x = x0
for y from y0 to y1
plot(x, y)
if D > 0
x = x + xi
D = D + (2 * (dx - dy))
else
D = D + 2*dx
end if
A complete solution would need to detect whether x1 > x0 or y1 > y0 and reverse the input coordinates before drawing, thus
plotLine(x0, y0, x1, y1)
if abs(y1 - y0) < abs(x1 - x0)
if x0 > x1
plotLineLow(x1, y1, x0, y0)
else
plotLineLow(x0, y0, x1, y1)
end ifelseif y0 > y1
plotLineHigh(x1, y1, x0, y0)
else
plotLineHigh(x0, y0, x1, y1)
end ifend if
In low level implementations which access the video memory directly, it would be typical for the special cases of vertical and horizontal lines to be handled separately as they can be highly optimized.
Some versions use Bresenham's principles of integer incremental error to perform all octant line draws, balancing the positive and negative error between the x and y coordinates.[3]
plotLine(x0, y0, x1, y1)
dx = abs(x1 - x0)
sx = x0 < x1 ? 1 : -1
dy = -abs(y1 - y0)
sy = y0 < y1 ? 1 : -1
error = dx + dy
while true
plot(x0, y0)
if x0 == x1 && y0 == y1 break
e2 = 2 * error
if e2 >= dy
error = error + dy
x0 = x0 + sx
end ifif e2 <= dx
error = error + dx
y0 = y0 + sy
end ifend while
Similar algorithms
The Bresenham algorithm can be interpreted as slightly modified digital differential analyzer (using 0.5 as error threshold instead of 0, which is required for non-overlapping polygon rasterizing).
The principle of using an incremental error in place of division operations has other applications in graphics. It is possible to use this technique to calculate the U,V co-ordinates during raster scan of texture mapped polygons.[4] The voxel heightmap software-rendering engines seen in some PC games also used this principle.
Bresenham also published a Run-Slice computational algorithm: while the above described Run-Length algorithm runs the loop on the major axis, the Run-Slice variation loops the other way.[5] This method has been represented in a number of US patents:
5,815,163
Method and apparatus to draw line slices during calculation
5,740,345
Method and apparatus for displaying computer graphics data stored in a compressed format with an efficient color indexing system
5,657,435
Run slice line draw engine with non-linear scaling capabilities
5,627,957
Run slice line draw engine with enhanced processing capabilities
5,627,956
Run slice line draw engine with stretching capabilities
5,617,524
Run slice line draw engine with shading capabilities
5,611,029
Run slice line draw engine with non-linear shading capabilities
5,604,852
Method and apparatus for displaying a parametric curve on a video display
5,600,769
Run slice line draw engine with enhanced clipping techniques
The algorithm has been extended to:
Draw lines of arbitrary thickness, an algorithm created by Alan Murphy at IBM.[6]
Draw multiple kinds curves (circles, ellipses, cubic, quadratic, and rational Bézier curves) and antialiased lines and curves; a set of algorithms by Alois Zingl.[3]
^Joy, Kenneth. "Bresenham's Algorithm"(PDF). Visualization and Graphics Research Group, Department of Computer Science, University of California, Davis. Retrieved 20 December 2016.
^US 5739818, Spackman, John Neil, "Apparatus and method for performing perspectively correct interpolation in computer graphics", published 1998-04-14, assigned to Canon KK
^"Murphy's Modified Bresenham Line Algorithm". homepages.enterprise.net. Retrieved 2018-06-09. ('Line Thickening by Modification to Bresenham's Algorithm' in the IBM Technical Disclosure Bulletin Vol. 20 No. 12 May 1978 pages 5358-5366.)
Bresenham, Jack (February 1977). "A linear algorithm for incremental digital display of circular arcs". Communications of the ACM. 20 (2): 100–106. doi:10.1145/359423.359432. – also Technical Report 1964 Jan-27 -11- Circle Algorithm TR-02-286 IBM San Jose Lab
شلل العصب الوجهي شلل العصب الوجهي معلومات عامة الاختصاص طب الجهاز العصبي من أنواع شلل العصب الجمجمي [لغات أخرى]، وضعف وجهي، وشلل المظهر السريري الأعراض نقص التوتر الوجهي [لغات أخرى] الإدارة أدوية هيوسين التاريخ وصفها المصدر معجم الت�...
Voce principale: Siracusa Calcio. Siracusa CalcioStagione 1978-1979Sport calcio Squadra Siracusa Allenatore Carlo Facchin Presidente Claudio Cassone Serie C2 - Gir. D2º posto (promosso in Serie C1) Coppa Italia SemiproVincitore Maggiori presenzeCampionato: Favero (33) Miglior marcatoreCampionato: Ballarin (17) 1977-1978 1979-1980 Si invita a seguire il modello di voce Questa voce raccoglie le informazioni riguardanti il Siracusa Calcio nelle competizioni ufficiali della stagione 1978-1...
Cet article est une ébauche concernant un réalisateur britannique. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les conventions filmographiques. Pour plus d’informations, voyez le projet Cinéma. Pour les articles homonymes, voir Wright. Joe Wright Au Comic-Con de San Diego, en juillet 2015. Données clés Nom de naissance Joseph Wright Naissance 25 août 1972 (51 ans)Londres (Angleterre) Nationalité Britannique Films notables Orgueil et Préjug�...
Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada November 2022. Hans BertramLahirHans-Karl Bertram(1906-02-26)26 Februari 1906Remscheid, JermanMeninggal8 Januari 1993(1993-01-08) (umur 86)Munich, JermanPekerjaanPenerbang, penulis naskah, sutradaraTahun aktif1938–85Suami/istriGisela UhlenKarier militerP...
Pékin 2008 Généralités Sport Triathlon Édition 3e Lieu(x) Pékin Participants 110 Épreuves 2 Palmarès Tenant du titre Hamish Carter Kate Allen Vainqueur Jan Frodeno Emma Snowsill Navigation Athènes 2004 Londres 2012 modifier Le Triathlon au réservoir des Tombeaux Ming . Les épreuves de triathlon aux Jeux olympiques d'été de 2008 se sont déroulées le 18 et 19 août 2008 à Pékin (République populaire de Chine), au bassin de Sanling, dans le quartier de Changping. Deux compéti...
Pemilihan umum Gubernur Bali 20031998200830 Juli 20036 Agustus 2003Kandidat Calon Gede Ngurah Wididana Dewa Made Beratha Tjokorda Gde Budi Suryawan Partai Fraksi Kesatuan Indonesia dan Fraksi Partai Golongan Karya Fraksi Partai Demokrasi Indonesia Perjuangan Fraksi Kesatuan Indonesia Pendamping I Putu Gede Ary Suta I Gusti Ngurah Kesuma Kelakan Anak Agung Hardiana Calon Anak Agung Gede Antara Partai Fraksi Partai Golongan Karya Pendamping Jro Gde Karang Tangkid Suwarsana Peta p...
مسيرة ملعب الثورة جزء من ثورة الشباب اليمنية 2011 التاريخ 27-4-2011 المكان Yemen ملعب مدينة الثورة الرياضية المظاهر مظاهرات مسيرات سلمية الأطراف المتظاهرين ضد الحكومة ونظام صالح الحكومة اليمنية الشرطة اليمنية الأمن المركزي اليمني القبائل الموالية للحكومة البلاطجة الخسائ�...
الأوضاع القانونية لزواج المثليين زواج المثليين يتم الاعتراف به وعقده هولندا1 بلجيكا إسبانبا كندا جنوب أفريقيا النرويج السويد المكسيك البرتغال آيسلندا الأرجنتين الدنمارك البرازيل فرنسا الأوروغواي نيوزيلندا3 المملكة المتحدة4 لوكسمبورغ الولايات المتحدة5 جمهورية أيرلندا ...
Mainz 05 IIStadionBruchwegstadion(Kapasitas: 7,378)ManajerBartosch GaulLigaRegionalliga Südwest2021–22ke-5, Regionalliga SüdwestSitus webSitus web resmi klub Kostum kandang Kostum tandang Kostum ketiga 1. FSV Mainz 05 II adalah tim cadangan klub sepak bola 1. FSV Mainz 05 yang berbasis di kota Mainz. Sejarah 1. FSV Mainz 05 II berhasil promosi ke 3. Liga pada tahun 2014.[1] Referensi ^ Fortuna Köln feiert Last-Minute-Aufstieg (dalam bahasa Jerman) Weltfussball.de, ...
SAGEMCompany logoJenisPublikIndustritelekomunikasiDidirikanParis, Prancis (1924)KantorpusatParis, PrancisProduktelekomunikasi, elektronika, sistem komunikasiSitus webwww.sagem.com SAGEM (Société d’Applications Générales de l’Électricité et de la Mécanique, atau diterjemahkan menjadi Perusahaan aplikasi elektrik dan mekanik umum) adalah perusahaan Prancis yang bergerak di bidang elektronika unutk pertahanan, rumah tangga dan sistem komunikasi. Pada 2005, Sagem bergabung dengan SNECM...
Bandar Udara Odate–Noshiro大館能代空港Terminal penumpang Bandar Udara Bandar Udara Odate–NoshiroIATA: ONJICAO: RJSRInformasiJenisPublikPengelolaAdministrasi Bandar Udara Odate–NoshiroMelayaniKitaakita, Ōdate, NoshiroLokasiKitaakita, Akita, JepangKetinggian dpl mdplSitus webonj-airterminal.comPetaRJSRTitik lokasi di petaLandasan pacu Arah Panjang Permukaan m kaki 11/29 2.000 6.562 Aspal beton Bandar Udara Odate–Noshiro (大館能代空港code: ja is deprecated , Odate-...
Women's 100 metres at the 1966 European Athletics ChampionshipsVenueNépstadionLocationBudapestDates30 August (heats)31 August (semifinals & final)Competitors23 from 10 nationsWinning time11.5Medalists Ewa Kłobukowska Poland Irena Kirszenstein Poland Karin Frisch West Germany← 19621969 → 1966 EuropeanAthletics ChampionshipsTrack events100 mmenwomen200 mmenwomen400 mmenwomen800 mmenwomen150...
Italian painter (1406–1486) Cassone Adimari, with The Triumph of Love shown as taking place in Piazza del Duomo in Florence; for a cassone Desco da parto, with a game of Civettino, recto c. 1450, by Giovanni di ser Giovanni Guidi Verso, as last. Two toddlers engage in no holds barred wrestling Giovanni di Ser Giovanni, (1406 – 1486) also known as Lo Scheggia, or the Splinter was an Italian Renaissance painter in Florence who was born in San Giovanni Valdarno and was the younger brothe...
2018 book by Bradley J Borougerdi Commodifying Cannabis AuthorBradley J BorougerdiSubjectEthnobotany, Cannabis industryGenreNonfictionPublished2018PublisherLexington BooksPages185ISBN9781498586375OCLC1048950003Websiterowman.com/ISBN/9781498586399/Commodifying-Cannabis-A-Cultural-History-of-a-Complex-Plant-in-the-Atlantic-World Commodifying Cannabis: A Cultural History of a Complex Plant in the Atlantic World is a 2018 nonfiction book by Bradley J Borougerdi about the historical and present co...
Chemical compound with the formula AgCl Silver chloride Names IUPAC name Silver(I) chloride Other names CerargyriteChlorargyriteHorn silver Argentous chloride Identifiers CAS Number 7783-90-6 Y 3D model (JSmol) Interactive image ChEBI CHEBI:30341 Y ChemSpider 22967 Y ECHA InfoCard 100.029.121 PubChem CID 24561 RTECS number VW3563000 UNII MWB0804EO7 Y CompTox Dashboard (EPA) DTXSID4035251 InChI InChI=1S/Ag.ClH/h;1H/q+1;/p-1 YKey: HKZLPVFGJNLROG-UHFFFAOYSA-M ...
Nota: Este artigo é sobre a artista. Para o álbum de estúdio autointitulado, veja Aaliyah (álbum). Aaliyah AaliyahAaliyah em maio de 2000. Nascimento Aaliyah Dana Haughton16 de janeiro de 1979Nova Iorque, Nova Iorque, EUA Morte 25 de agosto de 2001 (22 anos)Marsh Harbour, Ilhas Ábaco, Bahamas Causa da morte acidente aéreo Ocupação Cantora atriz dançarina modelo compositora produtora coreógrafa Período de atividade 1989–2001 Carreira musical Gênero(s) R&B ...
1917 songBring Back My Daddy To MeSongReleased1917Composer(s)George W. MeyerLyricist(s)William Tracey, Howard Johnson Bring Back My Daddy To Me is a World War I era song released in 1917. William Tracey and Howard Johnson wrote the lyrics. George W. Meyer composed the music.[1] Leo Feist, Inc. of New York, New York published the song. Sheet music The sheet music cover was designed by Rosenbaum Studios. It features child star Madge Evans in the center. Surrounding her image are silhoue...
Community Development Block in West Bengal, IndiaBasantiCommunity Development BlockInteractive Map Outlining Basanti CD BlockBasantiLocation in West BengalShow map of West BengalBasantiLocation in IndiaShow map of IndiaCoordinates: 22°11′54″N 88°42′50″E / 22.1983°N 88.7139°E / 22.1983; 88.7139Country IndiaState West BengalDistrictSouth 24 ParganasSubdivisionCanningArea • Total404.21 km2 (156.07 sq mi)Elevation6 m (20...
Battle of the Duisburg ConvoyPart of The Battle of the Mediterranean of the Second World WarItalian tanker Minatitlán on fire and sinking in the morning of 9 November 1941Date8/9 November 1941LocationOff Calabria, Mediterranean Sea37°08′N 18°09′E / 37.133°N 18.150°E / 37.133; 18.150Result British victoryBelligerents United Kingdom ItalyCommanders and leaders William Agnew Bruno BrivonesiStrength 2 light cruisers 2 destroyers 2 heavy cruisers 10 de...