drawing algorithms
play

Drawing Algorithms Rasterization Pixelization Scan Conversion - PowerPoint PPT Presentation

Drawing Algorithms Rasterization Pixelization Scan Conversion Continuous Discrete Line Drawing Algorithms Line Equation: (x 2 ,y 2 ) y mx B = + - dy y y y 2 1 m = = = y - dx x x x 2 1 (x 1 ,y 1 ) x DDA


  1. Drawing Algorithms Rasterization Pixelization Scan Conversion Continuous Discrete

  2. Line Drawing Algorithms Line Equation: (x 2 ,y 2 ) y mx B = + - dy y y y Δ 2 1 m = = = Δ y - dx x x x Δ 2 1 (x 1 ,y 1 ) Δ x DDA (Digital Differential Analyzer)

  3. Line Drawing Algorithms DDA (Digital Differential Analyzer) (x 2 ,y 2 ) y mx B = + i i y mx B = + i 1 i 1 Δ y + + y m ( x x ) B = + Δ + i 1 i + (x 1 ,y 1 ) Δ x

  4. Line Drawing Algorithms DDA (Digital Differential Analyzer) (x 2 ,y 2 ) if x 1 Δ = x x 1 = + i 1 i + Δ y y y m = + i 1 i + (x 1 ,y 1 ) Δ x

  5. Line Drawing Algorithms DDA (Digital Differential Analyzer) y = y 1 for ( x = x 1 ; x ≤ x 2 ; x ++ ) { Writepixel ( x , round ( y )); y + = m ; (x i , round(y i ) ) }

  6. Line Drawing Algorithms DDA (Digital Differential Analyzer) m <= 1 m > 1 Exchange the role of x and y

  7. Line Drawing Algorithms Midpoint Line Algorithm NE Line Find on what side of the line the mid point is: M above E If below then below NE is closer to line If above then E is closer to line

  8. Midpoint Line Algorithm M ’’ Line NE M ’ M E P(x p ,y p ) F(x, y) = 0 : (x, y) on line F(x, y) > 0 : (x, y) below line F(x, y) < 0 : (x, y) above line

  9. Midpoint Line Algorithm M ’’ Line NE Let 0 m 1 M ’ <= <= < M Consider line dy E P(x p ,y p ) y x B = + dx F ( x , y ) ax by c 0 = + + = - xdy ydx Bdx 0 + = - (a dy, b dx, c Bdx) = = =

  10. Midpoint Line Algorithm M ’’ Line NE M ’ M 1 F ( M ) F ( x 1 , y ) d = + + = p p E P(x p ,y p ) 2 1 d a ( x 1 ) b ( y ) c = + + + + p p 2 if d > 0 M is below the line, choose NE if d 0 M is above the line, choose E <

  11. Midpoint Line Algorithm M ’’ NE Line M ’ M When E : E P(x p ,y p ) 1 d F ( M ' ) F ( x 2 , y ) = = + + new p p 2 1 d a ( x 2 ) b ( y ) c = + + + + new p p 2 1 d a ( x 1 ) b ( y ) c = + + + + old p p 2 d - d a dy = = = Δ new old E

  12. Midpoint Line Algorithm M ’’ NE Line M ’ M When NE : E P(x p ,y p ) 3 d F ( M ' ' ) F ( x 2 , y ) = = + + new p p 2 3 d a ( x 2 ) b ( y ) c = + + + + new p p 2 1 d a ( x 1 ) b ( y ) c = + + + + old p p 2 d - d a b dy - dx = = + = Δ new old NE

  13. Midpoint Line Algorithm At start : 1 1 d F ( x 1 , y ) a ( x 1 ) b ( y ) c = + + = + + + + start 0 0 0 0 2 2 b d ax by c a = + + + + start 0 0 2 b dx d a = dy - (division) = + start 2 2 F ( x , y ) 2 ( ax by c ) = + +

  14. Midpoint Line Algorithm dx = x2 - x1; dy = y2 - y1; d = 2dy - dx; E = 2dy; NE = 2(dy - dx); Δ Δ x = x1; y = y1; Writepixel (x, y); While (x < x2) if d 0 ≤ d+ = E; x+ = 1; Δ else d+ = N E; x+ = 1; y+ = 1; Δ end Writepixel (x, y); end While

  15. Midpoint Circle Algorithm (x,y) 2 2 2 x y R + =

  16. Midpoint Circle Algorithm (x,y) 2 2 2 x y R + =

  17. Midpoint Circle Algorithm (x,y)

  18. Midpoint Circle Algorithm (-x,y) (x,y) (-y,x) (y,x) 8-way symmetry: drawing in one octant (-y,-x) (y,-x) is enough (x,-y) (-x,-y)

  19. Midpoint Circle Algorithm Consider II octant F ( x , y ) x 2 y 2 - R 2 = + P(x p , y p ) E For a given point (x, y) M ’ M F(x, y) = 0 : (x, y) on circle SE M ’’ F(x, y) > 0 : (x, y) outside circle F(x, y) < 0 : (x, y) inside circle

  20. Midpoint Circle Algorithm Consider II octant P(x p , y p ) E Evaluate F(M) If < 0 (M inside circle) M ’ M Choose E → SE If > 0 (M outside circle) M ’’ Choose SE →

  21. Midpoint Circle Algorithm Consider II octant 1 d F ( M ) F ( x 1 , y ) = = + − old p p 2 P(x p , y p ) E 1 2 2 2 ( x 1 ) ( y ) R = + + − − p p 2 M ’ M When E (d 0 ) < old 1 SE d F ( M ' ) F ( x 2 , y ) M ’’ = = + − new p p 2 1 2 2 2 ( x 2 ) ( y ) R = + + − − p p 2 d d 2 x 3 = − = + Δ new old p E

  22. Midpoint Circle Algorithm Consider II octant P(x p , y p ) E When SE (d 0 ) ≥ old 3 d F ( M ' ' ) F ( x 2 , y ) M ’ = = + − M new p p 2 3 2 2 2 ( x 2 ) ( y ) R SE = + + − − M ’’ p p 2 d d 2 x 2 y 5 = − = − + Δ new old p p SE

  23. Midpoint Circle Algorithm Consider II octant P(x p , y p ) E Initial Condition (0, R) start point, M ’ M 1 next mid point = (1, R - ) 2 SE M ’’ 1 5 F ( 1 , R ) R − = − 2 4

  24. Midpoint Circle Algorithm Consider II octant 5 x = 0; y = R; d = - R; 4 Writepixel (x, y); While (y > x) do if d 0 < d+ = 2x + 3; x+ = 1; else d+ = 2x - 2y + 5; x+ = 1; y- = 1; end Writepixel (x, y); end While

  25. Ellipse Drawing Algorithm 2 2 x y E + = 1 2 2 a b SE SE S

Recommend


More recommend