南昌大学计算机图形学实验报告Word下载.docx
- 文档编号:6639278
- 上传时间:2023-05-07
- 格式:DOCX
- 页数:34
- 大小:371.67KB
南昌大学计算机图形学实验报告Word下载.docx
《南昌大学计算机图形学实验报告Word下载.docx》由会员分享,可在线阅读,更多相关《南昌大学计算机图形学实验报告Word下载.docx(34页珍藏版)》请在冰点文库上搜索。
2.实验内容
1.、绘制一条直线
2、.绘制一个圆
3.实验环境
1、个人计算机
2、Windows7操作系统
3、VS2010
4.实验步骤
主要的代码:
1、线的实现代码:
这里采用的是数值微分法的方法
voidC线与圆2View:
:
dda(intx0,inty0,intx1,inty1,intcolor,CDC*pDC)
{
floatdx,dy,k,y;
dx=x1-x0;
dy=y1-y0;
k=dy/dx;
y=y0;
for(intx=x0;
x<
=x1;
x++)
{
pDC->
SetPixelV(x,int(y+0.5),RGB(255,0,0));
y=y+k;
}
}
2、圆的实现代码
这里采用的是中点画圆算法
midcircle(intr,intcolor,CDC*pDC)
intx=0;
inty=r;
floatd;
d=1.25-r;
pDC->
SetPixelV(x+100,y+100,RGB(255,0,0));
while(x<
y)
if(d<
0)
{
d+=2*x+3;
x++;
}
else
d+=2*(x-y)+5;
y--;
SetPixelV(y+100,x+100,RGB(255,0,0));
SetPixelV(-x+100,y+100,RGB(255,0,0));
SetPixelV(x+100,-y+100,RGB(255,0,0));
SetPixelV(-x+100,-y+100,RGB(255,0,0));
SetPixelV(-y+100,x+100,RGB(255,0,0));
SetPixelV(y+100,-x+100,RGB(255,0,0));
SetPixelV(-y+100,-x+100,RGB(255,0,0));
3、头文件包含的文件
#include"
stdafx.h"
//SHARED_HANDLERS可以在实现预览、
缩略图和搜索筛选器句柄的
//ATL项目中进行定义,并允许与该项目共享文档代码。
#ifndefSHARED_HANDLERS
线与圆.h"
#endif
线与圆Doc.h"
线与圆View.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
4、调用部分
voidC线与圆View:
OnDraw(CDC*pDC)
C线与圆Doc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
if(!
pDoc)
return;
midcircle(50,RGB(255,0,0),pDC);
dda(200,200,300,300,RGB(255,0,0),pDC);
这里画的是原点为(100,100)半径为50的圆和一条以(200,200)和(300,300)为端点的线段。
5、实验结果如下截图:
5.实验思考和问题解决
本来只能做出1/4的圆的,通过改变中心坐标和坐标正负号,重复循环4次,最后得到一个整圆。
前面有做直线的经验,所以总体来说还是比较顺利的。
上个学期学习了数值分析课程,也用过类似的描点函数,同样是设计函数,实现循环描点。
实验2种子填充算法
掌握图形的填充算法
1.绘制一个矩形
2.用种子填充算法为其上色
1.个人计算机
2.Windows7操作系统
3.VS2010
主要代码部分:
//seedfillView.cpp:
implementationoftheCSeedfillViewclass
//
seedfill.h"
seedfillDoc.h"
seedfillView.h"
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
/////////////////////////////////////////////////////////////////////////////
//CSeedfillView
IMPLEMENT_DYNCREATE(CSeedfillView,CView)
BEGIN_MESSAGE_MAP(CSeedfillView,CView)
//{{AFX_MSG_MAP(CSeedfillView)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG_MAP
//Standardprintingcommands
ON_COMMAND(ID_FILE_PRINT,CView:
OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT,CView:
ON_COMMAND(ID_FILE_PRINT_PREVIEW,CView:
OnFilePrintPreview)
END_MESSAGE_MAP()
//CSeedfillViewconstruction/destruction
CSeedfillView:
CSeedfillView()
//TODO:
addconstructioncodehere
~CSeedfillView()
BOOLCSeedfillView:
PreCreateWindow(CREATESTRUCT&
cs)
ModifytheWindowclassorstylesherebymodifying
//theCREATESTRUCTcs
returnCView:
PreCreateWindow(cs);
//CSeedfillViewdrawing
voidCSeedfillView:
CSeedfillDoc*pDoc=GetDocument();
adddrawcodefornativedatahere
DrawRectangle(pDC);
seed(210,210,(255,0,0),(225,255,225),pDC);
seed(intx,inty,intfillcolor,intoldcolor,CDC*pDC)
intccolor;
ccolor=pDC->
GetPixel(x,y);
if(ccolor!
=oldcolor&
&
ccolor!
=fillcolor)
SetPixelV(x,y,fillcolor);
seed(x+1,y,fillcolor,oldcolor,pDC);
seed(x-1,y,fillcolor,oldcolor,pDC);
seed(x,y+1,fillcolor,oldcolor,pDC);
seed(x,y-1,fillcolor,oldcolor,pDC);
DrawRectangle(CDC*pDC)
for(inti=200;
i<
=300;
i++)
SetPixelV(200,i,RGB(0,0,0));
SetPixelV(300,i,RGB(0,0,0));
SetPixelV(i,200,RGB(0,0,0));
SetPixelV(i,300,RGB(0,0,0));
//CSeedfillViewprinting
OnPreparePrinting(CPrintInfo*pInfo)
//defaultpreparation
returnDoPreparePrinting(pInfo);
OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addextrainitializationbeforeprinting
OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addcleanupafterprinting
//CSeedfillViewdiagnostics
AssertValid()const
CView:
AssertValid();
Dump(CDumpContext&
dc)const
Dump(dc);
CSeedfillDoc*CSeedfillView:
GetDocument()//non-debugversionisinline
ASSERT(m_pDocument->
IsKindOf(RUNTIME_CLASS(CSeedfillDoc)));
return(CSeedfillDoc*)m_pDocument;
#endif//_DEBUG
//CSeedfillViewmessagehandlers
运行结果如下:
参考书上的伪代码并且与同学室友相互讨论实践才得到最后的结果,结果也差强人意,图显示的效果不好,很小。
实验3线条的剪裁
掌握对线条的剪裁算法
1.绘制一条直线
2.绘制一个矩形
3.计算矩形内的线段
4.绘制矩形内的线段
//LineCutView.cpp:
implementationoftheCLineCutViewclass
LineCut.h"
LineCutDoc.h"
LineCutView.h"
//CLineCutView
IMPLEMENT_DYNCREATE(CLineCutView,CView)
BEGIN_MESSAGE_MAP(CLineCutView,CView)
//{{AFX_MSG_MAP(CLineCutView)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG_MAP
//Standardprintingcommands
//CLineCutViewconstruction/destruction
CLineCutView:
CLineCutView()
~CLineCutView()
BOOLCLineCutView:
//CLineCutViewdrawing
voidCLineCutView:
CLineCutDoc*pDoc=GetDocument();
adddrawcodefornativedatahere
DrawRectangle(pDC);
DrawLine(100,200,400,300,RGB(255,0,0),pDC);
C_S_Line_Clip(100,200,400,300,pDC);
DrawLine(intx0,inty0,intx1,inty1,intcolor,CDC*pDC)
intx;
for(x=x0;
SetPixelV(x,int(y+0.5),color);
encode(floatx,floaty,int&
code)
intc;
c=0;
if(x<
XL)
c=c|LEFT;
elseif(x>
XR)
c=c|RIGHT;
if(y<
YB)
c=c|BOTTOM;
elseif(y>
YT)
c=c|TOP;
code=c;
C_S_Line_Clip(floatx1,floaty1,floatx2,floaty2,CDC*pDC)
intx,y;
intcode1,code2,code;
encode(x1,y1,code1);
encode(x2,y2,code2);
while(code1!
=0||code2!
=0)
if((code1&
code2)!
return;
code=code1;
if(code1==0)
code=code2;
if((LEFT&
code)!
x=XL;
y=y1+(y2-y1)*(XL-x1)/(x2-x1);
elseif((RIGHT&
x=XR;
y=y1+(y2-y1)*(XR-x1)/(x2-x1);
elseif((BOTTOM&
y=YB;
x=x1+(x2-x1)*(YB-y1)/(y2-y1);
elseif((TOP&
y=YT;
x=x1+(x2-x1)*(YT-y1)/(y2-y1);
if(code==code1)
x1=x;
y1=y;
encode(x,y,code1);
x2=x;
y2=y;
encode(x,y,code2);
//DISplayLine(x1,y1,x2,y2);
DrawLine(x1,y1,x2,y2,RGB(0,0,0),pDC);
DrawLine(x1,y1,x2,y2,RGB(0,0,255),pDC);
return;
//CLineCutViewprinting
//CLineCutViewdiagnostics
CLineCutDoc*CLineCutView:
IsKindOf(RUNTIME_CLASS(CLineCutDoc)));
return(CLineCutDoc*)m_pDocument;
///////////////////////////////
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 南昌大学 计算机 图形学 实验 报告