- 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
您可能关注的文档
- PCB库元件名称及中英对照.doc
- PLC、DCS、FCS三大控制系统的基本特点及区别.doc
- PLC组态.doc
- Programmable and autonomous computing machine made of biomolecules(部分).doc
- PIN FUNCTIONS.doc
- ps英汉对照.doc
- s3c2410的定时器工作原理及应用--To.doc
- Science and technology 科学技术.doc
- SD卡的命令格式.doc
- simulink说明.doc
- (2026春新版)部编版八年级语文下册《第一单元》PPT课件.pptx
- 2018电力监控系统网络安全监测装置技术规范.docx
- 2022电力监控系统安全防护方案审核要点.docx
- 2014电力电缆光伏系统EN 50618欧标.docx
- (2026春新版)人教版二年级数学下册《第三单元 万以内数的认识》教案.docx
- (2026春新版)人教版二年级数学下册《第四单元 万以内的加法和减法》教案.docx
- (2026春新版)人教版二年级数学下册《综合与实践 时间在哪里》教案.docx
- (2026春新版)苏教版二年级数学下册《综合与实践 时间有多长》教案 .pdf
- (2026春新版)部编版三年级语文下册第3单元(教案).docx
- (2026春新版)部编版三年级语文下册第8单元(教案).docx
原创力文档

文档评论(0)