Bresenham's Line Algorithm
This algorithm is used for scan converting a line. It was developed by Bresenham. It is an efficient method because it involves only integer addition, subtractions, and multiplication operations. These operations can be performed very rapidly so lines can be generated quickly.
In this method, next pixel selected is that one who has the least distance from true line.
The method works as follows:
Assume a pixel P1'(x1',y1'),then select subsequent pixels as we work our may to the night, one pixel position at a time in the horizontal direction toward P2'(x2',y2').
Once a pixel in choose at any step
The next pixel is
The line is best approximated by those pixels that fall the least distance from the path between P1',P2'.
To chooses the next one between the bottom pixel S and top pixel T.
The actual y coordinates of the line at x = xi+1is
The distance from S to the actual line in y direction
The distance from T to the actual line in y direction
Now consider the difference between these 2 distance values
When (s-t) <0 ⟹ s < t
The closest pixel is S
When (s-t) ≥0 ⟹ s < t
The closest pixel is T
This difference is
Substituting m by and introducing decision variable
Where c= 2△y+△x (2b-1)
We can write the decision variable di+1 for the next slip on
Since x_(i+1)=xi+1,we have
If chosen pixel is at the top pixel T (i.e., di≥0)⟹ yi+1=yi+1
If chosen pixel is at the bottom pixel T (i.e., di<0)⟹ yi+1=yi
Finally, we calculate d1
Since mx1+b-yi=0 and m = , we have
1. It involves only integer arithmetic, so it is simple.
2. It avoids the generation of duplicate points.
3. It can be implemented using hardware because it does not use multiplication and division.
4. It is faster as compared to DDA (Digital Differential Analyzer) because it does not involve floating point calculations like DDA Algorithm.
1. This algorithm is meant for basic line drawing only Initializing is not a part of Bresenham's line algorithm. So to draw smooth lines, you should want to look into a different algorithm.
Bresenham's Line Algorithm:
Step1: Start Algorithm
Step2: Declare variable x1,x2,y1,y2,d,i1,i2,dx,dy
Step3: Enter value of x1,y1,x2,y2
Step4: Calculate dx = x2-x1
Step5: Consider (x, y) as starting point and xendas maximum possible value of x.
Step6: Generate point at (x,y)coordinates.
Step7: Check if whole line is generated.
Step8: Calculate co-ordinates of the next pixel
Step9: Increment x = x + 1
Step10: Draw a point of latest (x, y) coordinates
Step11: Go to step 7
Step12: End of Algorithm
Example: Starting and Ending position of the line are (1, 1) and (8, 5). Find intermediate points.
Program to implement Bresenham's Line Drawing Algorithm:
Differentiate between DDA Algorithm and Bresenham's Line Algorithm:
Next TopicDefining a Circle