0% found this document useful (0 votes)
31 views19 pages

Multimedia Systems: Muhammad Shahzad

Uploaded by

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

Multimedia Systems: Muhammad Shahzad

Uploaded by

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

MULTIMEDIA SYSTEMS

Lecture:5.1

Muhammad Shahzad
AGENDA
 Line drawing algorithm
 Digital differential analyzer (DDA)

Muhammad Shahzad
Line Drawing Algorithms
1. A line in Computer graphics is a portion of straight line that extends indefinitely in
opposite direction.
2. It is defined by its two end points.
3. Its density should be independent of line length.
the slope intercept equation for a line:
y = mx + b (1)
where, m = Slope of the line
b = the y intercept of a line
The two endpoints of a line segment are specified at positions (x1,y1) and (x2,y2).

y
P2(x2,y2)

b P1(x1,y1)

0
x
We can determine the value for slope m & b intercept as
m = y2-y1/x2-x1
i.e. m= Δy/ Δx (2)
Example 1 The endpoints of line are(0,0) & (6,18). Compute each value
of y as x steps from 0 to 6 and plot the result.
Solution : Equation of line is y= mx +b
m = y2-y1/x2-x1= 18-0/6-0 = 3
Next the y intercept b is found by plugging y1& x1 into the equation y =
3x + b,
0 = 3(0) + b. Therefore, b=0, so the equation for the line is y= 3x.

Examples:
(3,2) (4,7)
(5,6) (8,12)
(0,0) (6,18)
The challenge is to find a way to calculate the next x,y position by
previous one as quickly as possible.
DDA Algorithm
The Digital differential analyzer (DDA) algorithm is an incremental scan-conversion
method.

Such an approach is characterized by performing calculations at each step using results


from the preceding step.
INTRODUCTION
  As, this is an algorithm for drawing line on computer screen.
 Mathematical procedure is involved behind this.
 Equation for the straight line is:
 Where m is the slope of the line, Slope could be –ve or +ve.
 If [m>0 then +ve ] , if [m<0 then -ve]
 If +ve

Muhammad Shahzad
CASES
 Three types of cases

Case 1: Case 2: Case 3:

Muhammad Shahzad
Algorithm:
 

(x1,y1) (x2,y2) are the end points and x, y are the


float variables.
Where  Δ x= abs(x2-x1) and y= abs(y2-y1)

(i) If x >=y then


length = x
else
length = y
endif
  Coordinates (x1 , y1)( , ) , (x2 , y2)( , )
 Step 1:

 Calculate the number of iteration:

=
 Find the length:

Length = k =
 Find dx & dy
dx = =
dy= =

Muhammad Shahzad
  Solve using equations :

No. X Y Xn Yn Round of value

Muhammad Shahzad
(ii) dx = (x2-x1)/length
dy = (y2-y1)/length
(iii) x = x1 + 0.5
y = y1 + 0.5
(iv) i=0
(v) Plot ((x), (y))
(vi) x = x + dx
y = y + dy
(vii) i=i+1
(viii) If i < length then go to step (v)
(ix) Stop
Example 2 Scan convert a line having end points (3,2) & (4,7) using
DDA.
Solution: dx= x2 - x1 = 4-3 = 1
dy= y2 - y1 = 7-2 = 5
As, dx < dy then
length = y2-y1 = 5
dx = (x2-x1)/ length = 1/5 =0.2
dy = (y2-y1)/ length = 5/5 = 1
ADVANTAGES
 Faster as compared to direct line equation method
 No multiplication theorem is used
 As, it is an incremental approach no duplication
 Convineance

Muhammad Shahzad
LIMITATIONS OF DDA:
 The rounding operation & floating point arithmetic are time consuming procedures.
 Round-off error can cause the calculated pixel position to drift away from the true line path for
long line segment.

Muhammad Shahzad
Limitations of DDA:
(1) The rounding operation & floating point arithmetic are time
consuming procedures.
(2) Round-off error can cause the calculated pixel position to drift away
from the true line path for long line segment.
Muhammad Shahzad

You might also like