画圆——方程算法
来源:互联网 发布:优先级调度算法流程图 编辑:程序博客网 时间:2024/05/17 22:03
1、圆的方程:
2、代码:
#include "stdafx.h"#include <windows.h>#include <GL/glu.h>#include <GL/gl.h>#include <GL/glut.h>#include<stdlib.h> #include<math.h>void DrawCircle(int x, int y, int r){ int n = 20000; //分成20000份 float increment = 2 * r * 1.0 / n; //每次x的增量 glBegin(GL_POINTS); //上半个圆 float xCurrent = x - r; float yCurrent = 0; for (int i = 0; i <= n; ++i) { xCurrent += i*increment; yCurrent = y + sqrtf(pow((float)r, 2) - pow((x - xCurrent), 2)); glVertex3f(xCurrent, yCurrent, 0); } //下半个圆 xCurrent = x - r; yCurrent = 0; for (int i = 0; i <= n; ++i) { xCurrent += i*increment; yCurrent = y - sqrtf(pow((float)r, 2) - pow((x - xCurrent), 2)); glVertex3f(xCurrent, yCurrent, 0); } glEnd(); glFlush();}//主循环方法void display(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 0.0f, 1.0f); gluOrtho2D(-500,500,-500,500); //屏幕的坐标左下角为(-500,500),右上角为(500,500)。 glPointSize(3); DrawCircle(0, 0, 250); //半径为250}int main(int argc, char* argv[]){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400, 400); glutInitWindowPosition(200, 200); glutCreateWindow("Circle"); glutDisplayFunc(display); glutMainLoop(); return(0);}
这样会有有一定的误差,右边的圆形会有几个点间断:
0 0
- 画圆——方程算法
- 特殊的不定方程——佩尔方程
- 求解最大公约数——欧几里得算法及其(解同余方程)拓展欧几里得
- C语言之基本算法22—穷举法求方程近似根
- C语言之基本算法23—二分法求方程近似根
- C语言之基本算法24—黄金分割法求方程近似根
- C语言之基本算法25—牛顿迭代法求方程近似根
- C语言之基本算法26—佩尔方程求解
- 解线性同余方程—欧几里德与扩展欧几里德算法
- 【noip】解方程 秦九韶算法
- 组合方程的近似算法
- 不定方程算法java实现
- 欧几里得算法与不定方程
- 【枚举算法】佩尔方程
- 数字三角形——动态转移方程
- 神奇的数学——三次方程
- 数学——洛谷 P2312 解方程
- C语言——方程求解
- JSM之ActivityMQ
- POJ 1474 Video Surveillance -
- UIApplication
- 将每一个单词的首字母都转成大写的
- 设计模式-代理模式
- 画圆——方程算法
- ScrollView是否滑动到底部
- javascript中的this
- 二叉树中和为某一值的路径
- 在DCOM 中不存在WORD、EXCEL等OFFICE组件
- 输入验证
- hdu 2795 Billboard
- java条件中返回值那些事
- poj 3083 Children of the Candy Corn