• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Graphics » Line Drawing » Write Short Note on Digital Differential Analyzer (DDA)
Next →
← Prev

Write Short Note on Digital Differential Analyzer (DDA)

By Dinesh Thakur

DDA algorithm is an incremental scan conversion method. Here we perform calculations at each step using the results from the preceding step. The characteristic of the DDA algorithm is to take unit steps along one coordinate and compute the corresponding values along the other coordinate. The unit steps are always along the coordinate of greatest change, e.g. if dx = 10 and dy = 5, then we would take unit steps along x and compute the steps along y.

 Suppose at step i we have calculated (xi, yi) to be a point on the line. Since the next point (x i+1,y i+1) should satisfy ?y/? x =m where ?y= y i+1–yi and ? x= x i+1–xi , we have y i+1= yi + m? x or x i+1=xi+ ? y/m

 These formulas are used in DDA algorithm as follows. When |m| ? 1, we start with x = x1’? (assuming that x1’ <x2’) and y = y1’, and set ? x =1( i.e., unit increment in the x direction). The y coordinate of each successive point on the line is calculated using y i+1= yi + m.

When |m| >1, we start with x= x1’ and y= y1’ (assuming that y1’ < y2’), set ? y =1 ( i.e., unit increment in the y direction). The x coordinate of each successive point on the line is calculated using x i+1=xi+ 1/m. This process continues until x reaches x2’(for m| ? 1 case )or y reaches y2’ (for m| > 1 case ) and all points are scan converted to pixel points.

The explanation is as follows: In DDA algorithm we have to find the new point xi+1 and yi+1 from the existing points xi and yi. As a first step here we identify the major axis and the minor axis of the line to be drawn. Once the major axis is found we sample the major axis at unit intervals and find the value in the other axis by using the slope equation of the line.

For example if the end points of the line is given as (x1,y1)= (2,2) and (x2, y2)= (9,5). Here we will calculate y2-y1 and x2-x1 to find which one is greater. Here y2-y1 =3 and x2-x1 =7; therefore here the major axis is the x axis. So here we need to sample the x axis at unit intervals i.e.? x = 1 and we will find out the y values for each ? x in the x axis using the slope equation.

 In DDA we need to consider two cases; one is slope of the line less than or equal to one (|m| ? 1)and slope of the line greater than one (m| > 1). When |m| ? 1 means y2-y1 = x2-x1 or y2-y1 <x2-x1.In both these cases we assume x to be the major axis. Therefore we sample x axis at unit intervals and find the y values corresponding to each x value.

We have the slope equation as

? y = m ? x

           y2-y1 = m (x2-x1)

In general terms we can say that y i+1 – yi = m(x i+1 – xi ). But here ? x = 1; therefore the equation reduces to y i+1= yi + m = yi + dy/dx.

When m| > 1 means y2-y1> x2-x1 and therefore we assume y to be the major axis. Here

we sample y axis at unit intervals and find the x values corresponding to each y value. We have the slope equation as

? y = m ? x

y2-y1 = m (x2-x1)

In general terms we can say that y i+1 – yi = m(x i+1 – xi ). But here ? y = 1; therefore the equation reduces to 1 = m(x i+1 – xi). Therefore

x i+1=xi+ 1/m

x i+1=xi+ dx/dy

DDA Algorithm is given below:

procedure DDA( x1, y1, x2, y2: integer);

var

            dx, dy, steps: integer;

            x_inc, y_inc, x, y: real;

begin

            dx := x2 – x1; dy := y2 – y1;

            if abs(dx) > abs(dy) then

            steps := abs(dx); {steps is larger of dx, dy}

else

            steps := abs(dy);

            x_inc := dx/steps; y_inc := dy/steps;

            {either x_inc or y_inc = 1.0, the other is the slope}

            x:=x1; y:=y1;

            set_pixel(round(x), round(y));

            for i := 1 to steps do

begin

             x := x + x_inc;

             y := y + y_inc;

              set_pixel(round(x), round(y));

end;

end; {DDA}

The DDA algorithm is faster than the direct use of the line equation since it calculates points on the line without any floating point multiplication.

Advantages of DDA Algorithm

