Lecture Two COMPUTER GRAPHICS
Lecture Two COMPUTER GRAPHICS
Viewport
Rasterization
Transformatio
n
ADVANTAGE OF DEVELOPING ALGORITHMS
FOR SCAN CONVERSION
Special Cases
If chosen pixel is at the top pixel T (i.e., di≥0)⟹ yi+1=yi+1
di+1=di+2△y-2△x
If chosen pixel is at the bottom pixel T (i.e., di<0)⟹ yi+1=yi
di+1=di+2△y
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 = , we have
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 part of Bresenham's line
algorithm. So to draw smooth lines, you should
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
Where x1,y1are coordinates of starting point
And x2,y2 are coordinates of Ending point
Step4: Calculate dx = x2-x1
Calculate dy = y2-y1
Calculate i1=2*dy
Calculate i2=2*(dy-dx)
Calculate d=i1-dx
Step5: Consider (x, y) as starting point and xendas maximum possible value of x.
If dx < 0
Then x = x2
y = y2
xend=x1
If dx > 0
Then x = x1
y = y1
xend=x2
Step6: Generate point at (x,y)coordinates.
Step7: Check if whole line is generated.
If x > = xend
Stop.
Step8: Calculate co-ordinates of the next pixel
If d < 0
Then d = d + i1
If d ≥ 0
Then d = d + i2
Increment y = y + 1
Step9: Increment x = x + 1
Step10: Draw a point of latest (x, y) coordinates
Step11: Go to step 7
• Example: Starting and Ending position of the line
are (1, 1) and (8, 5). Find intermediate points.
Solution: x1=1
y1=1
x2=8
y2=5
dx= x2-x1=8-1=7
dy=y2-y1=5-1=4
I1=2* ∆y=2*4=8
I2=2*(∆y-∆x)=2*(4-7)=-6
d = I1-∆x=8-7=1
x y d=d+I1 or I2
1 1 d+I2=1+(-6)=-5
2 2 d+I1=-5+8=3
3 2 d+I2=3+(-6)=-3
4 3 d+I1=-3+8=5
5 3 d+I2=5+(-6)=-1
6 4 d+I1=-1+8=7
7 4 d+I2=7+(-6)=1
8 5
Differentiate between DDA Algorithm and
Bresenham's Line Algorithm
DDA Algorithm Bresenham's Line Algorithm
1. DDA Algorithm use floating point, i.e., 1. Bresenham's Line Algorithm use fixed
Real Arithmetic. point, i.e., Integer Arithmetic
2. DDA Algorithms uses multiplication & 2.Bresenham's Line Algorithm uses only
division its operation subtraction and addition its operation
5.DDA Algorithm can draw circle and 5. Bresenham's Line Algorithm can draw
curves but are not accurate as circle and curves with more accurate than
Bresenham's Line Algorithm DDA Algorithm.