0% found this document useful (0 votes)
155 views13 pages

DDA Line Drawing

The DDA (Digital Differential Analyzer) line drawing algorithm is used to draw lines on a computer display by approximating line segments on discrete pixels. It works by calculating the change in x and y between the line's endpoints, determining how many steps are needed to traverse the line, and incrementing x and y by a fixed amount in each step based on the slope of the line until it reaches the endpoint. The algorithm has limitations as it cannot represent decimal points and can be time consuming to generate floating point numbers, resulting in jagged line drawings.

Uploaded by

Mazharulislam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views13 pages

DDA Line Drawing

The DDA (Digital Differential Analyzer) line drawing algorithm is used to draw lines on a computer display by approximating line segments on discrete pixels. It works by calculating the change in x and y between the line's endpoints, determining how many steps are needed to traverse the line, and incrementing x and y by a fixed amount in each step based on the slope of the line until it reaches the endpoint. The algorithm has limitations as it cannot represent decimal points and can be time consuming to generate floating point numbers, resulting in jagged line drawings.

Uploaded by

Mazharulislam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

DDA Line Drawing Algorithm

• DDA stands for Digital Differential Analyzer


• A line drawing algorithm is a graphical algorithm for approximating a line
segment on discrete graphical media.
• This algorithm is used to draw a line on computer pixels.
What is a Line?
• A line in Computer graphics typically refers to line segment, which is a
portion of straight line that extends indefinitely in opposite direction.
• It is defined by its two end points & the slope intercept equation for a line:
y = mx + b
where, m = Slope of the line
b = the y intercept of a line
• The two endpoints of a line segment are specified at positions (x1,y1) and
(x2,y2).
Slope Conditions for Algorithms

• 1. ∆ y/ ∆ x > 1 when 0 >45 1

• 2. ∆ y/ ∆ x < 1 when 0 <45


• 3. ∆ y /∆ x = 1 when 0 =45 2
For Horizontal line

(x1,y1)(x2,y2)
(2,2) (9,2) X Y

∆ x=9-2=7 2 2
9
3 2
∆ y=2-2=0 4 2
8
m= ∆ y/ ∆ x=0/7=0 5 2
7
6 2
6
xinc=7/7=1 5
7 2
yinc=0/7=0 8 2
4
9 2
3
2
1

1 2 3 4 5 6 7 8 9 10
For Horizontal line

(x1,y1)(x2,y2)
(2,2) (9,2) X Y

∆ x=9-2=7 2 2
9
3 2
∆ y=2-2=0 4 2
8
m= ∆ y/ ∆ x=0/7=0 5 2
7
6 2
6
xinc=7/7=1 5
7 2
yinc=0/7=0 8 2
4
9 2
3
2
1

1 2 3 4 5 6 7 8 9 10
For Vertical line

(x1,y1)(x2,y2)
(2,3) (2,8)
∆ x=2-2=0 X Y 9
∆ y=8-2=6 2 3 8
m= ∆ y/ ∆ x=6/0=∞ 2 4 7
2 5 6
xinc=0/6=0 2 6 5
yinc=6/6=1 2 7 4
2 8 3
2
1

1 2 3 4 5 6 7 8 9 10
For Vertical line

(x1,y1)(x2,y2)
(2,3) (2,8)
∆ x=2-2=0 X Y 9
∆ y=8-2=6 2 3 8
m= ∆ y/ ∆ x=6/0=∞ 2 4 7
2 5 6
xinc=0/6=0 2 6 5
yinc=6/6=1 2 7 4
2 8 3
2
1

1 2 3 4 5 6 7 8 9 10
For any Diagonal line

(x1,y1)(x2,y2)
(1,2) (9,5) X Y

∆ x=9-1=8 1 2
9
2 2.37=2
∆ y=5-2=3 3 2.74=3
8
m= ∆ y/ ∆ x=3/8=0.37 4 3.11=3
7
6
xinc=8/8=1 5 3.48=3
5
6 3.85=4
yinc=3/8=0.37 7 4.22=4
4
3
8 4.59=5
2
9 4.96=5
1

1 2 3 4 5 6 7 8 9 10
For any Diagnal line

(x1,y1)(x2,y2)
(1,2) (9,5) X Y

∆ x=9-1=8 1 2
9
2 2.37=2
∆ y=5-2=3 3 2.74=3
8
m= ∆ y/ ∆ x=3/8=0.37 4 3.11=3
7
6
xinc=8/8=1 5 3.48=3
5
6 3.85=4
yinc=3/8=0.37 7 4.22=4
4
3
8 4.59=5
2
9 4.96=5
1

1 2 3 4 5 6 7 8 9 10
DDA Algorithm
dx-=x2-x1;
dy=y2-y1;
If(abs(dx) > abs(dy))
Steps=abs(dx);
else
Steps=abs(dy);
xinc=dx/steps;
yinc=dy/steps;
For(i-1, i<=step, i++)
{
putpixel(x1,y1);
x1=x1+xinc;
y1=y1+yinc;
}
Limitation

• There are no decimal points in coordinate system


• Time consuming because algorithm may generate floating numbers
• Line generated will not be smooth.
References:

• https://www.tutorialspoint.com/computer_graphics/line_generation_algorit
hm.htm
• http://personales.unican.es/iglesias
• https://www.geeksforgeeks.org/dda-line-generation-algorithm
• https://www.tutorialspoint.com/.../line_generation_algorithm.htm
• www.codingalpha.com/dda-line-drawing-algorithm-c-program

You might also like