Advantages and Disadv of DDA Algorithm
Advantages and Disadv of DDA Algorithm
Advantages and Disadv of DDA Algorithm
It is a simple algorithm.
It is easy to implement.
It avoids using the multiplication operation which is costly in terms of time complexity.
There is an extra overhead of using round off( ) function. Using round off( ) function increases
time complexity of the algorithm. Resulted lines are not smooth because of round off( )
function. The points generated by this algorithm are not accurate.
Bresenham Algorithm
Comparision
DDA uses floating points where as Bresenham algorithm use fixed points.
DDA round off the coordinates to nearest integer but Bresenham algorithm does
not.
Bresenham algorithm is much accurate and efficient than DDA.
Bresenham algorithm can draw circles and curves with much more accuracy than
DDA.
DDA uses multiplication and division of equation but Bresenham algorithm uses
subtraction and addition only
Arithmetic DDA algorithm uses floating Bresenhams algorithm uses fixed points
points i.e. Real Arithmetic i.e. integer Arithmetic.
Speed DDA algorithm is rather slowly Bresenhams algorithm is faster than DDA
than Bresenhams algorithm in algorithm in line drawing because it
line drawing because it uses real performs only addition and subtraction in
arithmetic (floating point its calculations and uses only integer
operations). arithmetic so it runs significantly faster.
- Digital Differential Bresenhams Line Drawing Algorithm
Analyzer,Line Drawing
Algorithm
Accuracy & DDA algorithm is not as accurate Bresenhm algorithm is more accurate and
Efficiency and efficient as Bresenhm efficient as than DDA algorithm.
algorithm.
Drawing DDA algorithm can draw circles Bresenhm algorithm can draw circles and
and curves but that are not as curves with much more accuracy than DDA
accurate as Bresenhm algorithm. algorithm.
Round off DDA algorithm round off the Bresenhm algorithm does not round off but
coordinates to integer that is takes the incremental value in its
nearest to the line. operation.
The main distinction between DDA algorithm and Bresenham line algorithm is that, the
DDA algorithmic rule uses floating purpose values whereas in Bresenham, spherical off
functions is used.
DDA algorithmic rule involves multiplication as well as division whereas in bresenham
algorithmic rule, addition and subtraction are the most performed operations.
Let’s see that the difference between DDA algorithm and Bresenham line drawing
algorithm:
DDA algorithm is less efficient than While it is more efficient than DDA
2. Bresenham line algorithm. algorithm.
Computer Graphics | Direct Use of Line Equation: In this tutorial, we are going to learn
about the Direct Use of Line Equation in Computer Graphics, 2D line and properties of good
line drawing algorithms.
Submitted by Monika Sharma, on April 15, 2020
The standard line equation, as we all know is used for drawing a line. It is given by: y = mx
+ c.
We are discussing here in 2D so we all know that there are 2 axes: x and y. Both of the axes
are required to give the equation of any 2D shape. The line is a straight path joining 2
points in the x-y plane. If both the points are given then we can find the equation of a line.
The slope of a line
The slope of a line defines the direction of a line. Its value is equal to the ratio of the
difference of y coordinates and the difference. Assume that the two points
are X( x1,y1 ) and Y( x2,y2 ). Its slope, 'm' will be: m = (y2 - y1) / (x2 - x1).
Example:
We have given two points X and Y. The coordinates of X are (0, 0) and the coordinates
of Y are (5, 15). The slope of the line will be,
m = (15 - 0) / (5-0)
m = 3
We have the slope of the line. Now let us put the slope in the line equation.
y = 3x + c
c = 0
y = 3x
Let x = 1 ⟹ y = 3 x 1 ⟹ y = 3
Let x = 2 ⟹ y = 3 x 2 ⟹ y = 6
Let x = 3 ⟹ y = 3 x 3 ⟹ y = 9
Let x = 4 ⟹ y = 3 x 4 ⟹ y = 12
Let x = 5 ⟹ y = 3 x 5 ⟹ y = 15
We got the intermediate points which are, (1, 3), (2, 6), (3, 9), (4, 12) and finally (5, 15)
ADVERTISEMENT
Step 1: Read the input of the 2 end points of the line as (x1, y1) & (x2, y2)
such that x1 != x2 and y1 != y2
Step 3:
if(dx>=dy)
step=dx
else
step=dy
Step 6:
x = x + xin
y = y + yin
putpixel(x, y)
1 #include <graphics.h>
2 #include <stdio.h>
3 #include <math.h>
4 #include <dos.h>
5
6 void main( )
7 {
8 float x,y,x1,y1,x2,y2,dx,dy,step;
9 int i,gd=DETECT,gm;
10
11 initgraph(&gd,&gm,"c:\\turboc3\\bgi");
12
14 scanf("%f%f",&x1,&y1);
16 scanf("%f%f",&x2,&y2);
17
18 dx=abs(x2-x1);
19 dy=abs(y2-y1);
20
21 if(dx>=dy)
22 step=dx;
23 else
24 step=dy;
25
26 dx=dx/step;
27 dy=dy/step;
28
29 x=x1;
30 y=y1;
31
32 i=1;
33 while(i<=step)
34 {
35 putpixel(x,y,5);
36 x=x+dx;
37 y=y+dy;
38 i=i+1;
39 delay(100);
40 }
41
42 closegraph();
43 }
Outptut
1 #include <graphics.h>
2 #include <iostream.h>
3 #include <math.h>
4 #include <dos.h>
5
6 void main( )
7 {
8 float x,y,x1,y1,x2,y2,dx,dy,step;
9 int i,gd=DETECT,gm;
10
11 initgraph(&gd,&gm,"c:\\turboc3\\bgi");
12
14 cin>>x1>>y1;
16 cin>>x2>>y2;
17
18 dx=abs(x2-x1);
19 dy=abs(y2-y1);
20
21 if(dx>=dy)
22 step=dx;
23 else
24 step=dy;
25
26 dx=dx/step;
27 dy=dy/step;
28
29 x=x1;
30 y=y1;
31
32 i=1;
33 while(i<=step)
34 {
35 putpixel(x,y,5);
36 x=x+dx;
37 y=y+dy;
38 i=i+1;
39 delay(100);
40 }
41
42 closegraph();
43 }