Exp 3_Computer Graphics_Lab
Exp 3_Computer Graphics_Lab
Aim/Overview of the practical : Scan convert a line with starting points (10, 10) and (20,30) using
bresenhams line drawing 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.
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').
62.5M
1K
Hello Java Program for Beginners
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
This difference is
s-t = (y-yi)-[(yi+1)-y]
= 2y - 2yi -1
di=△x (2 (xi+1)+2b-2yi-1)
=2△xyi-2△y-1△x.2b-2yi△x-△x
di=2△y.xi-2△x.yi+c
We can write the decision variable di+1 for the next slip on
di+1=2△y.xi+1-2△x.yi+1+c
di+1-di=2△y.(xi+1-xi)- 2△x(yi+1-yi)
Special Cases
Finally, we calculate d1
d1=△x[2m(x1+1)+2b-2y1-1]
d1=△x[2(mx1+b-y1)+2m-1]
Advantage:
1. It involves only integer arithmetic, so it is simple.
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.
Step5: Consider (x, y) as starting point and x endas 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
Step9: Increment x = x + 1
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.
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
Result/Output/Writing Summary:
Evaluation Grid: