计算机图形学.docx
- 文档编号:30543996
- 上传时间:2023-08-16
- 格式:DOCX
- 页数:9
- 大小:21.68KB
计算机图形学.docx
《计算机图形学.docx》由会员分享,可在线阅读,更多相关《计算机图形学.docx(9页珍藏版)》请在冰豆网上搜索。
计算机图形学
实验报告
课程计算机图形学
实验名称区域填充算法
专业班级
姓名
学号
实验日期
教师审批签字
二零一零年七月二日
一、实验目的和要求
1、实验目的
通过本实验,使自己了解计算机图形学的有关原理、算法及系统,掌握基本图形显示程序设计方法,为进一步学习计算机辅助设计方面的技术知识打下基础。
(1)、了解计算机图形学的原理、方法和应用。
(2)、掌握计算机的区域填充算法及基础知识。
(3)、验证扫描线填充算法可以填充多边形。
2、实验要求
(1)、利用Win-TC实现一个可以填充多边形的算法。
(2)、在程序中可以根据输入不同的坐标值来生成不同的形状的多边形。
(3)、可以任意改变填充多边形的颜色。
二、实验环境(包括硬件和软件)
1、硬件
处理器:
AMDX2240@2.6GHz2.6GHz
内存:
威刚万紫千红2.00GB
硬盘:
西部数据500GB
显卡:
迪兰恒进HD4650
显示器:
(三星)SyncMaster2033
2、软件
系统类型:
WindowsXpsp332位操作系统
应用软件:
TurboCforWindows集成实验与学习环境2007.5
三、实验步骤(可用逻辑框图表示)
首先,先对区域填充算法的思想进行理解,即:
区域填充既给出一个多边形的边界,要求对多边形范围内的所有像素单元赋予指定的颜色代码.
根据这个原理,我们可以写出区域填充算法程序的步骤:
(1)将多边形画在平面上
(2)先用x[MAXPOINT]和y[MAXPOINT]来存放坐标点的信息
(3)扫描线从上到下扫描出点(x,y)
Yi+1=Yi-1
Xi+1=Xi-(X2-Y1)/(Y2-Y1)
(4)找到活性边为A_TOP
(5)设置初始值为Y2-Y1,△y
(5)判断每一条边△y与0的关系,实现直线的描绘
四、实验参数与代码
#include
#include
#include
#defineMAXPOINT18
typedefstruct{
intA_TOP;
floatB_INT;
intDEL_X;
floatD_C;
}E_ENTRY;
voidput_in(intentry,intx1,inty1,intx2,inty2,intnext_y);
voidsoot(intn);
voidgetup(intcount,intscan);
voidswap(E_ENTRY*x,E_ENTRY*y);
voidSTX(intentry,intfirst_s);
voidPOX(intfirst_s,intlast_s);
voidDRAWLINE(intscan,intB_INT_c,intindex);
voidUPDATES();
E_ENTRYsides[MAXPOINT];
intx[MAXPOINT]={0,120,250,350,200,100};
inty[MAXPOINT]={0,170,220,190,110,130};
ints_count,first_s,last_s,scan,bottom_s,B_INT_c;
main()
{
intdriver,mode;
intv_count=5;
driver=DETECT;
initgraph(&driver,&mode,"");
setcolor(5);
fillarea(v_count,x,y);
getch();
closegraph();
}
fillarea(intcount)
{
soot(count);
first_s=1;
last_s=1;
for(scan=sides[1].A_TOP;scan>bottom_s;scan--)
{
getup(count,scan);
POX(first_s,last_s);
DRAWLINE(scan,B_INT_c,first_s);
UPDATES();
}
}
voidput_in(intentry,intx1,inty1,intx2,inty2,intnext_y)
{
intmaxy;
floatx2_temp,xch_temp;
xch_temp=(float)(x2-x1)/(float)(y2-y1);
x2_temp=x2;
if((y2>y1)&&(y2 { y2--; x2_temp-=xch_temp; } else { if((y2 { y2++; x2_temp+=xch_temp; } } maxy=(y1>y2)? y1: y2; while((entry>1)&&(maxy>sides[entry-1].A_TOP)) { sides[entry]=sides[entry-1]; entry--; } sides[entry].A_TOP=maxy; sides[entry].DEL_X=abs(y2-y1)+1; if(y1>y2) sides[entry].B_INT=x1; else sides[entry].B_INT=x2_temp; sides[entry].D_C=xch_temp; } voidsoot(intn) { intk,x1,y1; s_count=0; y1=y[n]; x1=x[n]; bottom_s=y[n]; for(k=1;k { if(y1! =y[k]) { s_count++; put_in(s_count,x1,y1,x[k],y[k],y[k+1]); } else { line((short)x1,480-(short)y1,(short)x[k],480-(short)y1); moveto((short)x1,480-(short)y1); lineto((short)x[k],480-(short)y1); } if(y[k] y1=y[k];x1=x[k]; } } voidgetup(intcount,intscan) { while((sides[last_s+1].A_TOP>scan)&&(last_s last_s++;} voidswap(E_ENTRY*x,E_ENTRY*y) { inti_temp; floatf_temp; i_temp=x->A_TOP;x->A_TOP=y->A_TOP;y->A_TOP=i_temp; f_temp=x->B_INT;x->B_INT=y->B_INT;y->B_INT=f_temp; i_temp=x->DEL_X;x->DEL_X=y->DEL_X;y->DEL_X=i_temp; f_temp=x->D_C; x->D_C=y->D_C; y->D_C=f_temp; } voidSTX(intentry,intfirst_s) { while((entry>first_s)&&(sides[entry].B_INT { swap(&sides[entry],&sides[entry-1]); entry--; } } voidPOX(intfirst_s,intlast_s) { intk; B_INT_c=0; for(k=first_s;k { if(sides[k].DEL_X>0) { B_INT_c++; STX(k,first_s); } } } voidDRAWLINE(intscan,intB_INT_c,intindex) {intk,x,x1,x2; for(k=1;k<(int)(B_INT_c/2+1.5);k++) { while(sides[index].DEL_X==0) index++; x1=(int)(sides[index].B_INT+0.5); index++; while(sides[index].DEL_X==0) index++; x2=(int)(sides[index].B_INT+0.5); line((short)x1,480-(short)scan,(short)x2,480-(short)scan); moveto((short)x1,480-(short)scan); lineto((short)x2,480-(short)scan); index++; } } voidUPDATES() { intk; for(k=first_s;k { if(sides[k].DEL_X>0) { sides[k].DEL_X--; sides[k].B_INT-=sides[k].D_C; } } } 五、实验数据、结果分析 运行结果如下图: 基本符合本次实验要求。 六、总结 本次实验获益匪浅,在同学朋友们的帮助下最终完成了此份实验报告。 编程的过程是需要投入很多精力的,对于编程这个事物,肯定还需要更多的实践、摸索,才能更上一层楼。 最后希望自己的编程越来越好,也感谢老师的指导。 七、教师意见
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 图形学