Bresenhams Line Generation Algorithm 23-03-2020


Instruction: First of all carefully watch video lecture then read theory.
Video Lecture: Bresenhams 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
  1. Either the one to its right (lower-bound for the line)
  2. One top its right and up (upper-bound for the line)
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.

If S is chosen            
                               We have xi+1=xi+1   and       yi+1=yi
If T is chosen                       
                                We have xi+1=xi+1    and      yi+1=yi+1
The actual y coordinates of the line at  x = xi+1is           

y=mxi+1+b
Bresenham's Line Algorithm

The distance from S to the actual line in y direction                       
                                                      s = y-yi
The distance from T to the actual line in y direction                       
t = (yi+1)-y.
Now consider the difference between these 2 distance values s - t.
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           

 s-t = (y-yi)-[(yi+1)-y] 
= 2y - 2yi -1

                            Bresenham's Line Algorithm


Substituting m by Bresenham's Line Algorithm and introducing decision variable                
di=x (s-t)                                   
di=x (2 Bresenham's Line Algorithm (xi+1)+2b-2yi-1)                                     
=2xyi-2y-1x.2b-2yix-x                                                      
di=2y.xi-2x.yi+c

Where c= 2y+x (2b-1).
We can write the decision variable di+1 for the next slip on                    
di+1=2y.xi+1-2x.yi+1+c                                   
di+1-di=2y.(xi+1-xi)- 2x(yi+1-yi)

Since x_(i+1)=xi+1,we have                     
di+1+di=2y.(xi+1-xi)- 2x(yi+1-yi).
If chosen pixel is at the top pixel T        
(i.e., di≥0) yi+1=yi+1                                   
di+1=di+2y-2x.
If chosen pixel is at the bottom pixel T      
(i.e., di<0) yi+1=yi                                                              
di+1=di+2y.
Finally, we calculate d1                       
d1=x[2m(x1+1)+2b-2y1-1]                       
d1=x[2(mx1+b-y1)+2m-1].
Since 
mx1+b-yi=0     and                      m = Bresenham's Line Algorithm, we have                                     
d1=2y-x

Advantage:
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.

Disadvantage:

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.

Comments

  1. AOA
    mam agar hum video wali e derivation likh lain yahan jo theory main derive hua hay wo nw likhain bs thoery portion iss ka kr lain and video say derivation koi masla to nae ho ga?????

    ReplyDelete

Post a Comment