C59 Exp1
C59 Exp1
A.3 Outcome:
After successful completion of this experiment students will
be able to
A.4 Theory:
DDA algorithm:
Input to the function is two endpoints (x1,y1) and (x2,y2)
1. length =abs(x2-x1);
2. if (abs(y2-y1) > length) then length =abs(y2-y1);
3. xincrement (x2-x1) / length;
4. yincrement (y2-y1) / length;
5. x =x + 0.5; y =Y + 0.5;
6. for i 1 to length follow steps 7 to 9
7. plot (trunc(x),trunc(y));
8. x= x + xincrement ;
9. y =y + yincrement ;
10.stop.
Bresenham's Line Drawing Algorithm:
1. Input the two line endpoints and store the left endpoint in(x0,y0)
2. Load ( x0,y0 ) into the frame buffer; that is , plot the first point.
3. Calculate constants dx, dy,2 dy and 2 dy -2 dx , and obtain the starting value for
the decision parameter as:
p0 = 2 dy - dx
4. At each xk, the next point the line , starting at k=0, perform the following test:
If pk < 0 , the next point to plot is (xk + 1 ,yk ) and
pk+1 = pk + 2 dy
Otherwise ,the next point to plot is (xk + 1, yk +1) and
pk+1 = pk + 2 dy - 2 dx
5.Repeat step 4 dx times.
A.5 Procedure:
DDA Algorithm:
Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm.
Step 1 − Get the input of two end points (X0,Y0) and (X1,Y1).
Step 3 − Based on the calculated difference in step-2, you need to identify the number of steps to
put pixel.
If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate.
Assumption :
Y=mX+b
where b is the intercept cut by line at Y axis and m is the
slope of line
(0 <= m < 1)
Derivation :
Initially we have plotted a point (Xk , Yk) and increase
X by 1 we come to Xk+1.
Decision Parameter(Pk) - (Xk+1 , Yk+1)
- (Xk+1 , Yk)
D1 = Y – Yk
D1 = m(Xk+1)+b – Yk
D2 = Yk+1 – Y
D2 = Yk+1 – [m(Xk+1)+b]
D1-D2 = m(Xk+1) – Yk - Yk+1 + m(Xk+1) + 2b
D1-D2 = 2m(Xk+1) + 2b – Yk – Yk+1
D1-D2 = 2mXk + 2m – 2Yk + (2b-1)
Put m = dY/dX
(D1-D2)dX = 2Xk dY – 2Yk dX + 2dY + (2b-1)dX
Pk = 2Xk dY – 2Yk dX + C
Where C = 2dY + (2b-1)dX
(D1-D2)dx >= 0
Xk+1 – Xk = 1
Yk+1 – Yk = 1
put these value in A
PART B
DDA Algorithm:
BRESENHAM’S Line Drawing Algorithm.
B.3 Observations and learning:
DDA Algorithm: Simple but slower due to floating-point operations. Requires rounding
and handles all slopes.
Bresenham's Algorithm: Faster as it uses only integer operations. More efficient and
accurate, especially for lines with steep slopes.
Learning:
DDA is easier to implement but less efficient.
Bresenham's is optimal for raster devices, minimizing computation and improving
performance in graphics applications.
B.4 Conclusion:
Bresenham's line drawing algorithm is preferred over DDA for its efficiency, accuracy, and use
of integer arithmetic, making it more suitable for real-time applications in computer graphics.
Ipfilt-FU NextMsgñlt-F?Prev
Q.1] Write Disadvantages of DDA line algorithm. How it is overcome by Bresenham
Line Drawing algorithm.
Q.2] Plot the Line for co-ordinates 100,100 to 150,150 using DDA and Bresenham
Line Drawing algorithm.
Step-by-Step Calculation:
dx = 150 - 100 = 50
dy = 150 - 100 = 50
Plotting Points:
Start at (100, 100)
Step-by-Step Calculation:
Start Point: (100, 100)
End Point: (150, 150)
dx = 50
dy = 50
Increment values: