如何使用x,y位置,半径,起始角度和结束角度在opengl中绘制圆弧。 [英] How to draw arc in opengl using x, y position, radius, start angle and end angle.
问题描述
使用OpenGL中的x,y位置,半径,起始角度和结束角度绘制弧线
x(中心x圆圈的位置)
y(圆圈的中心y位置)
r(半径)
Start_Angle(定义开始的角度(从圆心开始)>
弧的位置。)
End_Angle(角度(从圆心开始引用),定义弧的末端
位置。)
我尝试了什么:
我试过这个.. 。
Draw an arc using x,y position, Radius, Start Angle and End Angle in OpenGL
x (center x position of the circle)
y (center y position of the circle)
r (Radius)
Start_Angle (The angle (referenced from the center of the circle) that defines the start
position of the arc.)
End_Angle (The angle (referenced from the center of the circle) that defines the end
position of the arc.)
What I have tried:
I have tried this...
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;
}
glEnd();
}
但不满足我的要求。
but its not satisfying my requirement.
推荐答案
参见绘制弧形操作 - Google搜索 [ ^ ]。
GL.Begin(PrimitiveType.LineStrip) ;
double x = 2.047;
double y = 3.5;
double r = .5;
double start_angle = 1.5;
double end_angle = 3.2;
double max_angle = 2 * Math.PI;
double angle_increment = Math.PI / 1000 ;
for(double theta = start_angle; theta< end_angle; theta + = angle_increment)
{
x = r * Math.Cos(theta);
y = r * Math.Sin(theta);
GL.Vertex2(x,y);
}
GL.End();
******************* ************************************************** **********
可画弧形,但形状呈椭圆形。请帮助画一个合适的弧。
GL.Begin(PrimitiveType.LineStrip);
double x = 2.047;
double y = 3.5;
double r = .5;
double start_angle = 1.5;
double end_angle = 3.2;
double max_angle = 2 * Math.PI;
double angle_increment = Math.PI / 1000;
for (double theta = start_angle; theta < end_angle; theta += angle_increment)
{
x = r * Math.Cos (theta);
y = r * Math.Sin (theta);
GL.Vertex2(x, y);
}
GL.End();
*******************************************************************************
Could draw the arc, but became oval in shape. please help to draw a proper arc.
你的解决方案不符合你的要求。
Your solution don't respect your requirements.
x(中心x圈的位置)
y(圆圈的中心y位置)
x (center x position of the circle)
y (center y position of the circle)
您需要进行以下更改:
You need to make changes like that:
GL.Begin(PrimitiveType.LineStrip);
double x = 2.047;
double y = 3.5;
double r = .5;
double start_angle = 1.5;
double end_angle = 3.2;
double max_angle = 2 * Math.PI;
double angle_increment = Math.PI / 1000;
for (double theta = start_angle; theta < end_angle; theta += angle_increment)
{
//x = r * Math.Cos (theta);
//y = r * Math.Sin (theta);
GL.Vertex2(x+ r * Math.Cos (theta), y+ r * Math.Sin (theta));
}
GL.End();
这篇关于如何使用x,y位置,半径,起始角度和结束角度在opengl中绘制圆弧。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!