《计算机图形学实验Koch曲线.doc》由会员分享,可在线阅读,更多相关《计算机图形学实验Koch曲线.doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、计算机图形学实验Koch曲线实验 8-2一、实验题目在Koch 曲线的基础上,调整角,分别以0、60和120绘制三条Koch曲线构成封闭图形,形成图8-59所示的Koch雪花,请编程实现.二、实验思想已知初始直线段的起点坐标P0和终点坐标P1,可以计算出长度L0 .设递归n次后的最小线元长度为d,则三、实验代码void CTestView::GetMaxX()/求屏幕最大x值CRect Rect;GetClientRect(Rect); MaxX=Rect.right;void CTestView:GetMaxY()/求屏幕最大y值CRect Rect;GetClientRect(&Rect)
2、; MaxY=Rect。bottom;void CTestView::Koch1(CDC pDC,int n)/0Position.x=MaxX/4;Position.y=MaxY/4; if(n=0) b.x+=dcos(alphaPI/180);b。y+=d*sin(alpha*PI/180);pDC-MoveTo(ROUND(a.x+Position.x),ROUND(a。y+MaxY-Position。y));pDC-LineTo(ROUND(b。x+Position。x),ROUND(b。y+MaxYPosition。y);a=b;return; Koch1(pDC,n-1); al
3、pha+=60; Koch1(pDC,n1); alpha=120; Koch1(pDC,n1); alpha+=60; Koch1(pDC,n-1);void CTestView::Koch2(CDC *pDC,int n)/60Position.x=MaxX/4;Position.y=MaxY/4; if(n=0) b。x+=dcos((alpha+60)*PI/180);b。y+=d*sin((alpha+60)*PI/180);pDCMoveTo(ROUND(a.x+Position.x),ROUND(MaxY-Position.y-a.y));pDC-LineTo(ROUND(b。x
4、+Position。x),ROUND(MaxYPosition.y-b。y));a=b;return; Koch2(pDC,n1); alpha+=60; Koch2(pDC,n-1); alpha=120; Koch2(pDC,n1); alpha+=60; Koch2(pDC,n1);void CTestView::Koch3(CDC pDC,int n)Position。x=MaxX/2;Position.y=MaxY/4; if(n=0) b。x+=d*cos(alpha-120)*PI/180);/120b.y+=dsin(alpha120)PI/180);pDC-MoveTo(RO
5、UND(a。x+Position.x),ROUND(a。y+MaxY-Position。y);pDC-LineTo(ROUND(b.x+Position。x),ROUND(b。y+MaxY-Position。y);a=b;return; Koch3(pDC,n-1); alpha+=60; Koch3(pDC,n-1); alpha=120; Koch3(pDC,n1); alpha+=60; Koch3(pDC,n-1);void CTestView::OnMENUKochSnow() / TODO: Add your command handler code hereCInputDlg dlg;if (dlg。DoModal()=IDOK)n=dlg。m_n;elsereturn;RedrawWindow();CDC *pDC=GetDC();/客户区DCGetMaxX();GetMaxY();d=(MaxX/4)/pow(3,n);a.x=0,a。y=0,b.x=0,b.y=0,alpha=0;Koch1(pDC,n);a.x=0,a。y=0,b.x=0,b。y=0,alpha=0; Koch2(pDC,n);a。x=0,a.y=0,b.x=0,b。y=0,alpha=0; Koch3(pDC,n);ReleaseDC(pDC);四、实验结果截图