0% found this document useful (0 votes)
1 views

Assignment No 2

The document outlines the implementation of DDA and Bresenham line drawing algorithms for drawing simple, dotted, and dashed lines using a mouse interface. It details the steps involved in both algorithms, highlighting their advantages and disadvantages. The conclusion confirms the successful implementation of both algorithms.

Uploaded by

mayuri tambe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Assignment No 2

The document outlines the implementation of DDA and Bresenham line drawing algorithms for drawing simple, dotted, and dashed lines using a mouse interface. It details the steps involved in both algorithms, highlighting their advantages and disadvantages. The conclusion confirms the successful implementation of both algorithms.

Uploaded by

mayuri tambe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

1) DDA Line Drawing Algorithm


DDA stands for Digital Differential Analyzer. It is an incremental method of scan
conversion of line. In this method calculation is performed at each step but by
using results of previous steps.

DDA Line Drawing Algorithm:


• Step1: Start Algorithm
• Step2: Declare x1,y1,x2,y2,dx,dy,x,y as integer variables.
• Step3: Enter value of x1,y1,x2,y2.
• Step4: Calculate dx = x2-x1
• Step5: Calculate dy = y2-y1
• Step6: If ABS (dx) > =ABS (dy)
Then step = abs (dx)
Else steps=abs(dy)
• Step7: xinc=dx/step
yinc=dy/step
assign x = x1
assign y = y1
• Step8: Set pixel (x, y)
• Step9: Xnew = x + xinc
Ynew = y + yinc
Set pixels (Round (x), Round (y))
• Step10: Repeat step 9 until x = x2
• Step11: End Algorithm

Advantages of DDA :

 It is simple and easy to implement algorithm.


 It avoid using multiple operations which have high time complexities.
 It is faster than the direct use of the line equation because it does not use any
floating point multiplication and it calculates points on the line.

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.

2)Bresenham's 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.

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.

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.

Conclusion:
Hence, We have Successfully implemented DDA and Bresenham’s Line Drawing
Algorithm

You might also like