Examples // Bresenham's Line Algorithm
ex1://Consider the line from (5, 5) to (13, 9), use the Bresenham's algorithm.
sol//
𝚫x = ∣13-5∣=8
𝚫y = l9-5∣=4
x=5 , y=5
= 2*4-8 =0
i |
plot |
x |
y |
e |
|
|
5 |
5 |
0 |
1 |
(5,5) |
6 |
6 |
-16 |
|
|
|
|
-8 |
2 |
(6,6) |
7 |
6 |
0 |
3 |
(7,6) |
8 |
7 |
-16 |
|
|
|
|
-8 |
4 |
(8,7) |
9 |
7 |
0 |
5 |
(9,7) |
10 |
8 |
-16 |
|
|
|
|
-8 |
6 |
(10,8) |
11 |
8 |
0 |
7 |
(11,8) |
12 |
9 |
-16 |
|
|
|
|
-8 |
8 |
(12,9) |
13 |
9 |
0 |
9 |
(13,9) |
14 |
10 |
-16 |
|
|
|
|
-8 |
Ex2//Using Bresenham Algorithm calculate the points between the starting
coordinates (9, 18) and ending coordinates (14, 22).
Solution:
o Given:
Starting coordinates: (X0, Y0) = (9, 18)
Ending coordinates: (Xn, Yn) = (14, 22)
STEP – 01:
o Calculate ΔX, ΔY from the given input.
ΔX = Xn – X0 = 14 – 9 = 5
ΔY =Yn – Y0 = 22 – 18 = 4
STEP – 02:
o Calculate the decision para
meter Pk.
Pk= 2 ΔY- ΔX
= 2×4-5
= 3
STEP – 03:
o As Pk >= 0, so case-02 is satisfied. Thus,
Pk+1 = Pk + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
Xk+1 = Xk + 1 = 9 + 1 = 10
Yk+1 = Yk + 1 = 18 + 1 = 19
Similarly, Step-03 is executed until the end point is reached or number
of iterations equals to 4 times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)
Ex3//Using Bresenham Algorithm calculate the points between the starting
coordinates (20, 10) and ending coordinates (30, 18).
Solution:
o Given:
Starting coordinates: (X0, Y0) = (20, 10)
Ending coordinates: (Xn, Yn) = (30, 18)
STEP – 01:
o Calculate ΔX, ΔY from the given input.
ΔX = Xn – X0 = 30– 20 = 10
ΔY =Yn – Y0 = 18– 10= 8
STEP – 02:
o Calculate the decision parameter Pk.
Pk= 2 ΔY- ΔX
= 2×8-10
= 6
STEP – 03:
o As Pk >= 0, so case-02 is satisfied. Thus,
Pk+1 = Pk + 2ΔY – 2ΔX = 6 + (2 x 8) – (2 x 10) = 2
Xk+1 = Xk + 1 = 20 + 1 = 21
Yk+1 = Yk + 1 = 10 + 1 = 11
Similarly, Step-03 is executed until the end point is reached or number
of iterations equals to 9 times.
(Number of iterations = ΔX – 1 = 10 – 1 = 9)