SlideShare a Scribd company logo
1 of 12
Line Drawing Algorithms

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               (1)
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).
          y
                              P2(x2,y2)


                  P1(x1,y1)
          b

              0
                                x
We can determine the value for slope m & b
  intercept as
            m = y2-y1/x2-x1                (2)
And,         b = y1 – mx1                   (3)
For a given x interval Δx along a line, we can
compute the corresponding y interval Δy from
            Δy = m Δx                      (4)
Similarly, we can obtain x interval Δx by Δy:
            Δx = Δy/m                      (5)
If |m|<1, then for every integer value of x
    between and excluding x1 and x2, calculate
    the corresponding value of y using
    equation Δy = m Δx & scan convert (x,y).
If |m|>1, then for every integer value of y
    between and excluding y1 and y2, calculate
    the corresponding value of x using
    equation Δx = Δy/m & scan convert (x,y).
If |m|=1, Δx = Δy. In each case, a smooth line
    with slope m is generated between the
    specific endpoints.
Example 1 The endpoints of line are(0,0) &
  (6,18). Compute each value of y as x steps
  from 0 to 6 and plot the result.
Solution : Equation of line is y= mx +b
m = y2-y1/x2-x1= 18-0/6-0 = 3
Next the y intercept b is found by plugging
  y1& x1 into the equation y = 3x + b,
  0 = 3(0) + b. Therefore, b=0, so the
  equation for the line is y= 3x.
While this approach is mathematically sound,
 it involves floating-point computation
 (multiplication & addition) in every step
 that uses the line equation since m & b are
 generally real numbers. The challenge is to
 find a way to achieve the same goal as
 quickly as possible.
DDA Algorithm
     The digital differential analyzer (DDA)
algorithm is an incremental scan-
conversion method. Such an approach is
characterized by performing calculations at
each step using results from the preceding
step. Suppose, at step i we have
calculated(xi, yi) to be a point on the
line.Since the next point (xi+1,yi+1) should
satisfy Δy/Δx= m where Δy= yi+1 – yi &
Δx = xi+1 – xi.
We have, yi+1 = yi + mΔx
            yi+1 = yi + Δy            (1)
Or          xi+1 = xi + Δy/m          (2)
Algorithm:
(x1,y1) (x2,y2) are the end points and dx, dy are the
   float variables.
(i) If abs(x2-x1) > abs(y2-y1) then
          length = abs(x2-x1)
     else
          length = abs(y2-y1)
     endif
(ii)    dx = (x2-x1)/length
        dy = (y2-y1)/length
(iii)   x = x1 + 0.5
        y = y1 + 0.5
(iv)    i=0
(v)     Plot (trunc(x), trunc(y))
(vi)     x = x + dx
          y = y + dy
(vii)    i=i+1
(viii) If i < length then go to step (v)
(ix) Stop
Example 2 Scan convert a line having end
     points (3,2) & (4,7) using DDA.
Solution: x2 - x1 = 4-3 = 1
              y2 - y1 = 7-2 = 5
As, abs(x2-x1) < abs(y2-y1) then
       length = y2-y1 = 5
    dx = (x2-x1)/ length = 1/5 = .2
    dy = (y2-y1)/ length = 5/5 = 1
x1 y1 x2 y2 L dx dy i x     y     Result     Plot
3 2 4 7 5 .2 1 0 3.5        2.5   3.5, 2.5   3,2
                    1 3.7   3.5   3.7,3.5    3,3
                    2 3.9   4.5   3.9,4.5    3,4
                    3 4.1   5.5   4.1,5.5    4,5
                    4 4.3   6.5   4.3,6.5    4,6
                    5 4.5   7.5   4.5,7.5    4,7
Limitations of DDA:
(1) The rounding operation & floating point
    arithmetic are time consuming procedures.
(2) The accumulation of round-off error in
    successive addition of floating point
    increment can cause the calculated pixel
    position to drift away from the true line
    path for long line segment.

More Related Content

What's hot

Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notessmruti sarangi
 
COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"Ankit Surti
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)shalinikarunakaran1
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output PrimitivesRenita Santhmayora
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesOmprakash Chauhan
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output PrimitivesPrathimaBaliga
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithmMani Kanth
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformationsMohd Arif
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
2 d viewing computer graphics
2 d viewing computer graphics2 d viewing computer graphics
2 d viewing computer graphicsKALESHWAR KUMAR
 
Scan line method
Scan line methodScan line method
Scan line methodPooja Dixit
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithmAparna Joshi
 
4. THREE DIMENSIONAL DISPLAY METHODS
4.	THREE DIMENSIONAL DISPLAY METHODS4.	THREE DIMENSIONAL DISPLAY METHODS
4. THREE DIMENSIONAL DISPLAY METHODSSanthiNivas
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphicsSHIVANI SONI
 

What's hot (20)

