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^2+4)...+p5(1)*(1/6)*(-3*t.^3+3*t.^2+3*t+1)+p6(1)*(1/6)*t.^3;y=p3(2)*(1/6)*(-t.^3+3*t.^2-3*t+1)+p4(2)*(1/6)*(3*t.^3-6*t.^2+4)...+p5(2)*(1/6)*(-3*t.^3+3*t.^2+3*t+1)+p6(2)*(1/6)*t.^3;%plot([p0(1)p1(1)p2(1)p3(1)],[p0(2)p1(2)p2(2)p3(2)]);holdon;plot(x,y,'r');x=p4(1)*(1/6)*(-t.^3+3*t.^2-3*t+1)+p5(1)*(1/6)*(3*t.^3-6*t.^2+4)...+p6(1)*(1/6)*(-3*t.^3+3*t.^2+3*t+1)+p7(1)*(1/6)*t.^3;y=p4(2)*(1/6)*(-t.^3+3*t.^2-3*t+1)+p5(2)*(1/6)*(3*t.^3-6*t.^2+4)...+p6(2)*(1/6)*(-3*t.^3+3*t.^2+3*t+1)+p7(2)*(1/6)*t.^3;%plot([p0(1)p1(1)p2(1)p3(1)],[p0(2)p1(2)p2(2)p3(2)]);holdon;plot(x,y,'r');plot([p0(1)p1(1)p2(1)p3(1)p4(1)p5(1)p6(1)p7(1)],[p0(2)p1(2)p2(2)p3(2)p4(2)p5(2)p6(2)p7(2)]);执行:Byt8([0,0],[1,4],[3,9],[5,7],[6,2],[7,6],[9,5],[11,3])02468101201234567892、B样条曲线的反算functionByangtiao8(p)t=0:0.005:1;holdonfori=1:5x=p(1,i)*(1/6)*(-t.^3+3*t.^2-3*t+1)+p(1,i+1)*(1/6)*(3*t.^3-6*t.^2+4)...+p(1,i+2)*(1/6)*(-3*t.^3+3*t.^2+3*t+1)+p(1,i+3)*(1/6)*t.^3;y=p(2,i)*(1/6)*(-t.^3+3*t.^2-3*t+1)+p(2,i+1)*(1/6)*(3*t.^3-6*t.^2+4)...+p(2,i+2)*(1/6)*(-3*t.^3+3*t.^2+3*t+1)+p(2,i+3)*(1/6)*t.^3;plot(x,y,'k');endplot([p(1,1)p(1,2)p(1,3)p(1,4)p(1,5)p(1,6)p(1,7)p(1,8)],[p(2,1)p(2,2)p(2,3)p(2,4)p(2,5)p(2,6)p(2,7)p(2,8)]);3.贝塞尔曲线的拼接用matlab画代码如下:%Bylyqmathclc;clearall;closeall;p=[12;48;615;918];p=p';t=linspace(0,1,200);n=size(p,2)-1;r=0;fork=0:nr=r+prod(1:n)/(prod(1:k)*prod(1:n-k))*p(:,k+1)*(t.^k.*(1-t).^(n-k));endplot(r(1,:),r(2,:),p(1,:),p(2,:),'-or')4.双三次B样条曲面的算法//TestView.cpp:implementationoftheCTestViewclass//#includestdafx.h#includeTest.h#defineROUND(a)int(a+0.5)//四舍五入#includemath.h//数学头文件#includeTestDoc.h#includeTestView.h#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CTestViewIMPLEMENT_DYNCREATE(CTestView,CView)BEGIN_MESSAGE_MAP(CTestView,CView)//{{AFX_MSG_MAP(CTestView)ON_COMMAND(ID_MENUDrawHermite,OnMENUDrawHermite)//}}AFX_MSG_MAP//StandardprintingcommandsON_COMMAND(ID_FILE_PRINT,CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT,CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW,CView::OnFilePrintPreview)END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CTestViewconstruction/destructionCTestView::CTestView(){//TODO:addconstructioncodehere//9个型值点的初始化p1[0][0]=410;p1[0][1]=532;p1[1][0]=210;p1[1][1]=386;p1[2][0]=410;p1[2][1]=316;p1[3][0]=310;p1[3][1]=162;p1[4][0]=510;p1[4][1]=50;p1[5][0]=710;p1[5][1]=162;p1[6][0]=610;p1[6][1]=316;p1[7][0]=810;p1[7][1]=386;p1[8][0]=610;p1[8][1]=532;//9个型值点导数的初始化p2[0][0]=100;p2[0][1]=-100;p2[1][0]=100;p2[1][1]=-100;p2[2][0]=100;p2[2][1]=-100;p2[3][0]=100;p2[3][1]=-100;p2[4][0]=-100;p2[4][1]=-100;p2[5][0]=-100;p2[5][1]=100;p2[6][0]=-100;p2[6][1]=100;p2[7][0]=-100;p2[7][1]=100;p2[8][0]=-100;p2[8][1]=-100;}CTestView::~CTestView(){}BOOLCTestView::PreCreateWindow(CREATESTRUCT&cs){//TODO:ModifytheWindowclassorstylesherebymodifying//theCREATESTRUCTcsreturnCView::PreCreateWindow(cs);}///////////////////////////////////////////////////////////////////////////////CTestViewdrawingvoidCTestView::OnDraw(CDC*pDC){CTestDoc*pDoc=GetDocument();ASSERT_VALID(pDoc);//TODO:adddrawcodefornativedatahereCPenMyPen,*pOldPen;MyPen.CreatePen(PS_SOLID,3,RGB(0,0,255));//蓝色笔绘制特征多边形pOldPen=pDC-SelectObject(&MyPen);pDC-MoveTo(p1[0][0],p1[0][1]);pDC-Ellipse(p1[0][0]-2,p1[0][1]-2,p1[0][0]+2,p1[0][1]+2);//绘制特征多边形顶点for(inti=1;i9;i++){pDC-LineTo(p1[i][0],p1[i][1]);pDC-Ellipse(p1[i][0]-2,p1[i][1]-2,p1[i][0]+2,p1[i][1]+2);}pDC-SelectObject(pOldPen);MyPen.DeleteObject();}///////////////////////////////////////////////////////////////////////////////CTestViewprintingBOOLCTestView::OnPreparePrinting(CPrintInfo*pInfo){//defaultpreparationreturnDoPreparePrinting(pInfo);}voidCTestView::OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/){//TODO:addextrainitializationbeforeprinting}voidCTestView::OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/){/