0% found this document useful (0 votes)
1K views5 pages

DDA Simple and Symmetrical

Uploaded by

beastcover71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views5 pages

DDA Simple and Symmetrical

Uploaded by

beastcover71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Line Generation Algorithms

equation of line is :
y=mx+c where mis the slope of line∧c is the y intercept

y 2− y 1 dx
m ( slope of line )= =
x 2−x 1 dy

Simple DDA (Digital Differential Analyzer Algorithm)


The DDA is a scan-conversion line algorithm based on calculating eitherdx∧dy . We sample the line at
unit interval in one co-ordinates and determine corresponding integer values nearest the line path for the
other coordinate.

Step 1: Take two co-ordinates(x ¿ ¿ 1 , y 1 )¿ and (x ¿ ¿ 2 , y 2 )¿ as input.

Step 2: Calculate the difference between two end points.


dx=x 2−x 1 ¿

dy = y 2− y 1 ¿
Step 3: Based on the calculated difference in step-2, you need to identify the number of steps to put pixel.
If x >dy ¿ , then you need more steps in x coordinate; otherwise in y coordinate.

if (absolute (dx )>absolute (dy )¿ {


steps=absolute (dx );
}
else{
steps=absolute (dy );
}

Step 4: Calculate the increment in x coordinate and y coordinate.

dx
x increment =
float ( steps )
dy
y increment =
float ( steps )
Step 5: Put the pixel by successfully incrementing x and y coordinates accordingly and complete the
drawing of the line.

for(int i=0; i <=Steps; i++)


{
putpixel(Round( x ), Round( y ));
x=x + x increment ;
y= y+ y increment
}
Note:
With positive slope

Slope Condition X increment Y Increment

m<1 |dx|>|dy| x 1< ¿ x 2 x +1 y +m

m>1 |dx|<|dy| y 1 <¿ y 2


x+
1 y +1
m
m=1 |dx|=|dy| x +1 y +1

With negative slope

Slope Conditions X increemnt Y Increment

m<1 |dx|>|dy| x 1> ¿ x 2 x−1 y−m

m>1 |dx|<|dy| y 1 >¿ y 2


x−
1 y−1
m

Example 1: Plot the straight line from (10,15) to (20,21) using simple DDA Algorithm.
Step 1: Calculate dx and dy.

dx=20−10=10∧dy =21-15=6
Step2: Calculate slope of line.
6
m ( slope of line )= =0.6
10
Step 3: Calculate the number of steps need to increment in coordinates or length of line
if(abs(dx)>dy)
Steps=dx
else
Steps=dy
For this line the number of steps will be equals to dx i.e=10
Step 4:
x increment =1
dy
y increment = or =m
float ( steps )

Steps x increment y increment Round off (y)


1 10 15 15
2 11 15.6 16
3 12 16.2 16
4 13 16.8 17
5 14 17.4 17
6 15 18 18
7 16 18.6 19
8 17 19.2 19
9 18 19.8 20
10 19 20.4 20
11 20 21 21

x
0 1 2 3 4 5 6 7 8 9 10 1 12 1 14 1 16 1 18 1 20 21
1 3 5 7 9
1
2
3
4
5
6
7
y 8
9
10
11
12
13
14
15
16
17
18
19
20
21

Example 2: Plot a line from (5, 7) to (10,15).


Dx=10-5=5
Dy=15-7=8
m(slope)=dy/dx=8/5=1.6
steps=8
5 1 8
x increment = =0.625= ∧ y increment = =1∨dy /float (steps)
8 m 8
x + x increment Round off (x) y + y increment
5 5 7
5.625 6 8
6.250 6 9
6.875 7 10
7.500 7 11
8.125 8 12
8.750 9 13
9.375 9 14
10.000 10 15

Example: 3 Plot line segment between(2,2) and (6,6)


Dx=4
Dy=4
M=1
steps=4
dx
x increment = =1
steps
dy
y increment = =1
steps
x + x increment y + y increment
2 2
3 3
4 4
5 5
6 6

CASE x increment = y increment =


m<1 x +1 y +m

m>1 1 y +1
x+
m
m=1 x +1 y +1
Advantages of DDA Algorithm
1) It is fast method for calculating pixel positing than the direct use of Equation 1. It eliminates the
multiplication by making use of raster characteristics, so that appropriate increments are applied
in the x or y direction to step to pixel positions along the line path.
Drawback of DDA Algorithm
1) The accumulation of round off error in successive additions of floating point increment, however
can cause the calculated pixel positions to drift away from the true line path for long line
segment.
2) Rounding operations and floating point performance is time consuming.

References for Simple DDA Algorithm:

[1] “Computer Graphics” By Isrd Group.


[2] “Computer Graphics” by Sanjesh S. Pawale
[3] https://www.tutorialspoint.com/computer_graphics/line_generation_algorithm.htm
[4] https://www.geeksforgeeks.org/dda-line-generation-algorithm-computer-graphics/
Symmetrical DDA

Let us consider the straight line connecting ( x 1 , y 1) and ( x 2 , y 2 ) ,with the equation:

y=f ( x )=m . x +c ……(1)


'
Its first derivation is f ( x )=d y ¿ d x =m and the subsequent derivatives are zero.

The increment in each direction are chosen at small convenient values to satisfy this relationship. The
“small convenient value” should be such that it does not exceed half to one pixel dimension. One way of
choosing it, to suit binary arithmetic, is as follow:

1. Find the smallest integer value of the exponent n in 2n which will be equal to or greater than the
larger of d x ∧d y , the x and y component respectively
n
Then 2 ≥larger of d x ∧d y
Or

log [ larger of d x ∧d y ]
n≥
log2
(Note: log 2 to base 10 is 0.301030 and natural log, then is in 2 to base e is 0.693147 )
2. Set the incremental factor approximately to value
−n
e=2
Then the increment x inc=e .(d x ),

dy
From eq.(1) the increment y inc=m. x inc= . e . d x =e .(d ¿¿ y)¿
dx
This needs two additional of fractional numbers, one each in x∧ y .

Note: number of steps will be the largest of d x ∧d y

References:

[1] “Introduction to Computer Graphics” By Krishnamurthy

You might also like