原算法引用地址 http://slabode.exofire.net/circle_draw.shtml
这里是用点来分割画出圆, num_segments 是点的个数 这里theta =360/num_segments
x y,分别代表新的点位的坐标
y += ty * tangetial_factor; 这步就是 求BC 因为AB长度为r r*tan( theta)
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();
}