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 |
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) |
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.