中点算法画填充圆实验报告.docVIP

  • 18
  • 0
  • 约3万字
  • 约 6页
  • 2016-08-24 发布于河南
  • 举报
中点算法画填充圆实验报告

中点算法画填充圆实验报告 实验题目 中点算法画填充圆。 中点画圆算法内容: 1,输入圆心位置和圆的半径,得到圆周上的第一个点Point1; (假设起始点为坐标原点,后面将通过坐标平移来处理非圆心在圆点) 2,计算决策关键参数的初始值,P = 5/4 - r; 3,在每个Xn的位置,从n = 0开始,更具决策值P来判断: 如果P0,下一个点的位置为(Xn+1,Yn); 并且执行P = P + 2*x+3; 如果P=0,下一个点的位置为(Xn+1,Yn-1); 并且执行P = P + 2.0*(x-y)+5; 4,通过对称原理计算其他7个对称相关点; 5,移动坐标到圆心点(x1,y1) X = X + x1; Y = Y + y1; 6,如果XY重复执行3到5的步骤,否则结束该算法 源代码: #includeGL/glut.h GLint xc = 0; GLint yc = 0; int p[200][200]; class screenPt { private: GLint x,y; public: screenPt(){ x = y = 0; } void setCoords(GLint xCoordValue,GLint yCoordValue){ x = xCoordValue; y = yCoordValue; } GLint getx() const{ return x; } GLint gety() const{ return y; } void incrementx(){ x++; } void decrementy(){ y--; } }; void setPixel(GLint xCoord,GLint yCoord) { p[xCoord][yCoord]=1;//设置边缘色为1 glBegin(GL_POINTS); glVertex2i(xCoord,yCoord); glEnd(); } void circlePlotPoints(GLint xc,GLint yc,screenPt circPt) { setPixel(xc + circPt.getx(),yc + circPt.gety()); setPixel(xc - circPt.getx(),yc + circPt.gety()); setPixel(xc + circPt.getx(),yc - circPt.gety()); setPixel(xc - circPt.getx(),yc - circPt.gety()); setPixel(xc + circPt.gety(),yc + circPt.getx()); setPixel(xc - circPt.gety(),yc + circPt.getx()); setPixel(xc + circPt.gety(),yc - circPt.getx()); setPixel(xc - circPt.gety(),yc - circPt.getx()); } void circleMidpoint(GLint radius) { screenPt circPt; GLint p = 1 - radius; circPt.setCoords(0,radius); void circlePlotPoints(GLint,GLint,screenPt); circlePlotPoints(xc,yc,circPt); while(circPt.getx()circPt.gety()){ circPt.incrementx(); if(p0) p+=2*circPt.getx()+1; else{ circPt.decrementy(); p+=2*(circPt.getx() - circPt.gety())+1; } circlePlotPoints(xc,yc,circPt); } } void getPixel(int x , int y , int Color ) { Color=p[x][y]; } void setPixel2 (GLint xCoord , GLint yCoord) { //p[i][j]=1;填充色为2 p[xCoord][yCoord]=2; glColor3f(0.0,1.0,1.0); glPointSize(5); glBegin (GL_POINTS); glVertex2f(xCoor

文档评论(0)

1亿VIP精品文档

相关文档