DDA line Drawing Algorithm in Computer Graphics

DDA (Digital Differential Analyzer) Line Drawing Algorithm

The Digital Differential Analyzer helps us to interpolate the variables on an interval from one point to another point. We can use the digital Differential Analyzer algorithm to perform rasterization on polygons, lines, and triangles.

Digital Differential Analyzer algorithm is also known as an incremental method of scan conversion. In this algorithm, we can perform the calculation in a step by step manner. We use the previous step result in the next step.

As we know the general equation of the straight line is:

y = mx + c

Here, m is the slope of (x1, y1) and (x2, y2).

m = (y2 – y1)/ (x2 – x1)

Now, we consider one point (xk, yk) and (xk+1, yk+1) as the next point.

Then the slope m = (yk+1 - yk)/ (xk+1 - xk)

Now, we have to find the slope between the starting point and ending point. There can be following three cases to discuss:

Case 1: If m < 1

             Then x coordinate tends to the Unit interval.

                         xk+1 = xk + 1

                         yk+1 = yk + m

Case 2: If m > 1

             Then y coordinate tends to the Unit interval.

                         yk+1 = yk + 1

                          xk+1 = xk + 1/m

Case 3: If m = 1

             Then x and y coordinate tend to the Unit interval.

                         xk+1 = xk + 1

                         yk+1 = yk + 1

We can calculate all intermediate points with the help of above three discussed cases.

Algorithm of Digital Differential Analyzer (DDA) Line Drawing

Step 1: Start.

Step 2: We consider Starting point as (x1, y1), and ending point (x2, y2).

Step 3: Now, we have to calculate ?x and ?y.

              ?x = x2-x1

                    ?y = y2-y1

              m = ?y/?x               

Step 4: Now, we calculate three cases.

          If m < 1

       Then x change in Unit Interval

                y moves with deviation

              (xk+1, yk+1) = (xk+1, yk+1)

         If m > 1

      Then x moves with deviation

                y change in Unit Interval

              (xk+1, yk+1) = (xk+1/m, yk+1/m)

         If m = 1

       Then x moves in Unit Interval

                y moves in Unit Interval

              (xk+1, yk+1) = (xk+1, yk+1)

Step 5: We will repeat step 4 until we find the ending point of the line.

Step 6: Stop.

Example: A line has a starting point (1,7) and ending point (11,17). Apply the Digital Differential Analyzer algorithm to plot a line.

Solution: We have two coordinates,

Starting Point = (x1, y1) = (1,7)

Ending Point = (x2, y2) = (11,17)

Step 1: First, we calculate ?x, ?y and m.

           ?x = x2 – x1 = 11-1 = 10

             ?y = y2 – y1 = 17-7 = 10

              m = ?y/?x = 10/10 = 1

Step 2: Now, we calculate the number of steps.

              ?x = ?y = 10

Then, the number of steps = 10

Step 3: Weget m = 1, Third case is satisfied.

              Now move to next step.

          xk          yk          xk+1           yk+1     (xk+1, yk+1)
1 7 2 8 (2, 8)
    3 9 (3, 9)
    4 10 (4, 10)
    5 11 (5, 11)
    6 12 (6, 12)
    7 13 (7, 13)
    8 14 (8, 14)
    9 15 (9, 15)
    10 16 (10, 16)
    11 17 (11, 17)

Step 4: We will repeat step 3 until we get the endpoints of the line.

Step 5: Stop.

DDA line Drawing Algorithm in Computer Graphics

The coordinates of drawn line are-

P1 = (2, 8)

P2 = (3, 9)

P3 = (4, 10)

P4 = (5, 11)

P5 = (6, 12)

P6 = (7, 13)                                                   

P7 = (8, 14)

P8 = (9, 15)

P9 = (10, 16)

P10 = (11, 17)

Advantages of Digital Differential Analyzer

  • It is a simple algorithm to implement.
  • It is a faster algorithm than the direct line equation.
  • We cannot use the multiplication method in Digital Differential Analyzer.
  • Digital Differential Analyzer algorithm tells us about the overflow of the point when the point changes its location.

Disadvantages of Digital Differential Analyzer

  • The floating-point arithmetic implementation of the Digital Differential Analyzer is time-consuming. 
  • The method of round-off is also time-consuming.
  • Sometimes the point position is not accurate.

Related Topics

