C++画圆算法Algorithm DrawCircle

原算法引用地址 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(); 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值