|Published (Last):||2 July 2016|
|PDF File Size:||18.45 Mb|
|ePub File Size:||3.45 Mb|
|Price:||Free* [*Free Regsitration Required]|
Given coordinate of two points A x1, y1 and B x2, y2. The task to find all the intermediate points required for drawing line AB on the computer screen of pixels. Note that every pixel has integer coordinates.
Above algorithm works, but it is slow. The idea is to keep track of slope error from previous increment to y. If the slope error becomes greater than 0.
How to avoid floating point arithmetic The above algorithm still includes floating point arithmetic. To avoid floating point arithmetic, consider the value below value m. To avoid comparison with 0. Refer this for proof of this value. Below is the implementation of above algorithm. The above explanation is to provides a rough idea behind the algorithm.
For detailed explanation and proof, readers can refer below references. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.
See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement for details. Writing code in comment? Please use ide. Examples: Input : A 0,0 , B 4,4 Output : 0,0 , 1,1 , 2,2 , 3,3 , 4,4 Input : A 0,0 , B 4,2 Output : 0,0 , 1,0 , 2,1 , 3,1 , 4,2 Below are some assumptions to keep algorithm simple.
We draw a line from lower left to upper. Add slope to increment angle formed. Slope error reached limit, time to. This code is contributed by ash Improved By : nitin mittal , ash , gurrrung. Load Comments.
Bresenham Line Drawing 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 line primitives in a bitmap image e. It is an incremental error algorithm. It is one of the earliest algorithms developed in the field of computer graphics. An extension to the original algorithm may be used for drawing circles. While algorithms such as Wu's algorithm are also frequently used in modern computer graphics because they can support antialiasing , the speed and simplicity of Bresenham's line algorithm means that it is still important.
Bresenham’s Line Generation Algorithm
Given coordinate of two points A x1, y1 and B x2, y2. The task to find all the intermediate points required for drawing line AB on the computer screen of pixels. Note that every pixel has integer coordinates. Above algorithm works, but it is slow. The idea is to keep track of slope error from previous increment to y. If the slope error becomes greater than 0.