Scan Conversion in Computer Graphics

“When we represent regular objects in the form of discrete pixels, it is called Scan Conversion.” Every graphics system must transform the primitives into a collection of pixels. The scan conversion is also...

2 minutes read.

Polygon Clipping in Computer Graphics

“A Polygon can be described as the enclosed collection or group of the lines.” In a polygon, all lines are connected. Lines can be a combination of edges and vertices,...

4 minutes read.

Scan Conversion of a Circle Computer Graphics

A circle is an eight-way symmetric shape. All quadrants of a circle are the same. There are two octants in each quadrant of a circle. If we know the value of any...

3 minutes read.

Transformation

Introduction The term Transformation is generally referred to as converting a graphic into another graphic by applying some rules or algorithms. Sometimes an image or picture can be a combination of lines, rectangle,...

2 minutes read.

Anti-aliasing in Computer Graphics

Anti-aliasing in Computer Graphics “Anti-aliasing is a method for eliminating the aliasing effect used in computer graphics. In a 2-dimensional object, the ambient occlusion impact is the existence of sharp edges...

7 minutes read.

3D Shearing

We can denote shearing with ‘SHx,’ ‘SHy,’ and ‘SHz.’ These ‘SHx,’ ‘SHy,’ ‘SHz’ are called “Shearing factor.” The basic difference between 2D and 3D Shearing is that the 3D plane also...

1 minute read.

2D Rotation

The Rotation of any object depends upon the two points. Rotation Point: It is also called the Pivot point. Rotation Angle: It is denoted by Theta (). We can rotate an object in...

1 minute read.

Applications of Computer Graphics

Applications of Computer Graphics Some applications of computer graphics are mentioned below- Graphical User Interface (GUI): It is a way of interacting with a computer using the icon, ...

2 minutes read.

Clipping in Computer Graphics

“The Clipping is a type of transformation used in computer graphics to remove lines, objects, and segments of lines that are outside the computer screen or viewing pane.” The clipping is a...

2 minutes read.

Aspect Ratio in Computer Graphics

Aspect Ratio in Computer Graphics You might well understand the concept of Aspect ratio as of now if you know regarding aerial photography or see the configuration portion of any computer...

5 minutes read.

Output Devices in Computer Graphics

Computer Graphics Output Devices An output device is a component of hardware or the main physical part of a computer that can be touched and seen. An output device is an electromechanical device. “The...

5 minutes read.

2D Scaling

In scaling, we can expend or compress the size of any object. We can apply scaling on the object by multiplying the original coordinates with scaling factors. The term scaling factor...

2 minutes read.

Color Models in Computer Graphics

"Color model is a 3D color coordinate system to produce all range of color through the primary color set." There are millions of colors used in computer graphics. The light...

3 minutes read.

Display Devices in Computer Graphics

The display device is an output device used to represent the information in the form of images (visual form). Display systems are mostly called a video monitor or Video display unit (VDU). Display devices are designed to model, display, view, or display information. The...

6 minutes read.

Zooming

In computer graphics, the term “Zoom is referred as a function, focuses on a particular portion or part of an image and also enlarging the image’s size for greater details.” In windows...

2 minutes read.

2D Transformation in Computer Graphics

Some visuals are transformed into some other graphics by implementing several of the principles known as transformation. There are multiple kinds of transformation, including translation, scaling, rotation, shearing, etc. Whenever...

2 minutes read.

Composite Transformation in Computer Graphics

Composite transformation in Computer Graphics It is possible to integrate a range of transformations or series of transformations into some kind of a single one which is known as composition. The...

6 minutes read.

Projection in Computer Graphics

Projection Introduction: The technique projection was invented by the Swiss mathematician, engineer, and astronomer "Leonhard Euler Around" in 1756. The "Episcope" was the first projection system. “Projection is a technique or process which...

4 minutes read.

Mid-Point Line Drawing Algorithm in Computer Graphics

The Mid-point Subdivision algorithm is the extension of the Cyrus-Beck algorithm. The Mid-Point line plotting algorithm was introduced by “Pitway and Van Aken.” It is an incremental line drawing algorithm....

8 minutes read.

Homogenous Coordinates in Computer Graphics

Homogenous Coordinates in Computer Graphics The orbit of a point, a line graph or the whole picture on the computer, a point besides the origin, is accomplished by first shifting the...

7 minutes read.