puting the characters in their right positions!

I am trying to write a program in order to draw a filled circle with asterisk.
I have written the code in c++ with a for loop.
cin >> r;
for(x=-r ; x<=r ; x++)
{ double ypos =sqrt(pow(r,2.0)-pow(x,2.0));
ypos = floor(ypos); //position of y points
for(y=-ypos ; y <=ypos ; y++)
{
//cout<<"x "<<x<<" y "<<y<<endl; //it checks all needed y for each x
cout<<"*";
}
cout<< endl;
// break;
}
It doesn't take the exact shape of circle.
actually it will put the columns of y for each +x and -x beside each other.
It means that it is settling each columns of y corresponds to a positive and negative x next to each other which it is sorting them form the greatest x in the equation x^2+y^2=r^2 from right to letf of the screen.
it is an example that can be got by radius 4
*
*****
*******
*******
*********
*******
*******
*****
*
How is it possible to put each column in the right position for making a circle?
(this is the result that I got from my check procedure and it shows each column is right but it is not shown in the right place:
x -4 y -0

x -3 y -2
x -3 y -1
x -3 y 0
x -3 y 1
x -3 y 2

x -2 y -3
x -2 y -2
x -2 y -1
x -2 y 0
x -2 y 1
x -2 y 2
x -2 y 3

x -1 y -3
x -1 y -2
x -1 y -1
x -1 y 0
x -1 y 1
x -1 y 2
x -1 y 3

x 0 y -4
x 0 y -3
x 0 y -2
x 0 y -1
x 0 y 0
x 0 y 1
x 0 y 2
x 0 y 3
x 0 y 4

x 1 y -3
x 1 y -2
x 1 y -1
x 1 y 0
x 1 y 1
x 1 y 2
x 1 y 3

x 2 y -3
x 2 y -2
x 2 y -1
x 2 y 0
x 2 y 1
x 2 y 2
x 2 y 3

x 3 y -2
x 3 y -1
x 3 y 0
x 3 y 1
x 3 y 2

x 4 y -0
)
Last edited on
You can only fill lines char by char. If you need
   *
then you have to print three ' 's and one '*'. You need r-ypos spaces before each line, I think.
Last edited on
First of all thank for any reply.
I have figured this problem out. in the previous code I had written the algorithm in a way that it checks the column and just find all the value that should be plot for each x,y combination. but I have written it again in this form that it checks each row for any value of x for each y and it starts to plot the figure from the upper leftmost point of the space!
Topic archived. No new replies allowed.