2D Graphcs
2D Raster Graphcs Integer grd Sequental (left-rght, top-down scan j
Lne drawng A ver mportant operaton used frequentl, block dagrams, bar charts, engneerng drawng, archtecture plans, etc. curves as concatenaton of small lne segments Crtera lne should appear straght llumnate nearest grd pont
Lne drawng Lne should termnate correctl Lne should have a constant ntenst specf both end ponts nstead of end pont + slope +length 5 / 4 2 brghtness adjustment (antalasng 5/4 ntenst ~ # of dots/unt length
Lne drawng Lne should not have gaps =f( f slope < =f( f slope > =f(
Lne drawng Lne should be drawn as fast as possble Brute-force method DDA (dgtal dfferental analzer for( m m b ; o m m( b n b m b m ; m b fp * fp + fp +
Bresenham s Lne Algorthm nteger operatons onl t slope (, ( 2, 2 (, (, f s t or s t t else s t or s t s s
possble current ntersecton range 45 o 45 o possble net ntersecton range
Bresenham s Lne Algorthm d s ( d (, (, d t ( ( d d s t 2 ( d 2 d( s t 2( d d 2d d d floatng pont t s d d Integer!! (
( 2 2 ( 2 2 ( 2 ( 2 2 2( 2 2( d d d d d d d d d d d d d d d d d d d d d d Bresenham s Lne Algorthm
d d 2d 2d( f d choose t d d 2( d d f d Bresenham s Lne Algorthm choose s d d 2d ntal condton d 2d d (, (, Complet: left shft + 2 nteger addtons
Crcle Drawng Smmetr reduces drawng to /8 (-, (-,- (-, (, (, (,- r c c cos r sn (-,- (,-
Bresenham s Crcle Algorthm nteger operatons onl (, t (, (, c o c 45 9 o (, s 2 2 2 2 2 2 D( s ( ( r D( s D( t t D( t ( r D( s D( t s
Bresenham s Crcle Algorthm d D( s D( t D( s D( t 2 2 2 2 d 2r 2( ( 2 2 2 2 d 2r 2( 2 ( 2 2 d d 4 6 2( 2(
Bresenham s Crcle Algorthm d 3 2r (, (, r f d choose t, d d 4 6 f d choose s, d d 4 4 6 Complet: onl nteger and shft operatons
Ellpse Other prmtves smmetr reduces to /4 Bresenhem s ellpse algorthm Curve dffcult appromaton usng short lne segments general curve forms (Bezer, B-splne, etc. Characters rectangular grd patterns
Arbtrar # of sdes Conve or concave Holes Y olgon Flng X
Scan Lne Algorthm Edge table sort edges b scanlne (usng mn Y ma record coordnate of mn ma to be added (, mn
Scan Lne Algorthm Set to smallest n ET Intalze AET to be Null Repeat untl AET and ET are empt move from ET bucket to AET those edges whose mn= sort edges n AET b (nserton sort fll n pel values n between pars remove from AET those edges whose ma = ncrement b update for all edges n AET
olgon atterned Fllng Y Y logcal and X X X
olgon atterned Fllng attern can be anchored at a fed pont: transparent object moves on a patterned background a polgon corner: patterned object
2D Transformaton For anmaton, manpulaton, user nteracton translaton, rotaton, scalng T T S S ' ' ' ' cos sn sn cos ' '
A Ver Common Confuson What s beng transformed? onts or coordnate sstem? For CG, ppelne operatons are alwas appled to features (ponts, lnes, curves, planes But ou can thnk n ether wa: onts are phscall moved n a fed coordnate sstem (e.g., n modelng transform, or A coordnate sstem s moved, whle ponts sta statonar (e.g., n vewng transform Both nterpretatons are useful
2D Rgd Transformatons A rgd transformaton maps one coordnate sstem nto another reserves dstances and angles To transform ponts from one coordnate frame to another, fnd the rgd transformaton that brngs the two coordnate frames n algnment Translate so that ther orgns concde Rotate so that ther aes concde ( wth, wth, and z wth z
2D eamples Rot Trans Trans+Rot
2D Translaton Translate the coordnate sstem b (T,T What s the translated pont? T T (T,T
2D rotaton matr Rotate θ counterclockwse What s the transformaton R? R cos sn sn cos
2D Rgd Transformatons A rgd transformaton moves an object from one locaton to another locaton reserves dstances and angles To transform ponts from one place to another, fnd the rgd transformaton that Translate so that the object moves Rotate so that the object reorents
2D eamples Trans Rot Trans+Rot
2D Translaton Translate the coordnate sstem b (T,T What s the translated pont? (T,T T T (-T,-T
2D rotaton matr Rotate θ counterclockwse What s the transformaton R? R - cos sn sn cos
2D Transformaton For anmaton, manpulaton, user nteracton translaton, rotaton, scalng T T S S ' ' ' ' cos sn sn cos ' '
2D Transformaton (cont. Inconsstent representaton for translaton Cannot be concatenated Troublesome for Herarchcal transforms Interactve, ncremental dspla R n ( R3( R2( R T T2 T3 T n
Homogeneous Coordnates consstent representaton for all three can be concatenated & pre-computed (, ( w, w, w, w ( w, w, w ( w / w, w / w
' T ' T ' cos sn ' sn cos ' S ' S ' ' ( TRS
How about other transforms? For eample, reflecton Mrrored mages of each other
Tr to represent the new transform as a composte of T, R, S ( tan cos sn sn cos a b, ( b a ( tan cos sn sn cos a b
Clppng Aganst Uprght Rectangular Wndow onts f & mn ma mn ma then accept otherwse reject
Clppng Aganst Uprght Rectangular Wndow boundar wndow of ponts end : ', ',( ', ' ( lne of ponts end :,,(, ( ', ' ' ( ' ' ( ' ' ( ' ' ( 2 2 2 2 2 2 2 2 t t t t t t Lnes trvall accepted f both end ponts nsde otherwse onts
Cohen-Sutherland Lne-Clppng Algorthm mn ma ma mn Outcodes bt --above: ma- bt2 --below: -mn bt3 --rght of: ma- bt4 --left of: -mn
Trvall-accept: both end ponts havng outcode Trvall-reject: correspondng bts n two outcodes are set, or outcode & outcode2 nonzero
Nether: need more testng E.g. md-pont algorthm dvde a lne segment nto two lne segments (,,(( / 2,( / 2 test each lne ndependentl recursve dvson f necessar (,,( 2, 2 2 2 (( / 2,( / 2,(, 2 2 2 2 guarantee to stop n O(logn steps
Crus-Beck (Lang-Bask Lne Clppng Can be more effcent when ntersecton tests are unavodable Work n the parameter (t space to locate true ntersectons before calculatng 2D coordnates Work for all knds of clppng polgons and n 3D Two basc steps: fnd ntersectons (t classf ntersectons
Fnd ntersectons c b a, ( b a N o (t E ( ( E t N ( ( E t N ( ( E t N ( ( ( ( ( ( ( ( o E o E o o E o o E N N t N N t t N t N Crus-Beck (Lang-Bask Lne Clppng
Intersectons outsde (, range are not vald But ntersecton nsde (, range mght not be vald ether
Crus-Beck (Lang-Bask Lne Clppng Classf ntersectons N N ( ( o o E (potental l enterng L (potental l leavng N N
Locate the largest E pont & t> Locate the smallest L pont & t< E E < L for a vald lne L L L E L E E
olgon Clppng (Sutherland-Hodgman Gven an ordered sequence of polgon vertces And a conve clppng polgon Output ordered clpped polgon vertces Usng dvde-and-conquer, one clppng edge at a tme
IN OUT IN OUT IN OUT IN OUT
6 2 4 2 5 4 3 3 Orgnal Rght boundar clppng
7 7 6 6 5 8 5 2 3 4 2 3 4 Bottom boundar clppng Left boundar clppng
7 6 5 8 9 4 3 2 Top boundar clppng
Other rmtves Use of etents (etents for a whole strng, words, ndvdual characters Dvde and Conquer