Sei sulla pagina 1di 28

8teseoboms MlJlolot cltcle Alqotltbm

MldolnL Clrcle AlgorlLhm


W Slmllarly Lo Lhe case wlLh llnes Lhere ls an
lncremenLal algorlLhm for drawlng clrcles
Lhe mlJpolot cltcle olqotltbm
W n Lhe mldpolnL clrcle algorlLhm we use elghL
way symmeLry so only ever calculaLe Lhe
polnLs for Lhe Lop rlghL elghLh of a clrcle and
Lhen use symmeLry Lo geL Lhe resL of Lhe
polnLs
C|rc|e Generat|ng A|gor|thms
W A clrcle ls deflned as Lhe seL of polnLs LhaL are all
aL a glven dlsLance r from a cenLer polnL (x
c
, y
c
).
W or any clrcle polnL (x y) Lhls dlsLance ls
expressed by Lhe LquaLlon
W We calculaLe Lhe polnLs by sLepplng along Lhe x
axls ln unlL sLeps from x
c
-r Lo x
c
r and calculaLe y
values as
2 2 2
) ( ) ( r y y x x
c c
= +
2 2
) ( x x r y y
c c
=
A Slmple Clrcle urawlng AlgorlLhm
W 1he equaLlon for a clrcle ls
W where r ls Lhe radlus of Lhe clrcle
W So we can wrlLe a slmple clrcle drawlng
algorlLhm by solvlng Lhe equaLlon for y aL unlL
x lnLervals uslng
2 2 2
r y x = +
2 2
x r y =
A Slmple Clrcle urawlng AlgorlLhm (conL)
20 0 20
2 2
0
= y
20 1 20
2 2
1
= y
20 2 20
2 2
2
= y
6 19 20
2 2
19
= y
0 20 20
2 2
20
= y
C|rc|e Generat|ng A|gor|thms
W 1here are some prob|ems w|th th|s approach
Conslderable compuLaLlon aL each sLep
-onunlform spaclng beLween ploLLed plxels as ln Lhls lgure
A Slmple Clrcle urawlng AlgorlLhm (conL)
W Powever unsurprlslngly Lhls ls noL a brllllanL
soluLlon!
W lrsLly Lhe resulLlng clrcle has large gaps where
Lhe slope approaches Lhe verLlcal
W Secondly Lhe calculaLlons are noL very efflclenL
1he square (mulLlply) operaLlons
1he square rooL operaLlon Lry really hard Lo avold
Lhese!
W We need a more efflclenL more accuraLe soluLlon
C|rc|e Generat|on us|ng o|ar Coord|nates
W roblem can be correcLed uslng Lhe polar form
W uslng a flxed angular sLep slze a clrcle ls ploLLed wlLh
equally spaced polnLs along Lhe clrcumference
7
7
sin
cos
r y y
r x x
c
c
+ =
+ =
LlghLWay SymmeLry
W 1he flrsL Lhlng we can noLlce Lo make our clrcle drawlng
algorlLhm more efflclenL ls LhaL clrcles cenLred aL (, ) have
elqbtwoy symmetty
(x, y)
(y, x)
(y, -x)
(x, -y) (-x, -y)
(-y, -x)
(-y, x)
(-x, y)
2
#
LlghLWay SymmeLry
) , ( y x ) , ( y x
) , ( y x
) , ( y x
) , ( x y ) , ( x y
) , ( x y ) , ( x y
(x, y) (-x, y) (-x, -y) (x, -y), (y, x) (-y, x) (-y, -x) (y, -x)}

