Page 1 of 24 Basic Raster Graphics Algorithms for Drawing 2D Primitives (ch 3) • Idea is to approximate mathematical “ideal” primitives, described in Cartesian space, by sets of pixels on a raster display (bitmap in memory or framebuffer) • Fundamental algorithms for scan converting primitives to pixels, and clipping them • Many algorithms were initially designed for plotters • Can be implemented in hardware, software and firmware • Primitives: • lines • circles, arcs, ellipses • region filling • clipping • alphanumeric symbols - text • lines, circles, character generators (bitmaps), fonts • Want efficiency & speed (often drawing many primitives)
24
Embed
Basic Raster Graphics Algorithms for Drawing 2D · PDF fileBasic Raster Graphics Algorithms for ... large gaps as x approaches R (the slope approaches infinity) • can avoid the gaps
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
• Idea is to approximate mathematical “ideal”primitives, described in Cartesian space, by sets ofpixels on a raster display (bitmap in memory orframebuffer)
• Fundamental algorithms for scan convertingprimitives to pixels, and clipping them
• Many algorithms were initially designed for plotters• Can be implemented in hardware, software and
firmware• Primitives:
• lines• circles, arcs, ellipses• region filling• clipping• alphanumeric symbols - text
• lines, circles, character generators(bitmaps), fonts
• Endpoint order, want P0 to P1 to look exactly thesame as P1 to P0.
NE P P E W SW
• Starting at edge of clip rectangle, must knowerror at clip point (must know error or line willbe altered if assumed to be starting point)
Page 12 of 24
Additional Issues (continued)
• Varying the intensity of a line as function ofslope, solutions include varying intensity orantialiasing (assuming line has area)
• Output primitives composed of lines, scanconvert boundaries, beware of duplicateendpoints (if xoring especially), fill algorithms tocome.
Page 13 of 24
Scan Converting Circles
• equation of a circle centered at (0,0) isx2 + y2 = R2 (R is the radius)
• explicit scan conversion y = f(x) y R x= ± −2 2
• to draw ¼ of a circle: x = 0 to R, y R x= −2 2
• BUT it’s inefficient because of ( & 2 ), also createslarge gaps as x approaches R (the slope approachesinfinity)
• can avoid the gaps by plotting Rcosθθ or Rsinθθ, θθ = 0 to90 degrees, but still fairly inefficient
Page 14 of 24
• eight way symmetry: if you have (x,y) you can(generally) compute 7 more points trivially (just 4 intotal for x=y), therefore need only compute one 45degree segment.
Page 15 of 24
Midpoint Circle Algorithm (Bresenham)
• same idea as midpoint line strategy• increment around 45o segment, x = 0 to x =
y = R/ 2 (then use 8-way symmetry)
• Let, F(x,y) = x2 + y2 - R2
= 0 when on circle> 0 when outside circle< 0 when inside circle
Page 16 of 24
• So, if midpoint M is outside the circle pick SE, ifinside pick E, else either (be consistent, say SE)