70 likes | 183 Views
This lecture delves into the mathematical foundations of drawing circles in computer graphics, focusing on the Midpoint Circle Algorithm. It covers parametric equations for circles, decision functions, and circular symmetry. Key concepts include plotting pixels efficiently based on the geometric properties of circles, evaluating whether a pixel falls inside, on, or outside the circle using incremental calculations. The methodology outlined is essential for computer graphics programming, ensuring smooth rendering of circular shapes.
E N D
CS U540Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 6 – January 15, 2009
(x, y) Drawing Circles - 1 x = Rcos() y = Rsin() for = 0 to 360 do x = Rcos() y = Rsin() draw(x, y) R (0, 0)
(x, y) Drawing Circles 2 x2 + y2 = R2 forx = -R to R do y = sqrt(R2 - x2) draw(x, y) draw(x, -y) R (0, 0)
(-x, y) (x, y) (-y, x) (y, x) (-y, -x) (y, -x) (-x, -y) (x, -y) Circular Symmetry (0, 0)
Midpoint Circle Algorithm IN THE TOP OCTANT: If (x, y) was the last pixel plotted, either (x + 1, y) or (x + 1, y - 1) will be the next pixel. Making a Decision Function: d(x, y) = x2 + y2 – R2 d(x, y) < 0 (x, y) is inside the circle. If d(x, y) = 0 (x, y) is on the circle. d(x, y) > 0 (x, y) is outside the circle.
Decision Function Evaluate d at the midpoint of the two possible pixels. d(x + 1, y - ½) = (x + 1)2 + (y - ½)2 – R2 d(x + 1, y - ½)< 0 midpoint inside circle choose y If d(x + 1, y - ½)= 0 midpoint on circle choose y d(x + 1, y - ½)> 0 midpoint outside circle choose y - 1
Computing D(x,y) Incrementally D(x, y) = d(x + 1, y - ½) = (x + 1)2 + (y - ½)2 – R2 D(x + 1, y) – D(x, y)= (x+2)2 + (y - ½)2 – R2 – ((x + 1)2 + (y - ½)2 – R2) =2(x + 1)+ 1 integer D(x + 1, y - 1) – D(x, y)= (x+2)2 + (y – 3/2)2 – R2 – ((x + 1)2 + (y - ½)2 – R2) =2(x+1) + 1 – 2(y – 1) integer D(0, R) = 5/4 – R but we can round to 1 – R without changing any decisions. integer You can also compute the differences incrementally.