Important Graphics Output Primitives Graphics Output Primitives in 2D polgons, circles, ellipses & other curves piel arra operations in 3D triangles & other polgons Werner Purgathofer / Computergraphik Points and Lines point plotting instruction in displa list (random scan) entr in frame buffer (raster scan) line drawing instruction in displa list (random scan) intermediate discrete piel positions calculated (raster scan) jaggies, aliasing Lines: Staircase Effect Stairstep effect (jaggies) produced when a line is generated as a series of piel positions Werner Purgathofer / Computergraphik 2 Werner Purgathofer / Computergraphik 3 Line-Drawing Algorithms DDA Line-Drawing Algorithm line equation: = m. + b line path between two points: m = end 0 end 0 b = 0 m. 0 end 0 }b 0 end line equation: = m. + b δ = m. δ δ = δ m for m < for m > end 0 DDA (digital differential analzer) 5 sampling points 0 end for δ=, m < : k+ = k + m Werner Purgathofer / Computergraphik 4 Werner Purgathofer / Computergraphik 5
DDA Algorithm Principle d = End 0; d = End 0; m = d / d; = 0; = 0; setpiel (round(), round()); for (k = 0; k < d; k++) { += ; += m; setpiel (round(), round()} etension to other cases simple Werner Purgathofer / Computergraphik 6 Bresenham s Line Algorithm faster than simple DDA incremental integer calculations adaptable to circles, other curves 3 2 0 = m. ( k + ) + b 0 2 3 Werner Purgathofer / Computergraphik 7 Section of a displa screen where a straight line segment is to be plotted, starting from the piel at column 0 on scan line Bresenham s Line Algorithm Bresenham s Line Algorithm (/4) k+2 k+ k = m + b Section of the screen grid showing a piel in column k on scan line k that is to be plotted along the path of a line segment with slope 0<m< k+ k dupper d lower k k+ k+2 k+3 Werner Purgathofer / Computergraphik 8 k k+ Werner Purgathofer / Computergraphik 9 k+ Bresenham s Line Algorithm (/4) k d upper d lower Werner Purgathofer / Computergraphik k+ 0 = m. ( k + ) + b d lower = k = = m. ( k + ) + b k d upper = ( k + ) = = k + m. ( k + ) b d lower d upper = = 2m. ( k + ) 2 k + 2b k+ Bresenham s Line Algorithm (2/4) k d upper d lower Werner Purgathofer / Computergraphik k+ d lower d upper = = 2m. ( k + ) 2 k + 2b m = Δ/Δ (Δ= end 0, Δ = end 0 ) decision parameter: p k = Δ. (d lower d upper ) = = 2Δ. k 2Δ. k + c same sign as (d lower d upper ) 2
Bresenham s Line Algorithm (3/4) current decision value: p k = Δ. (d lower d upper ) = 2Δ. k 2Δ. k + c net decision value: p = 2Δ. k+ 2Δ. k+ k+ + c + 0 + p k 2Δ. k + 2Δ. k c = = p k + 2Δ 2Δ. ( k+ k ) starting decision value: p 0 = 2Δ Δ Werner Purgathofer / Computergraphik 2 Bresenham s Line Algorithm (4/4). store left line endpoint in ( 0, 0 ) 2. plot piel ( 0, 0 ) 3. calculate constants Δ, Δ, 2Δ, 2Δ 2Δ, and obtain p 0 =2Δ Δ 4. At each k along the line, perform test: if p k <0 then plot piel ( k +, k ); p k+ = p k + 2Δ else plot piel ( k +, k +); p k+ = p k + 2Δ 2Δ 5. perform step 4 (Δ ) times. Werner Purgathofer / Computergraphik 3 Bresenham: Eample k p k ( k+, k+ ) (20,4) 0-4 (2,4) 2 (22,42) 2-2 (23,42) 3-6 (24,42) 4 0 (25,43) 5-4 (26,43) 6-8 (27,43) 7-2 (28,43) 8 4 (29,44) 9-0 (30,44) Werner Purgathofer / Computergraphik 4 46 Δ = 0, Δ = 3 45 44 43 42 4 40 20 2 22 23 24 25 26 27 28 29 30 p 0 =2Δ Δ if p k <0 then plot piel ( k +, k ); p k+ = p k + 2Δ else plot piel ( k +, k +); p k+ = p k + 2Δ 2Δ Important Graphics Output Primitives In 2D polgons, circles, ellipses & other curves piel arra operations In 3D triangles & other polgons Werner Purgathofer / Computergraphik 5 What is Inside a Polgon? Fill-Area Primitives for polgon area (solid-color, patterned) scan-line polgon fill algorithm intersection points located and sorted consecutive pairs define interior span attention with verte intersections eploit coherence (incremental calculations) flood fill algorithm Odd Even rule Nonzero Winding Number rule??? Werner Purgathofer / Computergraphik 6 Werner Purgathofer / Computergraphik 7 3
Polgon Fill Areas polgon classifications conve: no interior angle > 80 concave: not conve splitting concave polgons vector method all vector cross products have the same sign conve rotational method rotate polgon-edges onto -ais, alwas same direction conve Werner Purgathofer / Computergraphik 8 Important Graphics Output Primitives In 2D polgons, circles, ellipses & other curves piel arra operations In 3D triangles & other polgons Werner Purgathofer / Computergraphik 9 Character Primitives Eample: Newspaper font (tpeface) design stle for (famil of) Courier, Times, Arial, serif (better readable), Sfzrn Sfzrn sans serif (better legible) definition model bitmap font (simple to define and displa), needs more space (font cache) outline font (more costl, less space, geometric transformations) Werner Purgathofer / Computergraphik 20 Werner Purgathofer / Computergraphik 2 Character Generation Eamples the letter B represented with an 88 bilevel bitmap pattern and with an outline shape defined with straight line and curve segments Werner Purgathofer / Computergraphik 22 Important Graphics Output Primitives In 2D polgons, circles, ellipses & other curves piel arra operations In 3D triangles & other polgons Werner Purgathofer / Computergraphik 23 4
Polgon Surfaces () set of surface polgons enclose object interior = Boundar Representation ( B-rep ) Polgon Surfaces (2) polgon tables (B-rep lists) geometric and attribute tables verte, edge, polgon tables consistenc, completeness checks Eample of a triangle mesh representing a dolphin. Werner Purgathofer / Computergraphik 24 Werner Purgathofer / Computergraphik 25 Polgon Surfaces: Data Structure Lists for B-Reps surface list V E E 3 E 6 S S 2 S S 2 E 2 E 4 V 2 V 3 V 4 V 5 E5 edge list E E 2 E 3 E 4 E 5 E 6 Werner Purgathofer / Computergraphik 26 verte list z V z V 2 Werner Purgathofer / Computergraphik 27 z V 3 z V 4 z V 5 Polgon Surfaces: Plane Equation plane parameters A,B,C,D normal (A,B,C) A + B + Cz + D = 0 N=(A,B,C) eample: = 0 N=(,0,0) Front and Back Polgon Faces back face = polgon side that faces into the object interior front face = polgon side that faces outward behind a polgon plane = visible to the polgon back face in front of a polgon plane = visible to the polgon front face z z Werner Purgathofer / Computergraphik 28 Werner Purgathofer / Computergraphik 29 5
Front and Back Polgon Faces A + B + Cz + D = 0 for points on the surface < 0 for points behind > 0 for points in front if () right-handed coordinate sstem (2) polgon points ordered V 4 counterclockwise V V 2 V,V 2,V 3 counterclockwise normal vector N = (V 2 -V ) (V 3 -V ) Werner Purgathofer / Computergraphik 30 V 5 V 3 N Reminder: Product of Vectors a V = b V 2 = c scalar product: a b c a 2 b 2 c 2 V V 2 = = a a 2 + b b 2 + c c 2 cross product (vector product): a b c a 2 b 2 c 2 V V 2 = = Werner Purgathofer / Computergraphik 3 a 2 b 2 c 2 b c 2 c b 2 c a 2 a c 2 a b 2 b a 2 6