Reputation: 11
How can I draw a half circle in OpenGl? I have tried this :
float step=5.0;
glBegin(GL_LINE_STRIP);
for(float angle=0.0f; angle <= 360; angle+=step)
{
float rad = 2*angle/180;
x = radius*sin(rad);
y = radius*cos(rad);
glVertex3f(x,y,0.0f);
}
glEnd();
but I obtained a half circle that is not on a straight line..it is inclined.How can i resolve this?
Upvotes: 1
Views: 5226
Reputation: 43319
Your question is hard to understand, particularly the last part.
If I understand correctly, what you are trying to say is that you are drawing something like this:
(source: mathopenref.com)
But what you want is this:
(source: js at abyss.uoregon.edu)
The reason for this is that you are using a line strip, which connects each line segment but does not create a segment that loops back to the first point. Use GL_LINE_LOOP
instead, and you will have a half-circle that is "on a straight line."
Upvotes: 3
Reputation: 36
those 2 functions draw 2 half circles, 1 is full and another is hollow.(in c++)
void drawLeftCircle() // the filled one
{
float radius = 70;
float twoPI = 2 * PI;
glBegin(GL_TRIANGLE_FAN);
for (float i = PI; i <= twoPI; i += 0.001)
glVertex2f((sin(i)*radius), (cos(i)*radius));
glEnd();
glFlush();
}
void drawRightHalfCircle() // the empty one
{
float radius = 70;
float twoPI = 2 * PI;
glBegin(GL_POINTS);
for (float i = 0.0; i <= twoPI / 2; i += 0.001)
glVertex2f((sin(i)*radius), (cos(i)*radius));
glEnd();
glFlush();
}
Upvotes: 0
Reputation: 3172
Your conversion fro degrees to radians is wrong, you have to multiply your degree value by PI/180 to get the correct value. And to obtain a "up facing" circle, swap your usage of sin and cos functions.
Upvotes: 1