角度离散法绘制圆弧 | 椭圆
来源:互联网 发布:腾讯网络电视 编辑:程序博客网 时间:2024/05/22 15:37
</pre><pre name="code" class="cpp">
#include<GL/glut.h> //绘制圆弧程序#include<stdio.h>#include<math.h>double pi=3.1415936;int x,y;double r,as,ae;void arc(int x,int y,double r,double as,double ae){if(ae<as)ae+=2*pi;double dt=0.4/r;//取角度离散值,反比,半径越大该值越小int n=(int)((ae-as)/dt);//一个圆弧上总共取n个点glColor3f(0.0,1.0,0.0);int xs=(int)(x+r*(cos(as)));//圆弧起始点int ys=(int)(y+r*(sin(ae)));glVertex2i(xs,ys);glBegin(GL_LINE_STRIP);//通过绘制折线来逼近圆弧for(int i=0;i<n;i++){double cost=r*cos(as+i*dt);double sint=r*sin(as+i*dt);glVertex2i(int(x+cost),int(y+sint));}glEnd();}void display(void){glClearColor(0.0,0.0,0.0,0.0);glClear(GL_COLOR_BUFFER_BIT);arc(x,y,r,as,ae);glFlush();}int main(int argc,char* argv[]){printf("please enter the position of Arc which include x_value,y_value,radiius,arc_start_angle,arc_end_angle\n");scanf("%d%d%lf%lf%lf",&x,&y,&r,&as,&ae);printf("x=%d,y=%d,r=%lf,as=%lf,ae=%lf\n",x,y,r,as,ae);glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);glutInitWindowSize(800,800);glutCreateWindow("hello world!");gluOrtho2D(0,1000,0,1000);glutDisplayFunc(display);glutMainLoop();return 0;}
</pre><pre name="code" class="cpp">
</pre><pre name="code" class="cpp">#include<stdio.h><span style="white-space:pre"></span>//绘制椭圆程序
#include<math.h>double pi=3.1415936;int a,b;void swap(int* a,int* b){int temp;temp=*a;*a=*b;*b=temp;}void ellipse(int x,int y,int a,int b){glColor3f(0.0,1.0,0.0);int flag=0;if (a<b)//比较a,b 的值确保a始终是长轴{ flag=1; swap(&a,&b);}double d=a*a-b*b;double c=sqrt(d);double dt=1/c;//取角度离散值,反比,c越大该值越小int n=(int)(2*pi/dt);//一个圆弧上总共取n个点glPointSize(3);glBegin(GL_POINTS);if(!flag){glVertex2f(x+c,y); glVertex2f(x-c,y); }else{ glVertex2f(y,x+c); glVertex2f(y,x-c); }glEnd();glBegin(GL_LINE_LOOP);for(int i=0;i<n;i++){int cost=a*cos(i*dt);int sint=b*sin(i*dt);if(!flag)glVertex2i(x+cost,y+sint);elseglVertex2i(y+sint,x+cost);//printf("x=%d,y=%d\n",cost,sint);}glEnd();}void display(void){glClearColor(0.0,0.0,0.0,0.0);glClear(GL_COLOR_BUFFER_BIT);ellipse(500,500,300,100);glFlush();}int main(int argc,char* argv[]){//printf("please enter the position of ellipse which include x_value,y_value,long_axiel,short_exiel\n");//scanf("%d%d",&a,&b);//printf("a=%d,b=%d\n",a,b);glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);glutInitWindowSize(800,800);glutCreateWindow("hello world!");gluOrtho2D(0,1000,0,1000);glutDisplayFunc(display);glutMainLoop();return 0;}
0 0
- 角度离散法绘制圆弧 | 椭圆
- Java绘图: 使用Graphics类绘制线段、矩形、椭圆/圆弧/扇形、图片、文本
- Java绘图: 使用Graphics类绘制线段、矩形、椭圆/圆弧/扇形、图片、文本
- 圆弧角度计算
- 绘制椭圆
- j2me-绘制圆弧
- CANVAS绘制圆弧
- drawArc绘制圆弧
- drawArc方法:绘制圆弧
- Graphics类提供基本的几何图形绘制方法,主要有:画线段、画矩形、画圆、画带颜色的图形、画椭圆、画圆弧、画多边形等。
- 从绘制圆弧思考定位
- OpenGL绘制圆弧/圆/饼图
- svg绘制圆弧(一)
- svg绘制圆弧(二)
- canvas绘制文本 圆弧 详解
- 3.canvas:圆弧的绘制
- 高速椭圆绘制程序
- c#绘制椭圆
- 习题 7-3 uva211
- 配置 windows server FTP开启防火墙例外后然然无法访问的解决办法
- shell进阶---linux shell 流程控制
- Java的集合容器(上)
- Java 链接查询
- 角度离散法绘制圆弧 | 椭圆
- 三维图形绕任意轴旋转矩阵求解步骤
- Python进阶---python判断字符串是否包含子字符串的方法
- 硬件-内存1
- Mysql分页-Limit
- 尺度空间
- 使用layout_weight属性实现视图的居中显示
- Python进阶---python 中字符串大小写转换
- Eclipse中写Hibernate的hbm.xml文件时不自动提示的问题解决