Sabtu, 19 Oktober 2013

Buatlah sebuah garis mulai dari titik awal (10,10) sampai titik akhir (17,16) dengan menggunakan algoritma DDA dan Bresenham



Jawab:
1. Dengan menggunakan algoritma DDA
Titik Awal = A(10,10)
Titik Akhir = B(17,16)
Dx = (X1-X0) (17-10) = 7
Dy = (Y1-Y0) (16-10) = 6
Abs(Dx) = Abs(7) = 7
Abs(Dy) = Abs(6) = 6
Abs(Dx) > Abs(Dy) maka
Step = Abs(Dx) = 7
Xincrement = Dx / Steps. 7 / 7 = 1
Yincrement = Dy / Steps. 6 / 7 = 0,86
Nilai perhitungan
K         X         Y         Xinc    Yinc
-           -           -           10        10
0          11        10,86  11        11
1          12        11,71  12        12
2          13        12,57  13        13
3          14        13,43  14        14
4          15        14,28  15        15
5          16        15,14  16        16
6          17        16        17        16



2. Menggunakan algoritma Bresenham
dx = abs(xb xa)= abs(17 10 ) = 7

dy = abs(yb ya)= abs(16 10) = 6

p = 2 * dy - dx = 2 * 6 7 = 5

twody = 2 * dy = 2 * 6 = 12

twodydx= 2 * (dy dx ) = 2 * ( 6 7 ) = -2

Periksa xa dan xb

xa = 10 < xb = 17Maka

x = xa = 10

y = ya = 10

Xend = xa = 17

Ulangi selama x < xend

K0: x = x + 1 = 10 + 1 = 11

Periksa nilai p , dimana p = 5

y = y + 1 = 10 + 1 = 11

p = p + twodydx = 5 + (-2) = 3

K1: x = x + 1 = 11 + 1 = 12

Periksa nilai p, dimana p = 3

y = y +1 = 11 + 1 = 12

p = p + twodydx = 3 + (-2) = 1

K2: x = x + 1 = 12 + 1 = 13

Periksa nilai p, dimana p = 1

y = y +1 = 12 + 1 = 13

p = p + twodydx = 1 + (-2) = -1

K3: x = x + 1 = 13 + 1 = 14

Periksa nilai p, dimana p = -1 Nilai y tetap yaitu y=13

p = p + twody = (-1) + 12 = 11

K4: x = x + 1 = 14 + 1 = 15

Periksa nilai p, dimana p = 11

y = y +1 = 13 + 1 = 14

p = p + twodydx = 11 + (-2) = 9

K5: x = x + 1 = 15 + 1 = 16

Periksa nilai p, dimana p = 9

y = y +1 = 14 + 1 = 15

p = p + twodydx = 9 + (-2) = 7

K6: x = x + 1 = 16 + 1 = 17

Periksa nilai p, dimana p = 7 y = y +1 = 15 + 1 = 16

p = p + twodydx = 7 + (-2) = 5

Proses berhenti karena x = x1 dan y = y1

Masukkan nilai kedalam tabel, seperti pada tabel 3.2.Tabel 3.2.

Hasil penelusuran dengan bressenham

K

Pk        (Xk+1 , Yk+1)
-           -           10,10
0          3          11,11
1          1          12,12
2          -1        13,13
3          11        14,13
4          9          15,14
5          7          16,15

6          5          17,16


Tidak ada komentar:

Posting Komentar