DDA Line Drawing
Algorithm
Muhammad Hamza
157101
Bioinformatics 7th
Graphics andVisualization
Presented to: Sir Muhammad Rizwan
Govt Post Graduate College Mandian
Abbottabad
Talk Sequence:
• What is Line
• Line Equation
• Slope of Line
• Examples of Drawing Line
• DDA
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
• 2. ∆ y/ ∆ x < 1 when 0 <45
• 3. ∆ y /∆ x = 1 when 0 =45
1
2
3
9
8
7
6
5
4
3
2
1
(x1,y1)(x2,y2)
(2,2) (9,2)
∆ x=9-2=7
∆ y=2-2=0
m= ∆ y/ ∆ x=0/7=0
xinc=7/7=1
yinc=0/7=0
X Y
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
1 2 3 4 5 6 7 8 9 10
For Horizontal line
9
8
7
6
5
4
3
2
1
1 2 3 4 5 6 7 8 9 10
(x1,y1)(x2,y2)
(2,2) (9,2)
∆ x=9-2=7
∆ y=2-2=0
m= ∆ y/ ∆ x=0/7=0
xinc=7/7=1
yinc=0/7=0
X Y
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
For Horizontal line
9
8
7
6
5
4
3
2
1
1 2 3 4 5 6 7 8 9 10
(x1,y1)(x2,y2)
(2,3) (2,8)
∆ x=2-2=0
∆ y=8-2=6
m= ∆ y/ ∆ x=6/0=∞
xinc=0/6=0
yinc=6/6=1
X Y
2 3
2 4
2 5
2 6
2 7
2 8
For Vertical line
9
8
7
6
5
4
3
2
1
1 2 3 4 5 6 7 8 9 10
(x1,y1)(x2,y2)
(2,3) (2,8)
∆ x=2-2=0
∆ y=8-2=6
m= ∆ y/ ∆ x=6/0=∞
xinc=0/6=0
yinc=6/6=1
X Y
2 3
2 4
2 5
2 6
2 7
2 8
For Vertical line
9
8
7
6
5
4
3
2
1
1 2 3 4 5 6 7 8 9 10
(x1,y1)(x2,y2)
(1,2) (9,5)
∆ x=9-1=8
∆ y=5-2=3
m= ∆ y/ ∆ x=3/8=0.37
xinc=8/8=1
yinc=3/8=0.37
X Y
1 2
2 2.37=2
3 2.74=3
4 3.11=3
5 3.48=3
6 3.85=4
7 4.22=4
8 4.59=5
9 4.96=5
For any Diagonal line
9
8
7
6
5
4
3
2
1
1 2 3 4 5 6 7 8 9 10
(x1,y1)(x2,y2)
(1,2) (9,5)
∆ x=9-1=8
∆ y=5-2=3
m= ∆ y/ ∆ x=3/8=0.37
xinc=8/8=1
yinc=3/8=0.37
X Y
1 2
2 2.37=2
3 2.74=3
4 3.11=3
5 3.48=3
6 3.85=4
7 4.22=4
8 4.59=5
9 4.96=5
For any Diagnal line
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

Dda line algorithm presentatiion

  • 1.
    DDA Line Drawing Algorithm MuhammadHamza 157101 Bioinformatics 7th Graphics andVisualization Presented to: Sir Muhammad Rizwan Govt Post Graduate College Mandian Abbottabad
  • 2.
    Talk Sequence: • Whatis Line • Line Equation • Slope of Line • Examples of Drawing Line • DDA
  • 3.
    DDA Line DrawingAlgorithm • 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.
  • 4.
    What is aLine? • 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
  • 5.
    • The twoendpoints of a line segment are specified at positions (x1,y1) and (x2,y2).
  • 6.
    Slope Conditions forAlgorithms • 1. ∆ y/ ∆ x > 1 when 0 >45 • 2. ∆ y/ ∆ x < 1 when 0 <45 • 3. ∆ y /∆ x = 1 when 0 =45 1 2 3
  • 7.
    9 8 7 6 5 4 3 2 1 (x1,y1)(x2,y2) (2,2) (9,2) ∆ x=9-2=7 ∆y=2-2=0 m= ∆ y/ ∆ x=0/7=0 xinc=7/7=1 yinc=0/7=0 X Y 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 1 2 3 4 5 6 7 8 9 10 For Horizontal line
  • 8.
    9 8 7 6 5 4 3 2 1 1 2 34 5 6 7 8 9 10 (x1,y1)(x2,y2) (2,2) (9,2) ∆ x=9-2=7 ∆ y=2-2=0 m= ∆ y/ ∆ x=0/7=0 xinc=7/7=1 yinc=0/7=0 X Y 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 For Horizontal line
  • 9.
    9 8 7 6 5 4 3 2 1 1 2 34 5 6 7 8 9 10 (x1,y1)(x2,y2) (2,3) (2,8) ∆ x=2-2=0 ∆ y=8-2=6 m= ∆ y/ ∆ x=6/0=∞ xinc=0/6=0 yinc=6/6=1 X Y 2 3 2 4 2 5 2 6 2 7 2 8 For Vertical line
  • 10.
    9 8 7 6 5 4 3 2 1 1 2 34 5 6 7 8 9 10 (x1,y1)(x2,y2) (2,3) (2,8) ∆ x=2-2=0 ∆ y=8-2=6 m= ∆ y/ ∆ x=6/0=∞ xinc=0/6=0 yinc=6/6=1 X Y 2 3 2 4 2 5 2 6 2 7 2 8 For Vertical line
  • 11.
    9 8 7 6 5 4 3 2 1 1 2 34 5 6 7 8 9 10 (x1,y1)(x2,y2) (1,2) (9,5) ∆ x=9-1=8 ∆ y=5-2=3 m= ∆ y/ ∆ x=3/8=0.37 xinc=8/8=1 yinc=3/8=0.37 X Y 1 2 2 2.37=2 3 2.74=3 4 3.11=3 5 3.48=3 6 3.85=4 7 4.22=4 8 4.59=5 9 4.96=5 For any Diagonal line
  • 12.
    9 8 7 6 5 4 3 2 1 1 2 34 5 6 7 8 9 10 (x1,y1)(x2,y2) (1,2) (9,5) ∆ x=9-1=8 ∆ y=5-2=3 m= ∆ y/ ∆ x=3/8=0.37 xinc=8/8=1 yinc=3/8=0.37 X Y 1 2 2 2.37=2 3 2.74=3 4 3.11=3 5 3.48=3 6 3.85=4 7 4.22=4 8 4.59=5 9 4.96=5 For any Diagnal line
  • 13.
    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; }
  • 14.
    Limitation • There areno decimal points in coordinate system • Time consuming because algorithm may generate floating numbers • Line generated will not be smooth.
  • 15.
    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