CS 45: COMPUTER GRAPHICS RASTERIZING CONICS SPRING 6 DR. MICHAEL J. REALE
RASTERIZING CURVES OTHER THAN LINES When dealing with othe inds of cuves, we can daw it in one of the following was: Use elicit fom i.e., = f)) o a aametic fom i.e., = fs) and = gs)) aoimate cuve with line segments Paametic fom bette fo this eas to get evenl-saced oints along cuve ath Can connect oints OR use best-fitting line linea egession o least squaes aoach) Use imlicit fom i.e., f,) = ) and deive incemental midoint method In the net few slides, we ll loo at how to asteize: Cicles Ais-aligned) Ellises using incemental midoint methods
MIDPOINT CIRCLE ALGORITHM
INTRODUCTION A cicle can be defined b its imlicit fom: c, c ) cente of cicle = adius Since a cicle is smmetic in all 8 octants just comute one octant and elicate in othes ) ) ), f c c
DECISION VARIABLE Assume the cicle is centeed at,) We e going to stat b: Incementing b Choose whethe to go down o not in To detemine ou net choice, we will loo at ou decision vaiable based on the midoint +, - ½): If < midoint inside cicle choose If > midoint outside cicle choose - f, )
UPDATING THE DECISION VARIABLE If ou wo though the math simila to the wa we deived ou line midoint algoithm), we also find two diffeent udate conditions HOWEVER, because the sloe along cicle is changing udate values deend on cuent and! If < add + ) + If > add + ) + ) We can mae this moe efficient is we udate +) and -) incementall: ) )
INITIAL VALUES We will stat at,) Initial decision vaiable value: Howeve, if ou adius is an intege, we can ound to =, since all incements ae integes f 4 5 4 ),
MIDPOINT CIRCLE ALGORITHM SUMMARIZED. Inut adius and cicle cente c, c ); fist oint =, ) =,). Calculate initial decision vaiable value: 3. At each, test : If < net oint is +, ) and: Othewise net oint is +, - ) and: Whee: 4. Fo each calculated osition,), lot + c, + c ) 5. Plot coesonding smmetic oints in othe seven octants 6. Reeat stes 3 though 5 UNTIL >= Effectivel etending we ae centeed on,) 5 4
MIDPOINT ELLIPSE ALGORITHM
MIDPOINT ELLIPSE ALGORITHM We e going to assume the following about ou ellise: Ais aligned Centeed at,) won t affect the iels we choose Ellises smmetic in each QUADRANT So, we just need one quadant s iels and then eeat fo the othe thee HOWEVER, when the abssloe) =. should switch fom incementing in X to decementing in Y! Means we will have two egions to wo about
ELLIPSE FORMULA AND SLOPE We assume the ellise iscenteed at,) Also, we will multil ou oiginal ellise fomula b and to get: We will also need to chec the sloe do imlicit diffeentiation to get d/d: ), f d d
TESTING THE SLOPE When the sloe = -. at bounda of R and R), then: When the sloe < -. enteing R): d d
DECISION VARIABLE: REGION Ou decision vaiable fo egion is going to be based on whee +, ½) is elative to the tue ellise: Simila to the midoint cicle algoithm: If < inside ellise choose Othewise outside ellise choose Initial value: ), f 4, f
INCREMENTING THE DECISION VARIBLE: REGION If < chose + = Othewise chose + = - ) ) )
WHEN DO WE SWITCH TO REGION? We have to chec when this eession becomes tue: At the stating oint, ), these values ae: So, eve iteation: Add to s If we choose ), subtact fom s s s
DECISION VARIABLE: REGION Decementing in If > outside choose incement : Othewise inside choose + ) incement :, f ) ) )
INITIAL DECISION VARIBLE: REGION We ll use the last oint we had befoe switching to egion : An altenative would be to stat at, ) and go counteclocwise; we would then INCREMENT and choose between and ), f
MIDPOINT ELLIPSE ALGORITHM: REGION. Inut,, and ellise cente c, c ); get fist oint fo ellise centeed on oigin:. Get initial decision vaiable fo egion : 3. While < ) If < choose +, ) Othewise choose +, ) ), ), 4 ) ) )
MIDPOINT ELLIPSE ALGORITHM: REGION 4. Get initial value of decision vaiable fo egion fom last osition, ) calculated in egion : 5. While!= ) If > choose, ) Othewise choose +, ) 6. Fo both egions, define smmet oints:,), -,),,-), and -,-) 7. Fo each osition,), lot: ) ) ) c c
NONSTANDARD ELLIPSES We have two was to deal with non-standad ellises i.e., ellises that do not line u with the coodinate aes): ) Adat fomulas to wo ove ENTIRE ellise ath ) Get the iels fo the standad ellise, but then tansfom the oints i.e., otation mati)
RASTERIZING CONIC SECTIONS SUMMARY
DRAWING CONIC SECTIONS SUMMARY Figue out whee the cuve is smmetical Cicles smmetical acoss 8 octants Ellises/Hebolas smmetical acoss 4 quadants Paabolas smmetical acoss vetical ais Comute decision vaiable fomulas fo aeas whee sloe is less than. and geate than. Go though midoint algoithm, checing when to switch because of sloe