尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
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

Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
nehrurevathy
 
Video display devices
Video display devicesVideo display devices
Video display devices
shalinikarunakaran1
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
Timbal Mayank
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
PrathimaBaliga
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
Mohd Arif
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
SwatiHans10
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
Mani Kanth
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
Mohd Arif
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
Ankit Garg
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
Mani Kanth
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
SHIVANI SONI
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
Omprakash Chauhan
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4
PrathimaBaliga
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithm
Mani Kanth
 
Video display devices
Video display devicesVideo display devices
Video display devices
Mohd Arif
 
Bresenham's line algorithm
Bresenham's line algorithmBresenham's line algorithm
Bresenham's line algorithm
Pooja Dixit
 
Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2
Iftikhar Ahmad
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
Arvind Kumar
 
Input of graphical data
Input of graphical dataInput of graphical data
Input of graphical data
Rajapriya82
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
Maruf Abdullah (Rion)
 

What's hot (20)

Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
 
Video display devices
Video display devicesVideo display devices
Video display devices
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithm
 
Video display devices
Video display devicesVideo display devices
Video display devices
 
Bresenham's line algorithm
Bresenham's line algorithmBresenham's line algorithm
Bresenham's line algorithm
 
Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 
Input of graphical data
Input of graphical dataInput of graphical data
Input of graphical data
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
 

Viewers also liked

Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
Praveen Kumar
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
Laxman Puri
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
Rajani Thite
 
dda algorithm
dda  algorithmdda  algorithm
dda algorithm
774474
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
Mahesh Kodituwakku
 
Bresenham's line algo.
Bresenham's line algo.Bresenham's line algo.
Bresenham's line algo.
Mohd Arif
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
Griffinder VinHai
 
Anti aliasing Computer Graphics
Anti aliasing Computer GraphicsAnti aliasing Computer Graphics
Anti aliasing Computer Graphics
University of Potsdam
 
Lecture15 anti aliasing
Lecture15 anti aliasingLecture15 anti aliasing
Lecture15 anti aliasing
Siddharth Maloo
 
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 graphics
lenance
 
Analytical chemistry_Instrumentation_Introduction
Analytical chemistry_Instrumentation_IntroductionAnalytical chemistry_Instrumentation_Introduction
Analytical chemistry_Instrumentation_Introduction
Bivek Timalsina
 
Perspective projection
Perspective projectionPerspective projection
Perspective projection
Prakash Bharadwaj
 
hermite cubic spline curve
hermite cubic spline curvehermite cubic spline curve
hermite cubic spline curve
Prakash Bharadwaj
 
[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
JinTaek Seo
 
Presentation non parametric
Presentation non parametricPresentation non parametric
Presentation non parametric
Irfan Hussain
 
Parametric equations
Parametric equationsParametric equations
Parametric equations
Tarun Gehlot
 
Presentation on bezier curve
Presentation on bezier curvePresentation on bezier curve
Presentation on bezier curve
Satyendra 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.pptx
R S Anu Prabha
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
SanthiNivas
 
Study on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan GraphicsStudy on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan Graphics
Chandrakant Divate
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
IndhuMcamphil
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
Alamelu
 
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
Amol Gaikwad
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
NaveenaKarthik3
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenham
simpleok
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
AhmadAbba6
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
Kumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
Muhammad 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.pptx
ssuser255bf1
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
Mattupallipardhu
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniya
TutorialsDuniya.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 techniques
Ankit Garg
 
Nis differentiation1
Nis differentiation1Nis differentiation1
Nis differentiation1
Bauyrzhan Yesbolov
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
Praveen Kumar
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
Prabin Gautam
 

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
 
Study on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan GraphicsStudy on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan Graphics
 
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
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
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
 

More from Mohd Arif

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcp
Mohd Arif
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarp
Mohd Arif
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
Mohd Arif
 
Project identification
Project identificationProject identification
Project identification
Mohd Arif
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniques
Mohd Arif
 
Presentation
PresentationPresentation
Presentation
Mohd Arif
 
Pointers in c
Pointers in cPointers in c
Pointers in c
Mohd Arif
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peer
Mohd Arif
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systems
Mohd Arif
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
Mohd Arif
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgeting
Mohd Arif
 
Network management
Network managementNetwork management
Network management
Mohd Arif
 
Networing basics
Networing basicsNetworing basics
Networing basics
Mohd Arif
 
Loaders
LoadersLoaders
Loaders
Mohd Arif
 
Lists
ListsLists
Lists
Mohd 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 platform
Mohd Arif
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and ssl
Mohd Arif
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psec
Mohd Arif
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardware
Mohd Arif
 
Heap sort
Heap sortHeap sort
Heap sort
Mohd 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.
  翻译: