Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Bresenhams circle

generation
X=
Use refection matrix 0 Y=
[-1 0; 0 1] Usex refection matrix
[0 1; 1 0]

(-, (+,
+) +)

(-,-) (+,-
y= )
Use refection
0 matrix
[1 0; 0 -1]
Circle in first quadrant
Radius 8
Start pt (0,8) 9
8
End pt. (8,0) 7
6
5
Y is Decrementing
4
3
0.8 2
X is Increasing 1
0
8.0 1 2 3 6 8
0 4 5 7
Circle in first quadrant
(xi,yi) (xi+1,yi)
m
H mH=| (xi+1)^2 + (yi)^2 -
(R)^2 |
m mD=| (xi+1)^2 + (yi-
m D 1)^2 (R)^2 |
mV=| (xi)^2 + (yi-1)^2
V (R)^2 |

(xi,yi-1) (xi+1,yi-
1)

Algorithm selects pixel which minimizes


the sq of distance between one of the 3
pixel and true circle.
Cases depends upon position of
diagonal point
i=| (xi+1)^2 + (yi-1)^2 (R)^2 |
If i <0 Then diagonal pt is inside the circle

=mH-mD
=| (xi+1)2+yi2-R2|-|(xi+1)2+
Case 2 (yi-1)2-R2|

If (<=0)
choose pt (xi+1,y1) //
horizontal pt
Case 1
Else
choose pt (xi+1,yi-1) //
diagonal pt
=mH-mD
= ((xi+1)2+yi2-R2) + ((xi+1)2+(yi-
1)2-R2)
= 2(xi+1)^2 + yi^2 + (yi-1)^2
-2R^2
= [2(xi+1)2 + (yi2-2yi+1)+ (yi-
1)2 -2R2] + 2yi-1
= [2(xi+1)2 + (yi-1)2+ (yi-1)2
-2R2] + 2yi-1
= [2(xi+1)2 + 2(yi-1)2 -2R2] +
Cases depends upon position of
diagonal point
i=| (xi+1)^2 + (yi-1)^2 (R)^2 |
If i >0 Then diagonal pt is outside the
circle
=mD-mV
=|(xi+1)2+(yi-1)2-R2|-|(xi)2+(yi-
1)2-R2|

If (<=0)
choose pt (xi+1,y1-1) //
diagonal pt
Else
choose pt (xi,yi-1)// vertical
pt
Case 4 Case 3
=mD-mV
= ((xi+1)2+(yi-1)2-R2) + ((xi)2+(yi-1)2-
R 2)
= (xi+1)2 + xi2 + 2(yi-1)2 -2R2
= [(xi+1)2 + (xi2+2xi+1)+ 2(yi-1)2
-2R2] -2xi-1
= [(xi+1)2 + (xi+1)2+ 2(yi-1)2 -2R2]
2xi-1
= [2(xi+1)2 + 2(yi-1)2 -2R2] 2xi-1
=2 * [(xi+1)2 + (yi-1)2 -R2] 2xi-1

= 2 * - 2xi-1
Cases depends upon position of
diagonal point
i=| (xi+1)^2 + (yi-1)^2 (R)^2 |
If i = 0 Then diagonal pt is on the circle

Case 5
Summary
If i <0
=mH-mD
If (<=0)
choose pt (xi+1,y1) // horizontal pt
Else
choose pt (xi+1,yi-1) // diagonal pt
Else If i >0
=mD-mV
If (<=0)
choose pt (xi+1,y1-1) // diagonal pt
Else
choose pt (xi,yi-1)// vertical pt
Else // i =0
Choose diagonal pt
Star
t
X=0, y=R; =2(1-R) ,
limit =0
Plot(x,
y)
Y<=lim yes
end
it
No
< yes H
V 0 point
point No
yes > =2+2y-
0 1
'=2-2x-
1 No <=
0
< D No yes
yes
=0 point X=x+1
No X=x+1
Y=y-1 =+2
Y=y-1
=- x+1
=+2x-2y+2
2y+1
Draw circle for radius =8
X=0, y=R; =2(1-R) , limit =0
X=0
Y=R=8
=2(1-8)=2*(-7)=-14
Limit=0

Plot(x,y)

Plot (0,8)
Y<=lim yes
end
it
No
<
0

Sr.no. Setpixel ' x y


1 (0,8) -14 0 8
Y<=lim yes
end
it
No
< yes
0
No
> =2+2y-
0 1

Sr.no. Setpixel ' x y


1 (0,8) -14 0 8
Y<=lim yes
end
it
No
< yes
0
No
> =2+2y-
0 1

Sr.no. Setpixel ' x y


1 (0,8) -14 0 8
=2*(-
14)+2*8-1
=-28+16-1
Y<=lim yes
end
it
No
< yes
0
No
> =2+2y-
0 1
X=x+1 <=
=+2 0
yes
x+1

Sr.no Setpixel ' x y


.
1 (0,8) -14 0 8
=2*(-
14)+2*8-1
=-28+16-1
=-12-1=-13
=0+1=1
=-
Plot(x,y)

Sr.no Setpixel ' x y


.
1 (0,8) -14 0 8
=- =2*(- =0+1=1
13+(2*1)+1 14)+2*8-1
=-11 =-28+16-1
=-12-1=-13
2 (1,8)
Y<=lim yes
end
it
No
<
0

Sr.no Setpixel ' x y


.
1 (0,8) -14 0 8
=- =2*(- =0+1=1
14+(2*1)+1 14)+2*8-1
=-14+3=-11 =-28+16-1
=-12-1=-13
2 (1,8)
Y<=lim yes
end
it
No
< yes
0
No
> =2+2y-
0 1

Sr.no Setpixel ' x y


.
1 (0,8) -14 0 8
=- =2*(- =0+1=1
13+(2*1)+1 14)+2*8-1
=-11 =-28+16-1
=-12-1=-13
2 (1,8)
Y<=lim yes
end
it
No
< yes
0
No
> =2+2y-
0 1
X=x+1 <=
=+2 0
yes
x+1
Sr.no Setpixel ' X y
.
1 (0,8) -14 0 8
=2*(- =0+1=1
14)+2*8-1
=-28+16-1
=-12-1=-13
=-
13+(2*1)+1
=-11
2 (1,8) =-22+16-
1=-7
Plot(x,y)

Sr.no Setpixel ' x y


.
1 (0,8) -14 0 8
=- =2*(- =0+1=1
13+(2*1)+1 14)+2*8-1
=-11 =-28+16-1
=-12-1=-13
2 (1,8)
=-26+16-
1=-9
=1+1=2
=-
Selected pixel
1) 0 8
2) 1 8 9
3) 2 8 8
4) 3 7 7
5) 4 7 6
6) 5 6 5
7) 6 5 4
8) 7 4 3
9) 7 3 2
10)8 2 1
11)8 1 0
12)8 0 0 1 2 3 4 5 6 7 8
Complete circle generation
To generate the next part, multiply
the coordinate matrix of selected
pixel by transformation matrix for
reflection through y axis and then by
transformation matrix used for
reflection through x-axis

You might also like