0% found this document useful (0 votes)
902 views20 pages

Eight Way Symmetry: Midpoint Line Drawing Algorithm

The document describes an algorithm for drawing lines on a 2D grid using the midpoint line drawing method. It discusses converting line coordinates between the 8 symmetry zones to allow using a single midpoint algorithm in zone 0. Coordinates are converted to zone 0 before drawing, then results are converted back to the original zone.

Uploaded by

Alif hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
902 views20 pages

Eight Way Symmetry: Midpoint Line Drawing Algorithm

The document describes an algorithm for drawing lines on a 2D grid using the midpoint line drawing method. It discusses converting line coordinates between the 8 symmetry zones to allow using a single midpoint algorithm in zone 0. Coordinates are converted to zone 0 before drawing, then results are converted back to the original zone.

Uploaded by

Alif hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Eight Way Symmetry

Midpoint Line Drawing Algorithm


Midpoint Line Drawing Algorithm
Midpoint (x1, y1, x2, y2){
dx= x2 - x1 ; dy = y2 - y1 ;
D = 2*dy – dx; ∆NE = 2*(dy-dx) ; ∆E = 2*dy ;
x= x1 ; y = y1 ;
while( x ≤ x2){
Draw(x, y);
x++ ;
if (D>0){
y++;
D = D+ ∆NE ;
}
else{
D = D+ ∆E ;
}
}
}
(-30, 20) to (90, 40)
dx= 90 + 30 = 120 ; dy = 40- 20 = 20;
D = 2*20 – 120 = -80; ∆NE = 2*(20-120) = -200 ; ∆E = 2*20 = 40;

45

40

35

30

25

20

15

10

0
-40 -20 0 20 40 60 80 100

 
m = = 0.167 < 1
(20, -30) to (40, 90)
dy= 90 + 30 = 120 ; dx = 40- 20 = 20;
D = 2*120 – 20 = 220; ∆NE = 2*(120-20) = 200 ; ∆E = 2*120 = 240;

0
15 20 25 30 35 40 45

-5

-10

-15

-20

-25

-30

-35

 
m = = 6 >1
(30, -20) to (-90, 40)
• 
• If we start from (30, -20), then we need
to decrement x to reach (-90, 40)
• If we start from (-90, 40), x will be
incremented to reach (30, -20) but y
needs to be decremented!
• m = = - 0.5 < 0
x1, y1

Midpoint Line Drawing Coordinates (x, y) of


points on the line
x2, y2
Algorithm
Eight Way Symmetry FindZone(x1, y1, x2, y2){
dx= x2 - x1 ; dy = y2 - y1 ;
Zone: 2
Zone: 1
dx<0, dy>0, |dy|>|dx| if(|dx| > |dy|){
dx>0, dy>0, |dy|>|dx|
if(dx>0 && dy>0) zone = 0;
else if(dx<0 && dy>0) zone =3;
else if (? ?) zone = ? ;
else if (? ?) zone = ?
Zone: 0 }
Zone: 3
dx<0, dy>0, |dx|>|dy| dx>0, dy>0, |dx|>|dy|
else{
if(dx>0 && dy>0) zone = 1;
Zone: 4 Zone: 7 else if(dx<0 && dy>0) zone =2;
? ? else if (? ?) zone = ? ;
else if (? ?) zone = ?
}

Zone: 5 Zone: 6
? ?
2 1

3 0 (100, 35)

4 7

(-50, -15)

5 6
dx = 100 + 50 = 150 > 0
dy = 35 + 15 = 50 > 0
|dx| > |dy|
Zone = 0
How do we utilize the zones?
Input (x1, y1) to (x2,y2) for a line of Zone M, FindZone
where M ={0, 1, …, 7}

Convert the coordinates of a line in Zone M


into the coordinates of a line in Zone 0 ?

Use the existing midpoint line drawing


algorithm for Zone 0 MidPoint

Convert the points (x, y) back to original ?


Zone M
Convert the coordinates of Zone M into the coordinates of Zone 0
Zone 1 → Zone 0

Coordinates in Zone 1: ( X, Y ) becomes (Y , X) in Zone 0

(5, 50) ConvertToZone0 (X, Y, zone){

if (zone == 1){
(50, 5) x = Y, y = X
}
return (x, y)

}
Convert the coordinates of Zone M into the coordinates of Zone 0
Zone 2 → Zone 0

Coordinates in Zone 2: ( X, Y ) becomes (Y , - X) in Zone 0


(-5, 50)
ConvertToZone0 (X, Y, zone){

if (zone == 1){
(50, 5) x = Y, y = X
}
else if (zone ==2){
x = Y, y = -X
}
return (x, y)

}
Convert the coordinates of Zone M into the coordinates of Zone 0
Zone 3 → Zone 0

Coordinates in Zone 3: ( X, Y ) becomes (-X, Y) in Zone 0

ConvertToZone0 (X, Y, zone){

if (zone == 1){
(-50, 5) (50, 5) x = Y, y = X
}
else if (zone ==2){
x = Y, y = -X
}
else if (zone ==3){
x = -X , y = Y
}
DIY for zone 4, 5, 6, 7
….
return (x, y)

}
Input (x1, y1) to (x2,y2) for a line of Zone M, FindZone
where M ={0, 1, …, 7}

Convert the coordinates of a line in Zone M


into the coordinates of a line in Zone 0 ConvertToZone0

Use the existing midpoint line drawing


algorithm for Zone 0 MidPoint

Convert the points (x, y) back to original ?


Zone M
Go back to original zone M
Zone 0 → Zone 1

Coordinates in Zone 0: ( X, Y ) becomes (Y , X) in Zone 1


(5, 50)

OriginalZone (X, Y, zone){

if (zone == 1){
(50, 5) x = Y, y = X
}
return (x, y)

}
Go back to original zone M
Zone 0 → Zone 2

Coordinates in Zone 0: ( X, Y ) becomes (-Y , X) in Zone 2


(-5, 50)

OriginalZone (X, Y, zone){

if (zone == 1){
(50, 5) x = Y, y = X
}
else if(zone == 2){
x = -Y, y = X
}
return (x, y)

}
Go back to original zone M
Zone 0 → Zone 3

Coordinates in Zone 0: ( X, Y ) becomes (-X , Y) in Zone 3

OriginalZone (X, Y, zone){

if (zone == 1){
(-50, 5) (50, 5) x = Y, y = X
}
else if(zone == 2){
x = -Y, y = X
}
else if (zone ==3){
x = -X , y = Y
}
…. DIY for zone 4, 5, 6, 7
return (x, y)

}
Input (x1, y1) to (x2,y2) for a line of Zone M, FindZone
where M ={0, 1, …, 7}

Convert the coordinates of a line in Zone M


into the coordinates of a line in Zone 0 ConvertToZone0

Use the existing midpoint line drawing


algorithm for Zone 0 MidPoint

Convert the points (x, y) back to original OriginalZone


Zone M
(-10,-20) to (-20, 70)
dx = -20 +10 = -10 < 0
dy = 70 + 20 = 90 > 0
|dy| > |dx|, zone = 2
(-10, -20) → (-20, 10) and (-20, 70) →(70, 20)
dx’ = 70 + 20 = 90, dy’ = 20-10 = 10
D = 2*10-90 = -70, ∆NE = 2*(10-90)= -160, ∆E=2*10=20
X’ Y’ D X Y
-20 10 -70 -10 -20
-19 10 -50 -10 -19
-18 10 -30 -10 -18
-17 10 -10 -10 -17
-16 10 10 -10 -16
-15 11 -150 -11 -15
-14 11 -130 -11 -14

You might also like