Grahics Ouu Primiives ( 그래픽스출력기본단위 ) 3 rd Wee, 8 Sun-Jeong Kim Poins Lines DDA algorihm Bresenham s algorihm Polgons Conens Conve and concave olgons Inside-ouside ess Polgon ales Fron and ac faces
Poins Posiion in sace Screen coordinaes sepiel(, ); ); gepiel(,,, color); 3 Lines All oins eween wo endoins DDA, Bresenham s line-drawing algorihms Sair-se effec (jaggies) 4
Line Equaions The Caresian sloe-inerce equaion m m end end end m end 5 DDA Algorihm The digial differenial analzer < sloe < Uni inerval end end m 6
DDA Algorihm The digial differenial analzer < sloe < Uni inerval sloe > Uni inerval end end m 7 DDA Algorihm The digial differenial analzer < sloe < Uni inerval sloe > Uni inerval < sloe < Uni inerval end (he saring endoin is a he righ) end m 8
DDA Algorihm The digial differenial analzer < sloe < Uni inerval sloe > Uni inerval < sloe < Uni inerval (he saring endoin is a he righ) sloe < Uni inerval end end m 9 Pseudo Code of DDA Algorihm #include #include <sdli.h> <sdli.h> #include #include <mah.h> <mah.h> inline inline in in round( round( cons cons floa floa a ) { reurn reurn in(a.5); in(a.5); void void linedda( linedda( in in,, in in,, in in End, End, in in End End ) { in in d d End End,, d d End End,, ses, ses, ; ; floa floa Incremen, Incremen, Incremen, Incremen,,, ; ; if( if( fas(d) fas(d) > fas(d) fas(d) ) ses ses fas(d); fas(d); else else ses ses fas(d); fas(d); Incremen Incremen floa(d)/floa(ses); Incremen Incremen floa(d)/floa(ses); sepiel( sepiel( round(), round(), round() round() ); ); for( for( ; ; <ses; <ses; ) { Incremen; Incremen; Incremen; Incremen; sepiel( sepiel( round(), round(), round() round() ); );
Bresenham s Algorihm () An accurae and efficien algorihm Using onl incremenal ineger calculaions Tesing he sign of an ineger arameer Lines wih osiive sloe less han. Afer he iel a (, ) is dislaed, ne which iel is decided o lo in column? (, ) or (, ) Bresenham s Algorihm () Lines wih osiive sloe less han. a samling osiion ( ) m Difference d m d ( ) ( ) m( ) d d > ( (, ) d d < ( (, )) Decision arameer d d ( ) c ( ) m m d d ( ) c
3 Bresenham s Algorihm (3) Lines wih osiive sloe less han. Decision arameer Decision arameer of a saring iel (, ) ( ) ( ) ( ) ( ) c c ( ) ( ) ( ) ( ) m 4 Bresenham s Algorihm (4) Algorihm for m <. Inu he wo line endoins and sore he lef endoin in (, ) Se he color for frame-uffer osiion (, ); i.e., lo he firs oin Calculae he consans,,, and, and oain he saring value for he decision arameer as A each along he line, saring a, erform he following es: If <, he ne oin o lo is (, ) and Oherwise, he ne oin o lo is (, ) and Perform se 4 imes
Bresenham s Algorihm (5) Eamle 3-) To illusrae he algorihm, we digiize he line wih endoins (, ) and (3, 8) Sloe.8 (, 8) Iniial decision arameer: 6 Incremens: 6, 4 Plo he iniial oin (, ) (, ) and deermine successive iel osiions: (, ) 6 (, ) (, ) (3, ) (, ) 3 4 (4, 3) 4 (5, 4) 5 6 (6, 5) 5 (, ) 6 (7, 6) 7 (8, 6) 8 4 (9, 7) Pseudo Code of Bresenham s Algorihm #include #include <sdli.h> #include <sdli.h> #include <mah.h> <mah.h> /* /* Bresenham s Bresenham s algorihm algorihm for for m <. m <. */ void */ void linebres( linebres( in in,, in in,, in in End, End, in in End End ) { in in d d fas(end fas(end ), ), d d fas(end fas(end ); in ); in * d d d; in d; in wod wod * d, d, wodminusd wodminusd * (d (d d); d); /* /* Deermine Deermine which which endoin endoin o o use use as as sar sar osiion osiion */ if( */ if( > End End ) { End; End; End; End; End End ; ; else else { ; ; ; ; sepiel( sepiel(,, ); ); while( while( < End End ) { ; if( ; if( < ) wod; else wod; else { ; ; wodminusd; wodminusd; sepiel( sepiel(,, ); ); 6
Polgons A lane figure secified a se of hree or more coordinae osiions, called verices Edges: sraigh-line segmens Conve and concave olgons < 8 < 8 7 Inside-Ouside Tess Self-inersecing closed olline Odd-even rule Nonzero winding-numer rule Eerior Inerior 3 4 8
Polgon Tales Descriing he ojecs in a scene V Vere Tale Edge Tale E V :,, z E : V, V V S E 3 E 6 E S V 3 V 5 V :,, z V 3 : 3, 3, z 3 V 4 : 4, 4, z 4 E : V, V 3 E 3 : V 3, V E 4 : V 3, V 4 E 4 E 5 V 5 : 5, 5, z 5 E 5 : V 4, V 5 V 4 E 6 : V 5, V Surface-Face Tale S : V, V, V 3 S : V 3, V 4, V 5, V 9 Fron and Bac Faces Fron face: he visile or ouward side N(A, B, C) N ( V V ) ( V3 V ) V 3 N V D V V A B Cz D z If If A A B B Cz Cz D < D >, he oin (,, z ) is ehind he lane, he oin (,, z ) is in fron of he lane