Computer Graphics – 17 Midpoint Circle Drawing Algorithm

[wpdm_package id=’1248′]

Sample Input –Draw a circle using Midpoint Circle Drawing Algorithm. The center of circle should be accepted using mouse clicks. Use 1 to 9 keyboard keys to specify the radius of circle.

Sample Output –Midpoint_Circle_Drawing_Algorithm

[sourcecode lang=”cpp”]
void circle_using_midpoint_drawing_algorithm(int a, int b, int Radius){
int x=0, y=Radius, p=1-Radius;
while(x<=y){
draw_dot(int(a+x), int(b+y));
draw_dot(int(a+y), int(b+x));
draw_dot(int(a-y), int(b+x));
draw_dot(int(a-x), int(b+y));
draw_dot(int(a-x), int(b-y));
draw_dot(int(a-y), int(b-x));
draw_dot(int(a+y), int(b-x));
draw_dot(int(a+x), int(b-y));

if(p<0){
++x;
p=p+2*x+3;
}
else{
++x,–y;
p=p+2*x-2*y+5;
}
}
}
[/sourcecode]

To compile the above program in ubuntu terminal –
# g++ -lGL -lGLU -lglut Circle_Midpoint_Drawing.cpp
# ./a.out

Leave a Reply

Your email address will not be published. Required fields are marked *