Reputation: 49
I want to draw an arc with opengl. The arc should start from an specific point and ends at a given point. Given are radius, centre of the arc and arc length, start angle and end angle. I have tried following function:
for (double theta = start_angle1; theta < end_angle1; theta += angle_increment)
{
glVertex2f((arcCenX+ r * sinf(theta)),(arcCenY+ r * cosf(theta)));
}
This functions gives arc properly, but starting point of arc is different. How to specify a starting point of an arc?
Edit: I also have tried this
for ( angleIndex = 0; angleIndex < arc_len; angleIndex = angleIndex+arcSegmentIndex )
{
glVertex2f((x + ( cosf( start_angle1 + angleIndex ) )* r),
(y + ( sinf( start_angle1 + angleIndex ) )* r));
}
But it also not working.
Upvotes: 1
Views: 1495
Reputation: 480
It should be
glVertex2f((arcCenX+ r * cosf(theta)),(arcCenY+ r * sinf(theta)));
Its bascially the parametric equation of the circle so
x = r cos(0)
y = r sin(0)
where "r" is the radius of the circle. You have your x and y coordinates swapped maybe that's what's causing the problem.
Edit:- to clear it up, the starting point of the arc depends on the first theta value you put in. so if for example the first value that goes into theta is 90 degrees then the arc starts directly above the center of the circle at a distance r.
Upvotes: 1