Unit II Computer Graphics
Unit II Computer Graphics
DDA (digital differential analyzer) creates good lines but it is too time
consuming due to the round function and long operations on real
values.
Digital Differential Analyzer (DDA) Algorithm:
• If |dx| is greater than |dy|, than |dx| will be step and otherwise |dy| will be
step.
• if |dx|>|dy| then
• step = |dx|
• else
• step = |dy|
• xIncrement = dx/step
• yIncrement = dy/step
• Next a loop is required that will run step times. In the loop drawPixel and
add xIncrement in x1 by and yIncrement in y1.
Xinc := 1
Yinc := 0.6
13
12
Values computed are:
11
(6,9), (7,9.6), 10
9
(8,10.2), (9,10.8),
6 7 8 9 10 11 12 13
(10,11.4), (11,12)
Criticism on Algorithm
• The algorithm uses floating point calculation. When we have to draw
points (i.e. Pixels), it should have integers as coordinates instead it uses
floating point calculation which requires more space as well as they have
more computational cost.
2y xk 2x yk c
• So, a decision parameter pk for the kth step
along a line is given by:
pk x(d lower d upper )
2y xk 2x yk c
• The sign of the decision parameter pk is
the same as that of dlower – dupper
• If pk is negative, then we choose the lower
pixel, otherwise we choose the upper pixel
• Remember coordinate changes occur
along the x axis in unit steps so we can do
everything with integer calculations
• At step k+1 the decision parameter is
given as:
pk 1 2y xk 1 2x yk 1 c
• Subtracting pk from this we get:
pk 1 pk 2y( xk 1 xk ) 2x( yk 1 yk )
• But, xk+1 is the same as xk+1 so:
pk 1 pk 2y 2x( yk 1 yk )
• where yk+1 - yk is either 0 or 1 depending
on the sign of pk
• The first decision parameter p0 is
evaluated at (x0, y0) is given as:
p0 2y x
• BRESENHAM’S LINE DRAWING ALGORITHM
(for |m| < 1.0)
• Input the two line end-points, storing the left end-point
in (x0, y0)
• Plot the point (x0, y0)
• Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx)
and get the first value for the decision parameter as:
17
1
2
16
3
15
4
14
5
13
6
12
7
11
8
10 9
20 21 22 23 24 25 26 27 28 29 30
• Bresenham line drawing algorithm for a
line going from (21,12) to (29,16)
Discussion on algorithm: