أخر الاخبار

Example DDA algorithm

   Example / Algorithm DDA

Ex1:/ consider the line from (0,0) to (6,6). Use the simple DDA algorithm?

sol//

x1=0  , y1=0   ,  x2=6    ,   y2=6

Length = 𝑦2− 𝑦1 = 𝑥2 − 𝑥1 =6

Δ𝑥 = (𝑥2 − 𝑥1)/𝑙𝑒𝑛𝑔𝑡

= 6/6 = 1    and

Δ𝑦 = (𝑦2 − 𝑦1)/𝑙𝑒𝑛𝑔𝑡

=6/6 = 1

Initial value for

𝑥 = 0 + 0.5 (1) =0.5

𝑌 = 0 + 0.5 (1) = 0.5

i

Plot

x

y

 

 

0.5

0.5

1

(0,0)

 

 

 

 

1.5

1.5

2

(1,1)

 

 

 

 

2.5

2.5

3

(2,2)

 

 

 

 

3.5

3.5

4

(3,3)

 

 

 

 

4.5

4.5

5

(4,4)

 

 

 

 

5.5

5.5

6

(5,5)

 

 

 

 

6.5

6.5







/Ex2 /consider the line from (23,33) to (29,40) Use the simple DDA algorithm



//sol

x1=23  , y1=33  ,  x2=29   ,   y2=40

Δ𝑥 = 𝑥2 − 𝑥1 =6

Length = 𝑦2− 𝑦1=7

Δ𝑥 = (𝑥2 − 𝑥1)/𝑙𝑒𝑛𝑔𝑡

= 6/7 = 0.85   and

Δ𝑦 = (𝑦2 − 𝑦1)/𝑙𝑒𝑛𝑔𝑡

=7/7 = 1

Initial value for

𝑥 = 23 + 0.5 (0.8) =23

𝑌 = 33 + 0.5 (1) = 33.5

 

i

x

y

Plot(x,y)

1.     

23.5

33.5

(23,33)

2.     

24.3

34.5

(24,34)

3.     

25.1

35.5

(25,35)

4.     

25.9

36.5

(25, 36)

5.     

26.7

37.5

(26, 37)

6.     

27.5

38.5

(27, 38)

7.     

28.3

39.5

(28, 39)




/Ex3/consider the line from (0,0) to (4,6). Use the simple DDA algorithm

//sol

x1=0 , y1=0 , x2=4, y2=6

Length = y2− y1 =6

Δ𝑥 = (x2 − x1)/ length = 4/6 and

Δy = (y2 − y1)/ length =6/6 = 1

 

Initial value for

𝑥 = 0+ 0.5 (4.6)=0.5

𝑌 = 0 + 0.5 (1) = 0.5

 




Ex4:/ consider the line from (5,6) to (8,12). Use the simple DDA algorithm?

sol//

Solution:

 o Given:

 Starting coordinates: (X0, Y0) = (5, 6) 

Ending coordinates: (Xn, Yn) = (8, 12) 

STEP – 01:

 o Calculate ΔX, ΔY and m from the given input.

 ΔX = Xn – X0 = 8 – 5 = 3 

ΔY =Yn – Y0 = 12 – 6 = 6 

m = ΔY / ΔX = 6 / 3 = 2 

STEP – 02:

 o Calculate the number of steps.

 As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6

STEP – 03: 

o As m > 1, so case-03 is satisfied.

 Now, Step-03 is executed until Step-04 is satisfied.






Ex5//    Using DDA algorithm, Calculate the points between the starting point (5, 6) and ending point (13, 10).

Solution:
 o Given:
 Starting coordinates: (X0, Y0) = (5, 6) 
Ending coordinates: (Xn, Yn) = (13, 10)

STEP – 01:
 o Calculate ΔX, ΔY and m from the given input.
 ΔX = Xn – X0 = 13 – 5 = 8 
ΔY =Yn – Y0 = 10 – 6 = 4 
m = ΔY / ΔX = 4 / 8 = 0.50

STEP – 02:
 o Calculate the number of steps. 
As |ΔX| > |ΔY| = 8 > 4, so number of steps = ΔX = 8

STEP – 03:
 o As m < 1, so case-01 is satisfied. 
Now, Step-03 is executed until Step-04 is satisfied.





Ex6//Using DDA algorithm, calculate the points between the starting point (1, 7) and ending point (11, 17).
Solution: 
o Given: 
Starting coordinates: (X0, Y0) = (1, 7) 
Ending coordinates: (Xn, Yn) = (11, 17)
STEP – 01:
 o Calculate ΔX, ΔY and m from the given input. 
ΔX = Xn – X0 = 11 – 1 = 10 
ΔY =Yn – Y0 = 17 – 7 = 10 
m = ΔY / ΔX = 10 / 10 = 1

STEP – 02:
 o Calculate the number of steps.
 As |ΔX| = |ΔY| = 10 = 10, so number of steps = ΔX = ΔY = 10 

STEP – 03:
 o As m = 1, so case-01 is satisfied. 
Now, Step-03 is executed until Step-04 is satisfied.


تعليقات



حجم الخط
+
16
-
تباعد السطور
+
2
-