1. It is the simplest algorithm and it does not require special skills for implementation.
2. It is a faster method for calculating pixel positions than the direct use of equation y = mx + b. It eliminates the multiplication in the equation by making use of raster characteristics, so that appropriate increments are applied in the x or v direction to find the pixel positions along the line path.

Disadvantages of DDAAlgorithm

1. Floating point arithmetic in DDA algorithm is still time-consuming.
2. The algorithm is orientation dependent. Hence end point accuracy is poor.

Let us see few examples to illustrate this algorithm.

 

Consider the line from (0,0) to (4,6). Use the simple DDA algorithm to rasterize this line.

 

Sol. Evaluating steps 1 to 5 in the DDA algorithm we have

 

Xl = 0                          Y1 = 0

X2 = 4                          Y2 = 6

Length = |Y2-Y1l = 6

                             ∆X = |X2– Xl | / Length

                                 =       4

                                           6

                             ∆Y = |Y2– Yl | / Length

                                   = 6/6=1

Initial value for

                               X = 0 + 0.5 * Sign (4) = 0.5

                                                                 6

                               Y = 0 + 0.5 * Sign (1) = 0.5

 

Tabulating the results of each iteration in the step 6 we get,

                         DDA Algorithm

                         DDA-Algo

                                             Result for a simple DDA

 

The results are plotted as shown in the Fig. It shows that the rasterized line lies to both sides of the actual line, i.e. the algorithm is orientation dependent.

 

Example 2 Consider the line from (0, 0) to (-6, -6). Use the simple DDA algorithm line.

 

Sol. Evaluating steps 1 to 5 in the DDA algorithm we have

 

Xl = 0                          Y1 = 0

X2 = – 6                       Y2 = – 6                  

Length = l X2-X1l |Y2-Y1l = 6

                           ∆X = ∆Y = -1

Initial values for

                                       X = 0 + 0.5 * Sign (-1) =-0.5

                                       Y = 0 + 0.5 * Sign (-1) =-0.5

Tabulating the results of each iteration in the step 6 we get,

                             DDA Algorithm Line

                             DDA Algorithm Lines

                                                Result for simple DDA

The results are plotted as shown in the Fig. It shows that the rasterized line lies on the actual line and it is 45° line.

 

You’ll also like:

  1. Write Short Note on C-Scan Scheduling
  2. Write Short Note on Shortest Seek Time First or SSTF
  3. Write a Short Note on Project Control Termination Analysis
  4. Short Note on Single Linked List
  5. Short Note on Singly Circular Linked List
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Computer Graphics Tutorials

Computer Graphics

  • CG - Home
  • CG - Introduction
  • CG - Applications
  • CG - Applications
  • CG - Raster Vs Random Scan Display
  • CG - Frame Buffer
  • CG - DVST
  • CG - CRT Display
  • CG - DDA
  • CG - Transformation
  • CG - Cathode Ray Tube
  • CG - Bresenham’s Line Algorithm
  • CG - Pixel
  • CG - Data Compression
  • CG - Clipping
  • CG - Shadow Mask CRT
  • CG - Line Drawing Algorithm
  • CG - Text Clipping
  • CG - Refresh Rates
  • CG - CRT/Monitor
  • CG - Interactive Graphics Display
  • CG - Raster Vs Random Scan System
  • CG - Liquid Crystal Display
  • CG - Scan Converting a Line
  • CG - Monitors Types
  • CG - Display Types
  • CG - Sutherland-Hodgeman Clipping
  • CG - Bitmap
  • CG - Antialiasing
  • CG - Refresh Rates
  • CG - Shadow Mask Vs Beam Penetration
  • CG - Scan Converting a Point
  • CG - Image Resolution
  • CG - Double Buffering
  • CG - Raster Vs Random Scan
  • CG - Aspect Ratio
  • CG - Ambient Light
  • CG - Image Processing
  • CG - Interactive Graphics Displayed
  • CG - Shadow Mask CRT
  • CG - Dithering
  • CG - GUI
  • CG - CLUT
  • CG - Graphics
  • CG - Resolutions Types
  • CG - Transformations Types
  • CG - Half-toning Effect
  • CG - VGA
  • CG - Aliasing
  • CG - CGA

Other Links

  • Computer Graphics - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW