Professional Documents
Culture Documents
Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Computer Graphics Course
Kocaeli University Fall 2012
yH yL xH xL
2 40 1 6 3
(6,4)
x6 y4
(0,2)
Question: if we draw the current pixel, where is the next pixel? Next column, E or NE direction
2/110
Midpoint Algorithm
Given a point just drawn, determine whether we move E or NE on next step
3/110
(6,4)
(0,2)
4/110
Two Issues
How to evaluate if the midpoint is above or below the line? How to incrementally evaluate this?
5/110
(3,7)
(6,5) (0,2)
x
6/110
y ( x H xL ) y (
yH yL xH xL yH yL xH xL
x b x b)(xH xL )
( xH xL ) y ( yH yL ) x ( xH xL )b ( xH xL ) y ( yL yH ) x ( xL xH )b 0
7/110
( xH xL ) y ( yL yH ) x ( xL xH )b 0
f ( x, y) cx dy e
c yL yH Properties d xH xL e b( x L x H )
f(x,y)=0 (x,y) on the line f(x,y)<0 (x,y) below the line f(x,y)>0 (x,y) above the line
8/110
y
f (0,5) 18
f ( x, y) 6 y 3x 12
(0,2)
(6,5) f (4,4) 0
f (4,1) 18
x
9/110
Two Issues
How to evaluate if the midpoint is above or below the line? How to incrementally evaluate this?
What about starting value? What is the middle point?
(xL+1,yL+1/2)
10/110
Midpoint Algorithm
What about starting value?
(xL+1,yL+1/2)
f ( xL 1, y L 1 ) c( xL 1) d ( y L 1 ) e 2 2 f ( xL 1, y L 1 ) f ( xL , y L ) c 1 d 2 2 f ( xL 1, y L 1 ) f ( xL , y L ) c 1 d 2 2
( xL , y L ) is on the line!
f ( xL 1, y L 1 ) c 1 d 2 2
11/110
Midpoint Algorithm
What about starting value?
f ( xL 1, y L 1 ) c( xL 1) d ( y L 1 ) e 2 2 f ( xL 1, y L 1 ) 2c d 2
Multiplying coefficients by 2 doesnt change sign of f
12/110
Midpoint Algorithm
Need value of f ( x 1, y 1 ) to determine E or 2 NE Build incremental algorithm Assume we have value of f ( x 1, y 1 ) 2
Find value of f ( x 2, y 1 ) if E chosen 2
13/110
Midpoint Algorithm
Need value of f ( x 1, y 1 )to determine E or NE 2 Build incremental algorithm Assume we have value of f ( x 1, y 1 ) 2
Find value of f ( x 2, y 1 ) if E chosen 2 Find value of f ( x 2, y 3 ) if NE chosen 2
14/110
Midpoint Algorithm
If E was chosen, find
f ( x 2, y 1 ) 2
f ( x 2, y 1 ) c( x 2) d ( y 1 ) e 2 2 f ( x 2, y 1 ) c f ( x 1, y 1 ) 2 2
15/110
Midpoint Algorithm
If NE was chosen, find
f ( x 2, y 3 ) 2
f ( x 2, y 3 ) c( x 2) d ( y 3 ) e 2 2 f ( x 2, y 3 ) c d f ( x 1, y 1 ) 2 2
16/110
x 0
y 2 sum 2 (6,4)
(0,2)
d =6 c = -2
20/110
x 0
y 2 sum 2 (6,4)
(0,2)
d =6 c = -2
21/110
x 1
y 2 sum 2 (6,4)
(0,2)
d =6 c = -2
22/110
x2
y 3 sum 6 (6,4)
(0,2)
d =6 c = -2
23/110
x 3
y 3 sum 2 (6,4)
(0,2)
d =6 c = -2
24/110
x 4 y 3 sum 2
(6,4)
(0,2)
d =6 c = -2
25/110
x 5 y 4 sum 6
(6,4)
(0,2)
d =6 c = -2
26/110
x 6
y 4 sum 2 (6,4)
(0,2)
d =6 c = -2
27/110
Midpoint Algorithm
Only integer operations Exactly the same as the more commonly found Bresenhams line drawing algorithm Extends to other types of shapes (circles)
28/110