1、南昌大学计算机图形学实验报告实 验 报 告实验课程: 计算机图形学 学生姓名: 涂汉江 学 号: 6100410181 专业班级: 数媒101班 2012年 12 月 16号目录实验1 绘制直线和圆.1实验2 种子填充算法.3实验3 线条的剪裁.6实验4 B样条曲线绘制.10实验 5 deboor曲线的绘制.13 南昌大学实验报告学生姓名:涂汉江 学 号:6100410181 专业班级: 数字媒体101班 实验类型:验证综合设计创新 实验日期:2012-12-16 实验1 绘制直线和圆1.实验目的掌握基本图形的绘制2.实验内容1.、绘制一条直线2、.绘制一个圆3.实验环境1、个人计算机2、Wi
2、ndows7操作系统3、VS20104.实验步骤主要的代码:1、线的实现代码:这里采用的是数值微分法的方法void C线与圆2View:dda(int x0,int y0,int x1,int y1,int color,CDC *pDC) float dx,dy,k,y; dx=x1-x0; dy=y1-y0; k=dy/dx; y=y0; for(int x=x0;xSetPixelV(x,int(y+0.5),RGB(255,0,0); y=y+k; 2、圆的实现代码这里采用的是中点画圆算法void C线与圆2View:midcircle(int r,int color,CDC *pDC)
3、 int x=0; int y=r; float d; d=1.25-r; pDC-SetPixelV(x+100,y+100,RGB(255,0,0); while(xy) if(dSetPixelV(x+100,y+100,RGB(255,0,0); pDC-SetPixelV(y+100,x+100,RGB(255,0,0); pDC-SetPixelV(-x+100,y+100,RGB(255,0,0); pDC-SetPixelV(x+100,-y+100,RGB(255,0,0); pDC-SetPixelV(-x+100,-y+100,RGB(255,0,0); pDC-SetP
4、ixelV(-y+100,x+100,RGB(255,0,0); pDC-SetPixelV(y+100,-x+100,RGB(255,0,0); pDC-SetPixelV(-y+100,-x+100,RGB(255,0,0); 3、头文件包含的文件#include stdafx.h/ SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的/ ATL 项目中进行定义,并允许与该项目共享文档代码。#ifndef SHARED_HANDLERS#include 线与圆.h#endif#include 线与圆Doc.h#include 线与圆View.h#ifdef _DEBUG
5、#define new DEBUG_NEW#endif4、调用部分void C线与圆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的圆的,通过改变中心
6、坐标和坐标正负号,重复循环4次,最后得到一个整圆。前面有做直线的经验,所以总体来说还是比较顺利的。上个学期学习了数值分析课程,也用过类似的描点函数,同样是设计函数,实现循环描点。 南昌大学实验报告学生姓名:涂汉江 学 号:6100410181 专业班级: 数字媒体101班 实验类型:验证综合设计创新 实验日期:2012-12-16 实验2 种子填充算法1.实验目的掌握图形的填充算法2.实验内容1.绘制一个矩形2.用种子填充算法为其上色3.实验环境1.个人计算机2.Windows7操作系统3.VS20104.实验步骤主要代码部分:/ seedfillView.cpp : implementati
7、on of the CSeedfillView class/#include stdafx.h#include seedfill.h#include seedfillDoc.h#include seedfillView.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CSeedfillViewIMPLEMENT_DYNCREATE(CSeedfillView, CView)BEGIN_MESSAGE_MAP(CSeedfillView, CView) /AFX_M
8、SG_MAP(CSeedfillView) / NOTE - the ClassWizard will add and remove mapping macros here. / DO NOT EDIT what you see in these blocks of generated code! /AFX_MSG_MAP / Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView:OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView:OnFilePrint) ON_COMMAND(
9、ID_FILE_PRINT_PREVIEW, CView:OnFilePrintPreview)END_MESSAGE_MAP()/ CSeedfillView construction/destructionCSeedfillView:CSeedfillView() / TODO: add construction code hereCSeedfillView:CSeedfillView()BOOL CSeedfillView:PreCreateWindow(CREATESTRUCT& cs) / TODO: Modify the Window class or styles here by
10、 modifying / the CREATESTRUCT cs return CView:PreCreateWindow(cs);/ CSeedfillView drawingvoid CSeedfillView:OnDraw(CDC* pDC) CSeedfillDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); / TODO: add draw code for native data here DrawRectangle(pDC); seed(210,210,(255,0,0),(225,255,225),pDC);void CSeedfill
11、View:seed(int x,int y,int fillcolor,int oldcolor,CDC* pDC) int ccolor; ccolor = pDC-GetPixel(x,y); if(ccolor!=oldcolor&ccolor!=fillcolor) pDC-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,old
12、color,pDC); void CSeedfillView:DrawRectangle(CDC* pDC) for(int i=200;iSetPixelV(200,i,RGB(0,0,0); pDC-SetPixelV(300,i,RGB(0,0,0); pDC-SetPixelV(i,200,RGB(0,0,0); pDC-SetPixelV(i,300,RGB(0,0,0); / CSeedfillView printingBOOL CSeedfillView:OnPreparePrinting(CPrintInfo* pInfo) / default preparation retu
13、rn DoPreparePrinting(pInfo);void CSeedfillView:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) / TODO: add extra initialization before printingvoid CSeedfillView:OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) / TODO: add cleanup after printing/ CSeedfillView diagnostics#ifdef _DEBUGvoid CSe
14、edfillView:AssertValid() const CView:AssertValid();void CSeedfillView:Dump(CDumpContext& dc) const CView:Dump(dc);CSeedfillDoc* CSeedfillView:GetDocument() / non-debug version is inline ASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CSeedfillDoc); return (CSeedfillDoc*)m_pDocument;#endif /_DEBUG/ CSeedfi
15、llView message handlers运行结果如下:5.实验思考和问题解决参考书上的伪代码并且与同学室友相互讨论实践才得到最后的结果,结果也差强人意,图显示的效果不好,很小。 南昌大学实验报告学生姓名:涂汉江 学 号:6100410181 专业班级: 数字媒体101班 实验类型:验证综合设计创新 实验日期:2012-12-16 实验3线条的剪裁1.实验目的掌握对线条的剪裁算法2.实验内容1.绘制一条直线2.绘制一个矩形3.计算矩形内的线段4.绘制矩形内的线段3.实验环境1.个人计算机2.Windows7操作系统3.VS20104.实验步骤/ LineCutView.cpp : impl
16、ementation of the CLineCutView class/#include stdafx.h#include LineCut.h#include LineCutDoc.h#include LineCutView.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CLineCutViewIMPLEMENT_DYNCREATE(CLineCutView, CView)BEGIN_MESSAGE_MAP(CLineCutView, CView) /AFX_
17、MSG_MAP(CLineCutView)/ NOTE - the ClassWizard will add and remove mapping macros here./ DO NOT EDIT what you see in these blocks of generated code!/AFX_MSG_MAP/ Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView:OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView:OnFilePrint) ON_COMMAND(ID_F
18、ILE_PRINT_PREVIEW, CView:OnFilePrintPreview)END_MESSAGE_MAP()/ CLineCutView construction/destructionCLineCutView:CLineCutView() / TODO: add construction code hereCLineCutView:CLineCutView()BOOL CLineCutView:PreCreateWindow(CREATESTRUCT& cs) / TODO: Modify the Window class or styles here by modifying
19、 / the CREATESTRUCT cs return CView:PreCreateWindow(cs);/ CLineCutView drawingvoid CLineCutView:OnDraw(CDC* pDC) CLineCutDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); / TODO: add draw code for native data hereDrawRectangle(pDC);DrawLine(100,200,400,300,RGB(255,0,0), pDC);C_S_Line_Clip(100,200,400,3
20、00,pDC);void CLineCutView:DrawRectangle(CDC* pDC) for(int i=200;iSetPixelV(200,i,RGB(0,0,0); pDC-SetPixelV(300,i,RGB(0,0,0); pDC-SetPixelV(i,200,RGB(0,0,0); pDC-SetPixelV(i,300,RGB(0,0,0); void CLineCutView:DrawLine(int x0,int y0,int x1,int y1,int color,CDC* pDC) int x; float dx,dy,k,y; dx=x1-x0; dy
21、=y1-y0; k=dy/dx; y=y0; for(x=x0;xSetPixelV(x,int (y+0.5),color); y=y+k; void CLineCutView:encode(float x,float y,int &code) int c; c=0; if(xXR) c=c|RIGHT; if(yYT) c=c|TOP; code=c;void CLineCutView:C_S_Line_Clip(float x1,float y1,float x2,float y2,CDC* pDC) int x,y; int code1,code2,code; encode(x1,y1
22、,code1); encode(x2,y2,code2); while(code1!=0 | code2!=0) if(code1&code2)!=0) return; code=code1; if(code1=0) code=code2; if(LEFT&code)!=0) x=XL; y=y1+(y2-y1)*(XL-x1)/(x2-x1); else if(RIGHT&code)!=0) x=XR; y=y1+(y2-y1)*(XR-x1)/(x2-x1); else if(BOTTOM&code)!=0) y=YB; x=x1+(x2-x1)*(YB-y1)/(y2-y1); else
23、 if(TOP&code)!=0) y=YT; x=x1+(x2-x1)*(YT-y1)/(y2-y1); if(code=code1) x1=x; y1=y; encode(x,y,code1); else 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;/ CLineCutView printingBOOL CLineCutView:OnPrepare
24、Printing(CPrintInfo* pInfo) / default preparation return DoPreparePrinting(pInfo);void CLineCutView:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) / TODO: add extra initialization before printingvoid CLineCutView:OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) / TODO: add cleanup after prin
25、ting/ CLineCutView diagnostics#ifdef _DEBUGvoid CLineCutView:AssertValid() const CView:AssertValid();void CLineCutView:Dump(CDumpContext& dc) const CView:Dump(dc);CLineCutDoc* CLineCutView:GetDocument() / non-debug version is inline ASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CLineCutDoc); return (CLineCutDoc*)m_pDocument;#endif /_DEBUG/
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2