Docsity

Computer Graphics I: Circle Drawing and Clipping Algorithms - Prof. David E. Breen, Study notes of Computer Graphics

Partial preview of the text

Download Computer Graphics I: Circle Drawing and Clipping Algorithms - Prof. David E. Breen and more Study notes Computer Graphics in PDF only on Docsity!

1

CS 430/

Computer Graphics I

Circle Drawing and Clipping

Week 3, Lecture 6

David Breen, William Regli and Maxim Peysakhov

Geometric and Intelligent Computing Laboratory

Department of Computer Science

Drexel University

http://gicl.cs.drexel.edu

2 Outline

  • Scan conversion of circles
  • Clipping circles
  • Scan conversion of ellipses

4 Scan Conversion of Circles

  • Implicit representation of the circle function:
  • Note: < 0 for points inside the circle, and > 0 for points outside the circle

5 Scan Conversion of Circles

  • Assume we finished pixel
  • What pixel to draw next? (going clockwise)
  • Note: the slope of the circular arc is between 0 and – 1 - Hence, choice is between: E and SE
  • Idea: If the circle passes above the midpoint M , then we go to E next, otherwise we go to SE 1994 Foley/VanDam/Finer/Huges/Phillips ICG

7 Case I: When E is next

  • What increment for computing a new D?
  • Next midpoint is:
  • Hence, increment by: Pics/Math courtesy of Dave Mount @ UMD-CP

8 Case II: When SE is next

  • What increment for computing a new D?
  • Next midpoint is:
  • Hence, increment by: Pics/Math courtesy of Dave Mount @ UMD-CP

10 Scan Conversion of Circles

  • Converting this to an integer algorithm:
    • Need only know if D is positive or negative
    • D & R are integers
    • Note D is incremented by an integer value
    • Therefore D + 1/4 is positive only when D is positive; it is safe to drop the 1/
  • Hence: set the initial D to 1 – R (subtracting 1/4 )

11 Circle Scan Conversion Algorithm

  • Given radius R and center (0, 0)
    • First point  (0, R)
  • Initial decision parameter D = 1- R
  • While x ≤ y
    • If (D < 0)
      • x++; D += 2x + 3;
    • else
      • x++; y--; D += 2(x - y) + 5
    • WritePoints(x,y)

13 Clipping Circles

  • Accept/Reject test
    • Does bounding box of

the circle intersect with

clipping box?

  • If yes, condition pixel write on clipping box inside/outside test

14 Properties of Ellipses

  • “Elongated circle”
  • For all points on ellipse, sum of distances to foci is constant d 1 + d 2 = const
  • If F 1 =(x 1 , y 1 ) and F 2 =(x 2 , y 2 ) then y x d 1 d 2 P=(x,y) F 1 F 2 ( x " x 1 ) 2
  • ( y " y 1 ) 2
  • ( x " x 2 ) 2
  • ( y " y 2 ) 2 = const

16 Symmetry Considerations

  • 4-way symmetry
  • Unit steps in x until reach

region boundary

  • Switch to unit steps in y (x,y) ry rx (x,-y) (-x,y) (-x,-y) Region 1 Region 2 Slope = -
  • Step in x while
  • Switch to steps in y when ! f ( x , y ) = ry 2 x 2
  • rx 2 y 2 " rx 2 ry 2 dy dx = " ry 2 x rx 2 y dy dx = " 1 r y 2 x = r x 2 y ! r y 2 x < r x 2 y r y 2 x " r x 2 y

17 Midpoint Algorithm (initializing)

  • Similar to circles
  • The initial value for region 1
  • The initial value for region 2
  • We have initial values, now we need the increments 1994 Foley/VanDam/Finer/Huges/Phillips ICG (x,y) r y Region 1 Region 2 Slope = - ! D init 1 = f ( 1 , r y " 1 2 ) = r y 2 " r x 2 r y

1 4 r x 2 ! D init 2 = f ( x p

1 2 , y p " 1 ) = r y 2 ( x p

1 2 ) 2

  • r x 2 ( y p " 1 ) 2 " r x 2 r y 2

19 Computing the Increment 1994 Foley/VanDam/Finer/Huges/Phillips ICG Dnew = f ( xp + 2 , yp " 1 2

= ry 2 ( xp + 2) 2

  • rx 2 ( yp " 1 2

2 " rx 2 ry 2 = Dold + ry 2 ( 2 xp + 3 ) Dnew = f ( xp + 2 , yp " 3 2

= ry 2 ( xp + 2 ) 2

  • rx 2 ( yp " 3 2

2 " rx 2 ry 2 = Dold + ry 2 ( 2 xp + 3 ) + rx 2 (" 2 yp + 2) increment = ry 2 (2 xp + 3 ) Dold < 0 ry 2 (2 xp + 3 ) + rx 2 (" 2 yp + 2 ) Dold # 0

E case

SE case

21 Computing the Increment in 2 nd Region

  • Decision variable in 2 nd

region

  • If then M is left of the arc,

hence the SE pixel is closer to the line.

  • If then M is right of the arc,

hence the S pixel is closer to the line.

1994 Foley/VanDam/Finer/Huges/Phillips ICG ! D = f ( x p

1 2 , y p " 1 ) = r y 2 ( x p

1 2 ) 2

  • r x 2 ( y p " 1 ) 2 " r x 2 r y 2