Академический Документы
Профессиональный Документы
Культура Документы
Midpoint Algorithm
Given a point just drawn, determine whether we move E or
NE on next step
Midpoint Algorithm
Given a point just drawn, determine whether we move E or NE
on next step?
Below: move E
Above: move NE
( x 1, y )
1
2
( x, y )
y mx B
yH yL
xH xL
xB
yH yL
xH xL
x B)(xH xL )
( x H xL ) y (
( xH xL ) y ( yH yL ) x ( xH xL ) B
Nihar Ranjan Roy,
https://sites.google.com/site/niharranjanroy/
( xH xL ) y ( yH yL ) x ( xH xL ) B
( yH yL ) x ( xH xL ) y ( xH xL ) B 0
( yH yL ) x ( xH xL ) y ( xH xL ) B 0
d f ( x, y ) ax by c
Location of midpoint d=?
f(x,y)=0 (x,y) on the line
a yH yL y
b ( xH xL ) x
c B( xH xL )
(6,5)
(0,2)
x
y x2
3
6
f ( x, y ) 3x 6 y 12
(6,5)
(0,2)
Location of midpoint d=?
f(x,y)=0 (x,y) on the line
y x2
3
6
f ( x, y ) 3x 6 y 12
f (0,5) 18
(6,5)
(0,2)
y x2
3
6
f ( x, y ) 3x 6 y 12
(6,5)
(0,2)
f (4,1) 18
y x2
3
6
f ( x, y ) 3x 6 y 12
(6,5)
f (4,4) 0
(0,2)
y x2
3
6
f ( x, y ) 3x 6 y 12
(6,5)
(0,2)
Midpoint Algorithm
Need value of f ( x 1, y 12 ) to determine E or NE
Build incremental algorithm
1
Assume we have value of f ( x 1, y 2 )
1
Find value of f ( x 2, y ) if E chosen
2
Find value of f ( x 2, y 3 ) if NE chosen
2
NE
d?
2
,
y
dnew f ( x 2, y 12 ) a( x 2) b( y 12 ) c
dnew dold a
dnew dold y
( x 2, y 12 )
NE
dnew
Midpoint Algorithm
d>0
3
f
(
x
2
,
y
dnew f ( x 2, y 32 ) a( x 2) b( y 32 ) c
NE
dold dnew
Nihar Ranjan Roy,
https://sites.google.com/site/niharranjanroy/
Midpoint Algorithm
d>0
f ( x 2, y 32 )
dnew f ( x 2, y 32 ) a b f ( x 1, y 12 )
dnew dold a b
dnew dold y x
Midpoint Algorithm
d0 ?
d 0 f ( xL 1, yL 12 ) a( xL 1) b( yL 12 ) c
Midpoint Algorithm d0 ?
What about starting value?
d 0 f ( xL 1, yL 12 ) a( xL 1) b( yL 12 ) c
d 0 f ( xL 1, yL 12 ) f ( xL , yL ) a 12 b
Midpoint Algorithm
What about starting value?
d 0 f ( xL 1, yL 12 ) a( xL 1) b( yL 12 ) c
f ( xL 1, yL 12 ) f ( xL , yL ) a 12 b
( xL , yL ) is on the line! =0
d 0 f ( xL 1, yL 12 ) a 12 b
Midpoint Algorithm
d 0 f ( xL 1, yL 12 ) a 12 b
Multiplying coefficients by 2 doesnt change sign of f
d 0 f ( xL 1, yL 12 ) 2a b
d 0 f ( xL 1, yL 12 ) 2y x
dnew dold 2y
E is Chosen
NE is Chosen
NE
Problem
-2
(1,2)
NE
(x,y)
(1,2)
(2,3)
(2,3)
-6
(3,3)
(3,3)
-2
(4,3)
(4,3)
2
-6
(5,4)
(6,4)
(5,4)
(6,4)
output
-2
(1,2)
NE
(x,y)
(2,3)
(2,3)
-6
(3,3)
(3,3)
-2
(4,3)
(4,3)
2
-6
(5,4)
(6,4)
(6,4)
(1,2)
(5,4)
(0,2)
(6,4)