# Thread: Half of the circle

1. ## Half of the circle

So i ran into a problem with circle. I could draw a whole circle easily, but when i tried half of the circle, it doesn't go in the way i wanted.

in my draw circle function, i set the vectors' coordinate base on the information of the class. Then use "gl triangle fan" to draw the circle:
Code:
vect2* BuildBar()
{
//Pi() is the function return Pi's value
Vertices = new vect2[numVertices+2];
for(int j=0; j<numVertices+2; j++)
{
double a =  2*Pi() * (j/double(numVertices));
Vertices[j] = vect2(cos(a), sin(a)) * (R); //R is the radius
}
return Vertices;
}
void Render()
{

glTranslatef(Pos.x, Pos.y, 0);
glBegin(GL_TRIANGLE_FAN);
for(int j=0; j<numVertices+2; j++)
{
glVertex2d(Vertices[j].x, Vertices[j].y);
}
glEnd();

}
and this is how it looks like:
http://www.albumtown.com/data/953ecc...66_p935793.gif

But my intention is just only part of the circle. I was trying to get something like this:
http://www.albumtown.com/data/953ecc...66_p935796.gif

so i change my build function and tried to get that half circle:
Code:
vect2* BuildBar()
{
/**/
Vertices = new vect2[numVertices+2];
for(int j=0; j<numVertices+2; j++)
{
double a =  Pi()/1.5 * (j/double(numVertices));
Vertices[j] = vect2(cos(a), sin(a)) * (R);
}
return Vertices;
}
and i get this:
http://www.albumtown.com/data/953ecc...66_p935794.gif

No matter what way i rotate, the whole thing just won't stay straight like the second picture. So, what should i set for the sin() and cos() in order to straight up the circle like the second picture?

2. What did you do to your function?

3. Sorry, the first one suppose to be:
Code:
double a =  2*Pi() * (j/double(numVertices));

4. This is a little non-related, but why do you have a function returning pi? Why not a constant?

5. Originally Posted by sand_man
This is a little non-related, but why do you have a function returning pi? Why not a constant?
Well, either way i still need a Pi value. It doesn't matter that Pi is a function or constant, as long as there is a value lol.

6. Originally Posted by hdragon
Well, either way i still need a Pi value. It doesn't matter that Pi is a function or constant, as long as there is a value lol.
Yeah I understand but a function is just an unneeded slowdown.

7. True, there may be no difference, but the point remains..

Using a function there is just plain silly!

Just do this

#Define PI = 3.14############....

Simple as that :d

8. Calling a function necessitates stack overhead that a common variable does not have. Therefore calling a function to do what a simple variable can accomplish is wasteful.

9. Either way, no one has still answered his question, which I believe is a bit more important that the tiny bit of overhead he is getting from the function call, or is it just me?

Sorry I don't know the answer :d

10. Vertices[j] = vect2(cos(a), sin(a)) * (R); //R is the radius

A circle is (r cos(a),r sin(a))

Why are you only using the cosine for X and not factoring in the radius?

11. Bubba I think you misread his code. He is doing exactly that, but using () around R for some reason.

12. Ahh I see it now.

He is doing this:

Vect2.x*=r;
Vect2.y*=r;

13. By the way, your result isn't strange at all if you consider that the axes aren't oriented the same way on a computer as they are in your math book. This should work:
Code:
double a =  -0.5*Pi() * (j/double(numVertices));
Vertices[j] = vect2(cos(a), sin(a)) * (R);

14. Hey sang-drax, your code works fine but it still doesn't give me the half circle with the curve straight up. Anyways, thank you all though. I figured instead using the sin() and cos() to draw part of the circle, i'm gonna define the coordinates manually. Then, i would draw a square box and put texture on. Therefore, i will have a physical, and renderable object work at the same time. The renderable object will look better since it doesn't have to worry about other stuff (collision,...).