角度离散法画画弧和椭圆

角度离散法可以利用已有的直线算法来分段绘制圆弧、椭圆弧。这种方法的优点在于可以自由控制所绘制的弧的角度范围。
摘要由CSDN通过智能技术生成

角度离散法可以利用已有的直线算法来分段绘制圆弧、椭圆弧。这种方法的优点在于可以自由控制所绘制的弧的角度范围。

在这里插入图片描述
完整代码:

#include<GL/glut.h>
#include<windows.h>
#include<math.h>
void Arcellipse(int xc, int yc, double r, double ts, double te)
{
   
 double pi = 3.1415926;
 if (te < ts)  //当终止角比起始角还小时,则将终止角加上2π
  te += 2 * pi;
 double dt = 0.4 / r; //取角度离散值,使其与半径r成反比
 int n = (int)((te - ts) / dt + 0.5); //确定总步数
 double ta = ts;
 int x = xc + int(r*cos(ts));
 int y = yc + int(r*sin(ts));
 glBegin(GL_LINE_STRIP); //如果绘制整圆,选GL_LINE_LOOP更好
 glVertex2f(x, y);
 for (int i = 1; i <= n; i++)
 {
   
  ta += i * dt;
  double cost = cos(ta);
  double sint = sin(ta);
  x = int(xc + r * cost);
  y = int(yc + r * sint);
  glVertex2f(x, y);
 }
 glEnd();
}
void ChangeSize(GLsizei w, GLsizei h)
{
   
 if (h == 0)     h = 1;
 // 设置视区尺寸
 glViewport(0, 0, w, h);
 // 重置坐标系统
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 // 建立修剪空间的范围
 if (w <= h)
  glOrtho(0.0f, 250.0f, 0.0f, 250.0f*h / w, 1.0, -1.0);
 else
  glOrtho(0.0f, 250.0f*w / h, 0.0f, 
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值