nd
CcLanL
We will
generate
2
nd
Octant
no verLlcal LangenLs ,8450, A 1
MldolnL Clrcle AlgorlLhm
(x
k
+1, y
k
)
(x
k
+1, y
k
-1)
(x
k
, y
k
)
W Assume LhaL we have
[usL ploLLed polnL (x
k
, y
k
)
W 1he nexL polnL ls a
cholce beLween (x
k
1, y
k
)
and (x
k
1, y
k
-1)
W We would llke Lo choose
Lhe polnL LhaL ls nearesL Lo
Lhe acLual clrcle
W So how do we make Lhls
cholce?

Clrcle LquaLlon
W LeL's modlfy Lhe equaLlon of Lhe clrcle sllghLly Lo glve us
W 1he funcLlon ( y) ls
on Lhe clrcle
poslLlve ouLslde Lhe clrcle
negaLlve lnslde Lhe clrcle
W 1he equaLlon evaluaLes as follows
W 8y evaluaLlng Lhls funcLlon aL Lhe mldpolnL beLween Lhe candldaLe plxels we can make our declslon


boundary circle the outside is y) (x, iI 0
boundary circle on the is y) (x, iI 0
boundar circle the inside is y) (x, iI 0
) , ( y x f
circ0
0 ) , (
2 2 2
= + = r y x y x f
circ0
f(x, y) evaluation
0 ) , ( y x f
0 ) , ( = y x f
0 ) , ( y x f
1he ueclslon varlable
W Assumlng we have [usL ploLLed Lhe plxel aL (x
k
, y
k
) so we
need Lo choose beLween (x
k
1, y
k
) and (x
k
1, y
k
-1)
W Cur declslon varlable can be deflned as
W f 5
k
Lhe mldpolnL ls lnslde Lhe clrcle and Lhe plxel aL
y
k
ls closer Lo Lhe clrcle
W CLherwlse Lhe mldpolnL ls ouLslde and y
k
-1 ls closer
2 2 2
)
2
1
( ) 1 (
)
2
1
, 1 (
r y x
y x f 5
k k
k k circ0 k
+ + =
+ =

L
ideal
curve
0 K
k
5
mldpolnL ls ouLslde Lhe clrcle

L
ideal
curve
0
k
5
mldpolnL ls lnslde Lhe clrcle
W Lhe plxel ls chosen and
W Lhe nexL mldpolnL wlll be
then ) 0 ( iI
k
5
)
2
1
, 1 (
1
+
+ k k
y x
)
)
) )
) )
) )
) )
x
r y x r y x x
r y x r y x x
r y x r y x
y x f y x f 5 5
5 5
r y x
y x f 5
k
k k k k k
k k k k k
k k k k
k k circ0 k k circ0 k k
k k
k k
k k circ0 k
A = + =
+ + + + + + =
+ + + + + + =
+ + + + + =
+ =
+ + + =
+ =
+ + +
+
+ +
2
2
1
) 1 (
2
1
2 ) 1 (
)
2
1
) 1 (( )
2
1
) 2 ) 1 ((
)
2
1
) 1 (( )
2
1
| 1 ) 1 (|(
2
1
,
2
1
, 1
and between diIIerence The
2
1
| 1 ) 1 |(
2
1
, 1
2
2
2 2
2
2
2
2
2 2
2
2
2
2
2 2
2
2
1 1 1
1
2
2
2
1 1
)
)
) )
) )
) )
) )
) )
) )
) )
$ y x
y x
y y y y x
y y y y x
y y y y x
y y x
r y x x r y x x
r y x x r y x x
r y x x r y x
r y x r y x
y x f y x f 5 5
5 5
r y x
y x f 5
k k
k k
k k
k k
k
k
k
k
k
k
k
k
k
k
k
k k k
k k
k
k k
k
k k
k
k k
k
k k
k
k k
k k k k
k k circ0 k k circ0 k k
k k
k k
k k circ0 k
A = + =
+ + =
+ + + + =
+ + + + =
+ + + + =
+ + =
+ + + + =
+

+ + + =

+ + +

+ + =

+ +

+ + =
+ + =
+ + =
+ =
+
+ +
+
+
+ +
2 2
2 2 2

9
2

9
2

9
2
2
1
2

2
2
1
1 2
2


2
1
1 2
2


