Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Bresenham's line algorithm
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Method== [[File:Bresenham.svg|right|300px|thumb|Illustration of the result of Bresenham's line algorithm. (0,0) is at the top left corner of the grid, (1,1) is at the top left end of the line and (11, 5) is at the bottom right end of the line.]] 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 <math>(x_0,y_0)</math> and <math>(x_1,y_1)</math>, 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 (plane geometry)|octant]] in which the segment goes down and to the right (<math>x_0 \leq x_1</math> and <math>y_0 \leq y_1</math>), and its horizontal projection <math>x_1-x_0</math> is longer than the vertical projection <math>y_1-y_0</math> (the line has a positive [[slope]] less than 1). In this octant, for each column ''x'' between <math>x_0</math> and <math>x_1</math>, there is exactly one row ''y'' (computed by the algorithm) containing a pixel of the line, while each row between <math>y_0</math> and <math>y_1</math> 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: :<math>\frac{y - y_0}{y_1-y_0} = \frac{x-x_0}{x_1-x_0}</math>. Since we know the column, ''x'', the pixel's row, ''y'', is given by rounding this quantity to the nearest integer: :<math>y = \frac{y_1-y_0}{x_1-x_0} (x-x_0) + y_0</math>. The slope <math>(y_1-y_0)/(x_1-x_0)</math> 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 <math>y_0</math> 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 <math>y_0-0.5</math> (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.<ref>{{Cite web|url=https://www.ercankoclar.com/wp-content/uploads/2016/12/Bresenhams-Algorithm.pdf|title=Bresenham's Algorithm|last=Joy|first=Kenneth|publisher=Visualization and Graphics Research Group, Department of Computer Science, University of California, Davis|access-date=20 December 2016}}</ref>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Bresenham's line algorithm
(section)
Add topic