View Full Version : draw an arc in opengl
07-07-2009, 02:05 AM
I'm new to opengl .i would like to draw an arc contains center point,start angle, end angle and radius.I want to convert this arc into lines..
07-07-2009, 02:49 AM
It's easy... You just need to (end angle-start angle)/number of segments(lines).
Then you create a loop that starts from the start angle until the end angle that will increment for each segment. In that loop you just have to find the point that will draw the arc.
In the end you'll have several points that will form the arc. Draw them as GL_LINES and then translate them...
More help @here (http://www.allegro.cc/forums/thread/594175).
07-07-2009, 04:56 AM
what is num_segments .. because i'm using this code
void DrawArc(float cx, float cy, float r, float start_angle, float arc_angle, int num_segments)
float theta = arc_angle / float(num_segments - 1);//theta is now calculated from the arc angle instead, the - 1 bit comes from the fact that the arc is open
float tangetial_factor = tanf(theta);
float radial_factor = cosf(theta);
float x = r * cosf(start_angle);//we now start at the start angle
float y = r * sinf(start_angle);
glBegin(GL_LINE_STRIP);//since the arc is not a closed curve, this is a strip now
for(int ii = 0; ii < num_segments; ii++)
glVertex2f(x + cx, y + cy);
float tx = -y;
float ty = x;
x += tx * tangetial_factor;
y += ty * tangetial_factor;
x *= radial_factor;
y *= radial_factor;
07-07-2009, 06:12 AM
num_segments is the number of segments that you will use to draw your curve.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.