Computer Graphics – 15. Circle Drawing – Naive Cartesian Form

[wpdm_package id=’1244′]
Sample Input –Draw a circle using the naive cartesian form of circle. The center of circle should be accepted using mouse clicks. Use 1 to 9 keyboard keys to specify the radius of circle.
Sample Output –Circle_Naive_Cartesian

[sourcecode lang=”cpp”]
void circle_using_cartesian_coordinates(int a, int b, int radius){
double x=0.0, y1=0.0, y2=0.0;
for(x=(a-radius);x<=(a+radius);x+=0.01){
double temp=sqrt(radius*radius-(x-a)*(x-a));
y1=temp+b;
y2=-temp+b;
draw_dot(x,y1);
draw_dot(x,y2);
}
}
[/sourcecode]

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

Leave a Reply

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