# Half of the circle

• 03-07-2006
hdragon
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()         {                 glLoadIdentity();                                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?
• 03-07-2006
dwks
What did you do to your function?
• 03-07-2006
hdragon
Sorry, the first one suppose to be:
Code:

`double a =  2*Pi() * (j/double(numVertices));`
• 03-08-2006
sand_man
This is a little non-related, but why do you have a function returning pi? Why not a constant?
• 03-08-2006
hdragon
Quote:

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.
• 03-08-2006
dwks
• 03-08-2006
sand_man
Quote:

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.
• 03-08-2006
Shamino
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
• 03-08-2006
VirtualAce
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.
• 03-09-2006
Shamino
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? :confused:

Sorry I don't know the answer :d
• 03-09-2006
VirtualAce
Quote:

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?
• 03-10-2006
Sang-drax
Bubba I think you misread his code. He is doing exactly that, but using () around R for some reason.
• 03-10-2006
VirtualAce
Ahh I see it now.

He is doing this:

Vect2.x*=r;
Vect2.y*=r;
• 03-10-2006
Sang-drax
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);```
• 03-10-2006
hdragon
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,...).