Example-1
Draw a circle using Midpoint Circle Algorithm having radius as 10 and center of circle (100,100).
- Important points:
- Starting d =5/4-r but as 5/4 is approximately equal to 1 so initial d would be d=1-r.
- Plotted one pixel will generate 7 other points, because of 8 way symmetry.
The Algorithm:
S-1: Assume the coordinates of center of the circle as (h,k) and radius =r.
S-2: Find d=1-r and take x=0 & y=r as starting points.
S-3: If d >=0
- Increment x by 1 and dcrement y by 1. Calculate new d =d+2*(x-y) +5
S-4: If d <0
- Increment x by 1and keep the y unchanged, Calculate new d =d+2*(x) +3.
S-5: Stop when either x or y reaches r/squareroot(2).
S-6: All the other points would be generated by 8 way symmetry (Circle 8 way symmetr).
S-1; Enter the center h=100, k=100 and radius r=10.
S-2: Find d= 1-r , so d=1-10= -9 and take x = 0 , y = 10 (Initial Points as x=0 & y=radius)
S-3: If (d>=0) then x = x +1 and y = y -1 ; d = d + 2*(x-y) + 5;
S-4: if (d <0) then x =x +1 and d = d +2*x + 3;
Where to stop : x or y = 10/sqrt(2) which is 10/1.414= approx = 7. So either x or y reaches 7, the algorithm will stop.
Midpoint Circle Algorithm (r=10,h,k=100) | ||||
Step Number | X | Y | d | Pixel |
1 | 0 | 10 | -9 | (x +h ,y +k) = 100,110 |
2 | 1 | 10 | -9+2*1+3= – 4 | 101,110 |
3 | 2 | 10 | -4+2*2+3=3 | 102,110 |
4 | 3 | 9 | 3+2*(3-9)+5 = -4 | 103,109 |
5 | 4 | 9 | -4+2*4+3 = 7 | 104,109 |
6 | 5 | 8 | 7+2*(5-8)+5 = 6 | 105,108 |
7 | 6 | 7 | Stop | —- |
Rest of the points will be plotted using 8-Way Symmetry. There would be 6*8=48 Points would be created in total, which on joining will look like circle.
Example -2
Draw a circle using Midpoint Circle Algorithm with radius 5.
- When ever nothing is mentioned about the center of the circle, we would then assume the center of circle to be zero. Therefore value of h and k would be zero.
The Solution:
S-1; Enter the center h=0, k=0 and radius r=5.
S-2: Find d= 1-r , so d=1-5= -4 and take x = 0 , y = 5 (Initial Points as x=0 & y=radius)
S-3: If (d>=0) then x = x +1 and y = y -1 ; d = d + 2*(x-y) + 5;
S-4: if (d <0) then x =x +1 and d = d +2*x + 3;
Where to stop : x or y = 5/sqrt(2) which is 5/1.414= approx = 4. So either x or y reaches 4, the algorithm will stop.
Midpoint Circle Algorithm (r=5,h,k=0) | ||||
Step Number | X | Y | d | Pixel |
1 | 0 | 5 | 1-(5)= -4 | (x +h ,y +k) = 0,5 |
2 | 1 | 5 | -4+2*1+3= 1 | 1,5 |
3 | 2 | 4 | 1+2*(2-4)+5=2 | 2,4 |
4 | STOP |
Rest of the points will be plotted using 8-Way Symmetry. Using this circle will have 8*3 =24 Points, which on joining will look like circle.