BRESENHAM’S LINE DRAWING ALGORITHM
BRESENHAM’S  LINE DRAWING ALGORITHMBRESENHAM’S  LINE DRAWING ALGORITHM
BRESENHAM’S LINE DRAWING ALGORITHM
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"
 
Three dimensional concepts - Computer Graphics
Three dimensional concepts - Computer GraphicsThree dimensional concepts - Computer Graphics
Three dimensional concepts - Computer Graphics
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 
Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithm
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
2 d viewing computer graphics
2 d viewing computer graphics2 d viewing computer graphics
2 d viewing computer graphics
 
Scan line method
Scan line methodScan line method
Scan line method
 
3D Transformation
3D Transformation 3D Transformation
3D Transformation
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
 
4. THREE DIMENSIONAL DISPLAY METHODS
4.	THREE DIMENSIONAL DISPLAY METHODS4.	THREE DIMENSIONAL DISPLAY METHODS
4. THREE DIMENSIONAL DISPLAY METHODS
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
 

Viewers also liked

Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer GraphicsLaxman Puri
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in GraphicsRajani Thite
 
dda algorithm
dda  algorithmdda  algorithm
dda algorithm774474
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmKasun Ranga Wijeweera
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmMahesh Kodituwakku
 
Bresenham's line algo.
Bresenham's line algo.Bresenham's line algo.
Bresenham's line algo.Mohd Arif
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Saikrishna Tanguturu
 
Vector graphics
Vector graphicsVector graphics
Vector graphicslenance
 
Analytical chemistry_Instrumentation_Introduction
Analytical chemistry_Instrumentation_IntroductionAnalytical chemistry_Instrumentation_Introduction
Analytical chemistry_Instrumentation_IntroductionBivek Timalsina
 
Hermite spline english_20161201_jintaeks
Hermite spline english_20161201_jintaeksHermite spline english_20161201_jintaeks
Hermite spline english_20161201_jintaeksJinTaek Seo
 
Presentation non parametric
Presentation non parametricPresentation non parametric
Presentation non parametricIrfan Hussain
 
Parametric equations
Parametric equationsParametric equations
Parametric equationsTarun Gehlot
 
Presentation on bezier curve
Presentation on bezier curvePresentation on bezier curve
Presentation on bezier curveSatyendra Rajput
 

Viewers also liked (20)

Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
 
dda algorithm
dda  algorithmdda  algorithm
dda algorithm
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Bresenham's line algo.
Bresenham's line algo.Bresenham's line algo.
Bresenham's line algo.
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Anti aliasing Computer Graphics
Anti aliasing Computer GraphicsAnti aliasing Computer Graphics
Anti aliasing Computer Graphics
 
Lecture15 anti aliasing
Lecture15 anti aliasingLecture15 anti aliasing
Lecture15 anti aliasing
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
 
Vector graphics
Vector graphicsVector graphics
Vector graphics
 
Analytical chemistry_Instrumentation_Introduction
Analytical chemistry_Instrumentation_IntroductionAnalytical chemistry_Instrumentation_Introduction
Analytical chemistry_Instrumentation_Introduction
 
Perspective projection
Perspective projectionPerspective projection
Perspective projection
 
hermite cubic spline curve
hermite cubic spline curvehermite cubic spline curve
hermite cubic spline curve
 
[Download] rev chapter-5-june26th
[Download] rev chapter-5-june26th[Download] rev chapter-5-june26th
[Download] rev chapter-5-june26th
 
Hermite spline english_20161201_jintaeks
Hermite spline english_20161201_jintaeksHermite spline english_20161201_jintaeks
Hermite spline english_20161201_jintaeks
 
Presentation non parametric
Presentation non parametricPresentation non parametric
Presentation non parametric
 
Parametric equations
Parametric equationsParametric equations
Parametric equations
 
Presentation on bezier curve
Presentation on bezier curvePresentation on bezier curve
Presentation on bezier curve
 

Similar to Line drawing algo.

Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxR S Anu Prabha
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxIndhuMcamphil
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxAlamelu
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxNaveenaKarthik3
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenhamsimpleok
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptxAhmadAbba6
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationMuhammad Fiaz
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptxssuser255bf1
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniyaTutorialsDuniya.com
 
Applications of Differential Calculus in real life
Applications of Differential Calculus in real life Applications of Differential Calculus in real life
Applications of Differential Calculus in real life OlooPundit
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c versionMarwa Al-Rikaby
 

Similar to Line drawing algo. (20)

Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenham
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniya
 
Applications of Differential Calculus in real life
Applications of Differential Calculus in real life Applications of Differential Calculus in real life
Applications of Differential Calculus in real life
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Nis differentiation1
Nis differentiation1Nis differentiation1
Nis differentiation1
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
 

More from Mohd Arif

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcpMohd Arif
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarpMohd Arif
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocolMohd Arif
 
