Assignment No 2
Assignment No 2
Assignment Name:
Implement DDA and Bresenham line drawing algorithm to draw:
i) Simple Line
ii) Dotted Line
iii) Dashed Line
Using mouse interface Divide the screen in four quadrants with center as (0, 0). The line
should work for all the slopes positive as well as negative.
Advantages of DDA :
Disadvantages of DDA :
It deals with the rounding off operation and floating point arithmetic so it has high
time complexity.
As it is orientation dependent, so it has poor endpoint accuracy.
Due to the limited precision in the floating point representation it produces
cumulative error.
In this method, next pixel selected is that one who has the least distance from true line.
Steps:
1. Accept two endpoints from user and store the left endpoint in (x₀,y₀) as starting
point.
2. Plot the point (x₀,y₀)
3. Calculate all constants from two endpoints such as Dx, Dy, 2Dy,
2Dy-2Dx and find the starting value for the G as G= 2Dy-Dx.
4. For each column increment x and decide y-value by checking G>0 condition. If it
is true then increment y-value and add (2Dy-2Dx) to current value of G otherwise
add(2Dy) to G and don’t increment y-value. Plot next point.
5. Repeat step 4 till Dx times.
Advantage:
1. It involves only integer arithmetic, so it is simple.
3. It can be implemented using hardware because it does not use multiplication and division
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.
Conclusion:
Hence, We have Successfully implemented DDA and Bresenham’s Line Drawing
Algorithm