2
1
) 1 2 (
2

) 2 (
2
1
) 1 (
2

) 1 (
2
1
, 1
2

, 1
and between diIIerence The
2

) 1 (
2

, 1
2 2
2 2
2 2
2 2
2
2
2 2
2
2
2
2
2 2
2
2
2
2
2 2
2
2
2
2
`
2 2
2
2
1
1 1
1
2
2
2
1
1 1
then ) 0 ( iI K
k
5
W Lhe plxel S ls chosen and
W Lhe nexL mldpolnL wlll be
)
2

, 1 (
1
+
+ k k
y x
ueclslon varlable updaLe
2 2
)
2

1 ( be ill midpoint w next the


chosen is pixel the
then ) 0 ( iI
2
)
2
1
1 ( be ill midpoint w next the
chosen is pixel the
then ) 0 ( iI
1
1
1
1
+ + = A + =
+
K
+ + = A + =
+

+
+
+
+
k k k k k
k k
k
k k k k
k k
k
y x 5 $ 5 5
,y x
$
5
x 5 5 5
,y x

5
and $ are not constants. Depend on values oI x
k
and y
k.
n|t|a| Va|ue of Dec|s|on arameter
W 1he lnlLlal declslon parameLer ls obLalned by evaluaLlng Lhe
clrcle funcLlon aL Lhe sLarL poslLlon (

) ( t)
r
r
r r r
r r
r f 5
circ
=
+ =
+ + =
+ =
=

1 1
) 1 ( 1
)
2
1
( 1
)
2
1
, 1 (
2 2
2 2
0
cltclelolots( y) funcLlon
Void CirclePoints(int x, int y)
,
setPixel( x, y,1);
setPixel( y, x,1);
setPixel( y, -x,1);
setPixel( x, -y,1);
setPixel(-x, -y,1);
setPixel(-y, -x,1);
setPixel(-y, x,1);
setPixel(-x, y,1);
,
MldpolnL clrcle AlgorlLhm
;oid MidpointCircle(int radius, int ;alue)
,
int x=0;
int y=radius;
double d=5.0/4.0-radius;
CirclePoints(x,y);
while (y x)
,
if (d < 0) d += 2.0 x + 3.0;
else
,
d += 2.0 (x - y) + 5.0;
y--;
,
x++;
CirclePoints(x, y);
,
,
econd Crder D|fferences
W Can lmprove Lhe performance of Lhe scan
converslon by uslng Lhe lncremenLal Lechnlque
a second Llme
W 1he Lechnlque ls called second order
dlfferences
W 1he funcLlons are llnear equaLlons
W Any polynomlal can be compuLed
lncremenLally
econd Crder D|fferences
2 2 2 2 2 2
) 2 2 ( 2 ) 1 ( 2
2 ) 1 ( 2
) , 1 ( at thereIore
2 2
$imilarly
2 2 2 2
) 1 ( 2
) , 1 ( at thereIore
2
) ( at diIIerence order Iirst The
) , 1 ( to ) , ( From
1
1
1
1
= + + + = A A
+ + + = A A
+ + = A
+
+ = A
= + + = A A
+ + = A
+
+ = A
+
+
+
+
+
+
k k k k k k
k k k k k k
k k k
k k
k k k
k k k k
k k
k k
k k
k k
k k k k
y x y x $ $
y x y x $ $
y x $
y x
y x $
x x
x
y x
x
y x
y x y x
f we choose Lhe plxel aL Lhe currenL lLeraLlon Lhe polnL of evaluaLlon moves
econd Crder D|fferences
2 2 2 2 2 2
) 2 2 ( ) 1 ( 2 ) 1 ( 2
) 1 ( 2 ) 1 ( 2
) 1 , 1 ( at thereIore
2 2
$imilarly
2 2 2 2
) 1 ( 2
) 1 , 1 ( at thereIore
2
) ( at diIIerence order Iirst The
) 1 , 1 ( to ) , ( From
1
1
1
1
1
= + + + + = A A
+ + + = A A
+ + = A
+
+ = A
= + + = A A
+ + = A
+
+ = A
+
+
+
+
+
+
+
k k k k k k
k k k k k k
k k k
k k
k k k
k k k k
k k
k k
k k
k k
k k k
y y x x $ $
y x y x $ $
y x $
y x
y x $
x x
x
y x
x
y x
y x y x
f we choose Lhe plxel aL Lhe currenL lLeraLlon Lhe polnL of evaluaLlon moves
Comput|ng n|t|a| Dec|s|on Va|ue
W f Lhe radlus r ls speclfled as an lnLeger we can
slmply round l

Lo
W Slnce all lncremenLs are lnLegers
integer) an (Ior 1
0
r r P =
econd D|fference C|rc|e A|gor|thm
;oid circle( int radius, int ;alue )
,
int x, y, d, deltaE, deltaSE;
int x = 0; y = radius;
int d = 1-radius;
deltaE = 3;
deltaSE = 5 - radius 2;
CirclePoints( x, y);
while( y x )
,
if( d < 0 )
,
d += deltaE;
deltaE += 2;
deltaSE += 2;
x++;
,
else
,
d += deltaSE;
deltaE += 2;
deltaSE += 4;
x++;
y--;
,
CirclePoints(x, y);
,
,

Potrebbero piacerti anche