Project identification
Project identificationProject identification
Project identificationMohd Arif
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniquesMohd Arif
 
Presentation
PresentationPresentation
PresentationMohd Arif
 
Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peerMohd Arif
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systemsMohd Arif
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdpMohd Arif
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgetingMohd Arif
 
Network management
Network managementNetwork management
Network managementMohd Arif
 
Networing basics
Networing basicsNetworing basics
Networing basicsMohd Arif
 
Iris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformIris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformMohd Arif
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and sslMohd Arif
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psecMohd Arif
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardwareMohd Arif
 

More from Mohd Arif (20)

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcp
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarp
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
 
Project identification
Project identificationProject identification
Project identification
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniques
 
Presentation
PresentationPresentation
Presentation
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peer
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systems
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgeting
 
Network management
Network managementNetwork management
Network management
 
Networing basics
Networing basicsNetworing basics
Networing basics
 
Loaders
LoadersLoaders
Loaders
 
Lists
ListsLists
Lists
 
Iris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformIris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platform
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and ssl
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psec
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardware
 
Heap sort
Heap sortHeap sort
Heap sort
 

Line drawing algo.

  • 1. Line Drawing Algorithms 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 (1) where, m = Slope of the line b = the y intercept of a line
  • 2. The two endpoints of a line segment are specified at positions (x1,y1) and (x2,y2). y P2(x2,y2) P1(x1,y1) b 0 x
  • 3. We can determine the value for slope m & b intercept as m = y2-y1/x2-x1 (2) And, b = y1 – mx1 (3) For a given x interval Δx along a line, we can compute the corresponding y interval Δy from Δy = m Δx (4) Similarly, we can obtain x interval Δx by Δy: Δx = Δy/m (5)
  • 4. If |m|<1, then for every integer value of x between and excluding x1 and x2, calculate the corresponding value of y using equation Δy = m Δx & scan convert (x,y). If |m|>1, then for every integer value of y between and excluding y1 and y2, calculate the corresponding value of x using equation Δx = Δy/m & scan convert (x,y). If |m|=1, Δx = Δy. In each case, a smooth line with slope m is generated between the specific endpoints.
  • 5. Example 1 The endpoints of line are(0,0) & (6,18). Compute each value of y as x steps from 0 to 6 and plot the result. Solution : Equation of line is y= mx +b m = y2-y1/x2-x1= 18-0/6-0 = 3 Next the y intercept b is found by plugging y1& x1 into the equation y = 3x + b, 0 = 3(0) + b. Therefore, b=0, so the equation for the line is y= 3x.
  • 6. While this approach is mathematically sound, it involves floating-point computation (multiplication & addition) in every step that uses the line equation since m & b are generally real numbers. The challenge is to find a way to achieve the same goal as quickly as possible.
  • 7. DDA Algorithm The digital differential analyzer (DDA) algorithm is an incremental scan- conversion method. Such an approach is characterized by performing calculations at each step using results from the preceding step. Suppose, at step i we have calculated(xi, yi) to be a point on the line.Since the next point (xi+1,yi+1) should satisfy Δy/Δx= m where Δy= yi+1 – yi & Δx = xi+1 – xi.
  • 8. We have, yi+1 = yi + mΔx yi+1 = yi + Δy (1) Or xi+1 = xi + Δy/m (2) Algorithm: (x1,y1) (x2,y2) are the end points and dx, dy are the float variables. (i) If abs(x2-x1) > abs(y2-y1) then length = abs(x2-x1) else length = abs(y2-y1) endif
  • 9. (ii) dx = (x2-x1)/length dy = (y2-y1)/length (iii) x = x1 + 0.5 y = y1 + 0.5 (iv) i=0 (v) Plot (trunc(x), trunc(y)) (vi) x = x + dx y = y + dy (vii) i=i+1
  • 10. (viii) If i < length then go to step (v) (ix) Stop Example 2 Scan convert a line having end points (3,2) & (4,7) using DDA. Solution: x2 - x1 = 4-3 = 1 y2 - y1 = 7-2 = 5 As, abs(x2-x1) < abs(y2-y1) then length = y2-y1 = 5 dx = (x2-x1)/ length = 1/5 = .2 dy = (y2-y1)/ length = 5/5 = 1
  • 11. x1 y1 x2 y2 L dx dy i x y Result Plot 3 2 4 7 5 .2 1 0 3.5 2.5 3.5, 2.5 3,2 1 3.7 3.5 3.7,3.5 3,3 2 3.9 4.5 3.9,4.5 3,4 3 4.1 5.5 4.1,5.5 4,5 4 4.3 6.5 4.3,6.5 4,6 5 4.5 7.5 4.5,7.5 4,7
  • 12. Limitations of DDA: (1) The rounding operation & floating point arithmetic are time consuming procedures. (2) The accumulation of round-off error in successive addition of floating point increment can cause the calculated pixel position to drift away from the true line path for long line segment.