您好,欢迎访问三七文档
1实验报告课程名称:计算几何实验实验项目:1.Bezier曲线2.B样条曲线专业班级:信息与计算科学1202班姓名:马全学号:120701211实验室号:理学院机房实验组号:实验时间:2015.6.26批阅时间:指导教师:曲绍波成绩:2专业班级:信息与计算科学1202班学号:120701211姓名:马全实验名称:1.实验目的:(1)了解Bezier曲线,B样条曲线(2)根据要求编制程序进行实现2.实验内容:编制程序实现(1)Bezier曲线,(2)B样条曲线。3.实验题目一、Bezier曲线:编制程序实现(1)根据输入的4个控制定点绘制3次Bezier曲线和相关的控制多边形;(2)对于(1)中的Bezier曲线进行升阶,画出升阶后的控制多边形;(3)对于输入的参数值,根据deCasteljau算法绘出曲线上相应的点。二、B样条曲线:编制程序实现(1)根据输入的8个控制定点P0,P1….,P7绘制定义在节点向量U={0,0,0,1,2,3,4,5,6,6,6}上的2次B样条曲线和对应的控制多边形:曲线的每一段用不同的颜色或线形绘出。(2)对于(1)中的控制顶点和节点向量,绘制相应的3次B样条和相应的控制多边形:曲线的每一段用不同的颜色或线形绘出。4实验步骤或程序(经调试后正确的源程序)【见附件A】5.程序运行结果【见附件A】6.出现的问题及解决方法未出现问题。3附件A沈阳工业大学实验报告(适用计算机程序设计类)专业班级:信息与计算科学1202班学号:120701211姓名:马全一,源程序(C++语言)1.Bezier曲线(Win32Appvc6.0)#includewindows.h#includestdlib.h#includetime.h#defineNUM10LRESULTCALLBACKWinproc(HWND,UINT,WPARAM,LPARAM);intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstanc,LPSTRlpCmdLine,intnShowCmd){MSGmsg;staticTCHARszClassName[]=TEXT;HWNDhwnd;WNDCLASSwc;wc.cbClsExtra=0;wc.cbWndExtra=0;wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wc.hCursor=LoadCursor(NULL,IDC_ARROW);wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);wc.hInstance=hInstance;wc.lpfnWndProc=Winproc;wc.lpszClassName=szClassName;wc.lpszMenuName=NULL;wc.style=CS_HREDRAW|CS_VREDRAW;if(!RegisterClass(&wc)){MessageBox(NULL,TEXT(),TEXT(),MB_ICONERROR);return0;}hwnd=CreateWindow(szClassName,szClassName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,4NULL,NULL,hInstance,NULL);ShowWindow(hwnd,SW_SHOWMAXIMIZED);UpdateWindow(hwnd);while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}returnmsg.wParam;}LRESULTCALLBACKWinproc(HWNDhwnd,UINTmessage,WPARAMwparam,LPARAMlparam){PAINTSTRUCTps;HDChdc;staticPOINTpt[NUM];TEXTMETRICtm;staticintcxClient,cyClient;HPENhpen;inti,j,k,n,t;switch(message){caseWM_CREATE:staticintcxchar;hdc=GetDC(hwnd);GetTextMetrics(hdc,&tm);cxchar=tm.tmAveCharWidth;ReleaseDC(hwnd,hdc);caseWM_SIZE:cxClient=LOWORD(lparam);cyClient=HIWORD(lparam);return0;caseWM_PAINT:hdc=GetDC(hwnd);srand(time(0));Rectangle(hdc,0,0,cxClient,cyClient);for(i=0;i500;i++){5SelectObject(hdc,GetStockObject(WHITE_PEN));PolyBezier(hdc,pt,NUM);for(j=0;jNUM;j++){pt[j].x=rand()%cxClient;pt[j].y=rand()%cyClient;}hpen=CreatePen(PS_INSIDEFRAME,3,RGB(rand()%256,rand()%256,rand()%256));DeleteObject(SelectObject(hdc,hpen));PolyBezier(hdc,pt,NUM);for(k=0;k50000000;k++);}for(i=0;i100;i++){Ellipse(hdc,rand()%cxClient,rand()%cyClient,rand()%cxClient,rand()%cyClient);Pie(hdc,j=rand()%cxClient,k=rand()%cyClient,n=rand()%cxClient,t=rand()%cyClient,rand()%cxClient,rand()%cyClient,rand()%cxClient,rand()%cyClient);}if((n=(n+j)/2)cxchar*20)n=cxchar*20;SetTextColor(hdc,RGB(rand()%256,rand()%256,rand()%256));TextOut(hdc,n/2,(t+k)/2,TEXT(PiermBezier!),lstrlen(TEXT(PiermBezier!)));ReleaseDC(hwnd,hdc);DeleteObject(hpen);ValidateRect(hwnd,NULL);return0;caseWM_DESTROY:PostQuitMessage(0);return0;}returnDefWindowProc(hwnd,message,wparam,lparam);}62.B样条曲线namespacesp{staticdoubleeps=1.0e-8;}voidSetEps(doubleEps){if(Eps0.1)return;eps=Eps;}doubleGetEps(){returneps;}inlineintMBiger(doublea,doubleb){returnab||a-b;}doubleN(inti,intk,doublesu[],doubleu){if(k==0){if(u-su[0]eps){if(i==0)return1.0;elsereturn0.0;}if(u=su[i]&&usu[i+1])return1.0;elsereturn0.0;}elseif(k0){if(MBiger(su[i+k]-su[i],eps)&&MBiger(su[i+k+1]-su[i+1],eps)){return(u-su[i])*N(i,k-1,su,u)/(su[i+k]-su[i])+(su[i+k+1]-u)*N(i+1,k-1,su,u)/(su[i+k+1]-su[i+1]);}7elseif(!MBiger(su[i+k]-su[i],eps)&&MBiger(su[i+k+1]-su[i+1],eps)){return(su[i+k+1]-u)*N(i+1,k-1,su,u)/(su[i+k+1]-su[i+1]);}elseif(MBiger(su[i+k]-su[i],eps)&&!MBiger(su[i+k+1]-su[i+1],eps)){return(u-su[i])*N(i,k-1,su,u)/(su[i+k]-su[i]);}elsereturn0.0;}elsereturn0.0;}doubleBSL1(intk,doublesu[],doubled[],intn,doubleu){inti;doubles=0.0;for(i=0;in;i++)s=s+d[i]*N(i,k,su,u);returns;}8二.运行结果1.Bezier曲线:编制程序实现(1)根据输入的4个控制定点绘制3次Bezier曲线和相关的控制多边形;(2)对于(1)中的Bezier曲线进行升阶,画出升阶后的控制多边形;(3)对于输入的参数值,根据deCasteljau算法绘出曲线上相应的点。92.B样条曲线:编制程序实现(1)根据输入的8个控制定点P0,P1….,P7绘制定义在节点向量U={0,0,0,1,2,3,4,5,6,6,6}上的2次B样条曲线和对应的控制多边形:曲线的每一段用不同的颜色或线形绘出(此图形由Matlab生成)。(2)对于(1)中的控制顶点和节点向量,绘制相应的3次B样条和相应的控制多边形:曲线的每一段用不同的颜色或线形绘出(下图由Matlab生成)。
本文标题:计算几何实验报告
链接地址:https://www.777doc.com/doc-2041642 .html