أخر الاخبار

Examples Mid Point Line Drawing Algorithm

Examples Mid Point Line Drawing Algorithm 

Ex1//Using Mid Point 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 Dinitial and ΔD as: 

Dinitial = 2ΔY – ΔX = 2×8 – 10 = 6 

 ΔD = 2(ΔY – ΔX) = 2×(8 – 10) = -4

STEP – 03:

 o As Dinitial >= 0, so case-02 is satisfied. Thus, 

Xk+1 = Xk + 1 = 20 + 1 = 21 

Yk+1 = Yk + 1 = 10 + 1 = 11 

Dnew = Dinitial + ΔD = 6 + (-4) = 2 

o Similarly, Step-03 is executed until the end point is reached.





Ex2//Using Mid Point Algorithm calculate the points between the starting coordinates (5, 9) and ending coordinates (12, 16).

Solution:

 o Given: 

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

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

STEP – 01:

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

 ΔX = Xn – X0 = 12– 5= 7 

ΔY =Yn – Y0 = 16– 9= 7

STEP – 02:

 o Calculate Dinitial and ΔD as: 

Dinitial = 2ΔY – ΔX = 2 ×7 – 7 = 7

 ΔD = 2(ΔY – ΔX) = 2 × (7 – 7) = 0


STEP – 03:

 o As Dinitial >= 0, so case-02 is satisfied. Thus,

 Xk+1 = Xk + 1 = 5+ 1 = 6 

Yk+1 = Yk + 1 = 9+ 1 = 10 

Dnew = Dinitial + ΔD = 7+ 0 = 7 

o Similarly, Step-03 is executed until the end point is reached.

STEP – 04:

 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)



تعليقات



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