0% found this document useful (0 votes)
51 views8 pages

Circle, Ellipse, Fill Algo's

The document describes several computer graphics algorithms: 1) Circle algorithm uses a midpoint circle algorithm to plot pixels on a circle by calculating the change in a decision parameter at each step. 2) Ellipse algorithm similarly uses a decision parameter to plot pixels on an ellipse by calculating the change in the parameter at each step in two regions. 3) Boundary fill algorithm fills in a region enclosed by a boundary by recursively calling itself on neighboring pixels of the same color as the boundary. It can fill 4-connected or 8-connected regions. 4) Flood fill algorithm fills a region by recursively calling itself on neighboring pixels of the same color as the initially selected pixel.

Uploaded by

Sagar Aryan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views8 pages

Circle, Ellipse, Fill Algo's

The document describes several computer graphics algorithms: 1) Circle algorithm uses a midpoint circle algorithm to plot pixels on a circle by calculating the change in a decision parameter at each step. 2) Ellipse algorithm similarly uses a decision parameter to plot pixels on an ellipse by calculating the change in the parameter at each step in two regions. 3) Boundary fill algorithm fills in a region enclosed by a boundary by recursively calling itself on neighboring pixels of the same color as the boundary. It can fill 4-connected or 8-connected regions. 4) Flood fill algorithm fills a region by recursively calling itself on neighboring pixels of the same color as the initially selected pixel.

Uploaded by

Sagar Aryan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

CIRCLE ALGO

Circle Equation F(xk,yk)=xk2+yk2-r2 Mid point equation for (xk+1,yk-1/2) Desired position p=f(xk+1,yk-1/2)= (xk+1)2+( yk-1/2)2-r2 pold= f(xk+1,yk-1/2)= (xk+1)2+( yk-1/2)2-r2

We will get two cases based on pold value If pold < 0 case 1 for upper pixel If pold >0 case 2 for lower pixel

Case1 for upper pixel Pnew=F(xk+2,yk-1/2)=( xk+2)2+ (yk-1/2)2-r2


P u=pnew-pold=((xk+2)2+( yk-1/2)2-r2)-(( xk+1)2+ (yk-1/2)2-r2)= 2xk+3

Case2 for lower pixel Pnew=F(xk+2,yk-3/2)=( xk+2)2+ (yk-3/2)2-r2


P l=pnew-pold=( xk+2)2+ (yk-3/2)2-r2-(( xk+1)2+ (yk-1/2)2-r2)= 2xk-2yk+5

Starting p value P=f(x0+1,y0-1/2)= (x0+1)2+( y0-1/2)2-r2=f(x0,y0)+1/4-r=1-r

Algorithm Step1:input radius r and (x,y)=(0,r) Step2: initial value of the decision parameter as P=1-r Step3: while(x<y) If(p<0) P=p+2xk+3; Else P=p+2xk-2yk+5; y--; endif; x++; plotpixe(x,y); end while; step 4:exit;

Example: R=10; X=0,y=10; p -9 -6 -1 6 -3 8 5

X,y (1,10) (2,10) (3,10) (4,9) (5,9) (6,8) (7,7)

Ellipse Algorithm Step1: input radios Rx and Ry and (0,Ry) Step2:initial p1 value P1=Ry2-Rx2Ry+(1/4)Rx2 for region 1 Step3:While(2Rx2y>2Ry2 x) If(p<0) P=p+2Ry2x+3Ry2; Else P=P+2Rx2y-2Rx2+Ry2; y++; endif; x++;plotpixel(x,y); end while; step4: find initial value p2 for region 2 P2=Ry2(x0+1/2)2+Rx2(y0-1)2-Ry2Rx2 While(y>0) If(p2>0) p2=p2-2Rx2y+3Rx2; Else p2=p2+2Ry2x+2Ry2-2Rx2y+3Rx2 ,x++;

endif; Y--; plot pixel(x,y); End while; Step 5: exit;

Example
Rx= and Ry= 8 6 P1= y2-Rx2Ry+ R (1/4)Rx2= -332
p -332 -224 -44 208 -108 288 244 (X,Y) (1,6 ) (2,6 ) (3,6 ) (4,5 ) (5,5 ) (6,4 ) (7,3 )

7 6 5 4 3 2 1 0 2ry2x 72 144 216 288 360 432 504 1 2 3 4 5 6 7 8

2 x2y r 7 68 7 68 7 68 6 40 6 40 5 12 3 84

2 P 2= R2(x0+1 /2)+ Rx2(y0-1)2-Ry2Rx2 y W hile(y >0 ) If(p2>0) Left p2= p 22 Rx2y+3R2; x E lse R ig ht 2 p2= p 2+2Rx+ 2R2-2Rx2y+3R2 y y x x++ ; en dif;y-; ; p lo t p ixel( x,y);

7 6 5 4 3 2 1 0 1 2 2rx2y 256 128 3 4 5 6 7 8

p -151 233 745

X,y (8,2) (8,1) (8,0)

2ry2x 576 576 -

Boundary Fill algorithm In many graphics packages the user can fill a region (defined by a boundary). In the figure, the boundary is red and the filling color is blue

The fill method can be applied to a 4-connected area or an 8connected area

The following pseudo-code fills a 4-connected area: boundaryFill(x, y, fill, boundary) { }

current = getPixel(x, y) If (current != boundary) and (current != fill) { setPixel(x, y, fill) boundaryFill(x+1, y, fill, boundary) boundaryFill(x , y+1, fill, boundary) boundaryFill(x-1, y, fill, boundary) boundaryFill(x , y-1, fill, boundary)

The following pseudo-code fills a 8-connected area: boundaryFill(x, y, fill, boundary) { current = getPixel(x, y) If (current != boundary) and (current != fill) { setPixel(x, y, fill)

boundaryFill(x+1, y, fill, boundary) boundaryFill(x , y+1, fill, boundary) boundaryFill(x-1, y, fill, boundary) boundaryFill(x , y-1, fill, boundary)

boundaryFill(x+1, y+1, fill, boundary) boundaryFill(x+1 , y-1, fill, boundary) boundaryFill(x-1, y+1, fill, boundary) boundaryFill(x -1, y-1, fill, boundary)

Flood fill algo


Flodfill(x,y,fill,old){ if(getpixel(x,y)==old) { Setcolor(fill); setpixel(x,y); Flodfill(x+1,y,fill,old) Flodfill(x-1,y,fill,old) Flodfill(x,y+1,fill,old) Flodfill(x,y-1,fill,old) }

You might also like