B样条曲线正算反算贝塞尔曲线拼接曲面车身CAD作业答案_第1页
B样条曲线正算反算贝塞尔曲线拼接曲面车身CAD作业答案_第2页
B样条曲线正算反算贝塞尔曲线拼接曲面车身CAD作业答案_第3页
B样条曲线正算反算贝塞尔曲线拼接曲面车身CAD作业答案_第4页
B样条曲线正算反算贝塞尔曲线拼接曲面车身CAD作业答案_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1、 贝塞尔曲线的拼接用matlab画代码如下:% By lyqmathclc; clear all; close all;p=1 2; 4 8; 6 15; 9 18;p=p't=linspace(0,1,200);n=size(p,2)-1;r=0;for k=0:n r=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')2、 B样条曲线的正算function Byt8(p0,p1,p2,p3,p4,p5,p6

2、,p7)t=0:0.001:1;%m=-1 3 -3 1;3 -6 3 0;-3 0 3 0;1 4 1 0;x=p0(1)*(1/6)*(-t.3+3*t.2-3*t+1)+p1(1)*(1/6)*(3*t.3-6*t.2+4). +p2(1)*(1/6)*(-3*t.3+3*t.2+3*t+1)+p3(1)*(1/6)*t.3;y=p0(2)*(1/6)*(-t.3+3*t.2-3*t+1)+p1(2)*(1/6)*(3*t.3-6*t.2+4). +p2(2)*(1/6)*(-3*t.3+3*t.2+3*t+1)+p3(2)*(1/6)*t.3;%plot(p0(1) p1(1) p2(

3、1) p3(1),p0(2) p1(2) p2(2) p3(2);hold on;plot(x,y,'r');x=p1(1)*(1/6)*(-t.3+3*t.2-3*t+1)+p2(1)*(1/6)*(3*t.3-6*t.2+4). +p3(1)*(1/6)*(-3*t.3+3*t.2+3*t+1)+p4(1)*(1/6)*t.3;y=p1(2)*(1/6)*(-t.3+3*t.2-3*t+1)+p2(2)*(1/6)*(3*t.3-6*t.2+4). +p3(2)*(1/6)*(-3*t.3+3*t.2+3*t+1)+p4(2)*(1/6)*t.3;%plot(p0(1) p

4、1(1) p2(1) p3(1),p0(2) p1(2) p2(2) p3(2);hold on;plot(x,y,'r');x=p2(1)*(1/6)*(-t.3+3*t.2-3*t+1)+p3(1)*(1/6)*(3*t.3-6*t.2+4). +p4(1)*(1/6)*(-3*t.3+3*t.2+3*t+1)+p5(1)*(1/6)*t.3;y=p2(2)*(1/6)*(-t.3+3*t.2-3*t+1)+p3(2)*(1/6)*(3*t.3-6*t.2+4). +p4(2)*(1/6)*(-3*t.3+3*t.2+3*t+1)+p5(2)*(1/6)*t.3;%plot

5、(p0(1) p1(1) p2(1) p3(1),p0(2) p1(2) p2(2) p3(2);hold on;plot(x,y,'r');x=p3(1)*(1/6)*(-t.3+3*t.2-3*t+1)+p4(1)*(1/6)*(3*t.3-6*t.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

6、.3;%plot(p0(1) p1(1) p2(1) p3(1),p0(2) p1(2) p2(2) p3(2);hold on;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)

7、*(1/6)*t.3;%plot(p0(1) p1(1) p2(1) p3(1),p0(2) p1(2) p2(2) p3(2);hold on;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)3、 B样条曲线的反算function Byangtiao8(p)t=0:0.005:1;hold onfo

8、r i=1:5 x=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,

9、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); 4、 双三次B样条曲面的算法/ TestView.cpp : implementation of the CTestView class/#include "stdafx.h"#include "Test.h"#define ROUND(a) int(a+0.5)/四舍五入#include "math.h"/数学头文件#include "

10、TestDoc.h"#include "TestView.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CTestViewIMPLEMENT_DYNCREATE(CTestView, CView)BEGIN_MESSAGE_MAP(CTestView, CView)/AFX_MSG_MAP(CTestView)ON_COMMAND(ID_MENUDrawHermite, OnMENUDrawHermite)/AFX_MSG_MAP

11、/ Standard printing commandsON_COMMAND(ID_, CView:On)ON_COMMAND(ID_, CView:On)ON_COMMAND(ID_, CView:On)END_MESSAGE_MAP()/ CTestView construction/destructionCTestView:CTestView()/ TODO: add construction code here/9个型值点的初始化p100=410;p101=532;p110=210;p111=386;p120=410;p121=316;p130=310;p131=162;p140=51

12、0;p141=50;p150=710;p151=162;p160=610;p161=316;p170=810;p171=386;p180=610;p181=532;/9个型值点导数的初始化p200=100;p201=-100;p210=100;p211=-100;p220=100;p221=-100;p230=100;p231=-100;p240=-100;p241=-100;p250=-100;p251=100;p260=-100;p261=100;p270=-100;p271=100;p280=-100;p281=-100;CTestView:CTestView()BOOL CTestVi

13、ew:PreCreateWindow(CREATESTRUCT& cs)/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csreturn CView:PreCreateWindow(cs);/ CTestView drawingvoid CTestView:OnDraw(CDC* pDC)CTestDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data hereCPen

14、MyPen,*pOldPen;MyPen.CreatePen(PS_SOLID,3,RGB(0,0,255);/蓝色笔绘制特征多边形pOldPen=pDC->SelectObject(&MyPen);pDC->MoveTo(p100,p101);pDC->Ellipse(p100-2,p101-2,p100+2,p101+2);/绘制特征多边形顶点for(int i=1;i<9;i+)pDC->LineTo(p1i0,p1i1);pDC->Ellipse(p1i0-2,p1i1-2,p1i0+2,p1i1+2);pDC->SelectObjec

15、t(pOldPen);MyPen.DeleteObject();/ CTestView printingBOOL CTestView:OnPreparePrinting(CPrintInfo* pInfo)/ default preparationreturn DoPreparePrinting(pInfo);void CTestView:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add extra initialization before printingvoid CTestView:OnEndPrinting(

16、CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add cleanup after printing/ CTestView diagnostics#ifdef _DEBUGvoid CTestView:AssertValid() constCView:AssertValid();void CTestView:Dump(CDumpContext& dc) constCView:Dump(dc);CTestDoc* CTestView:GetDocument() / non-debug version is inlineASSERT(m_pDocum

17、ent->IsKindOf(RUNTIME_CLASS(CTestDoc);return (CTestDoc*)m_pDocument;#endif /_DEBUG/ CTestView message handlersvoid CTestView:Hermite(CDC *pDC)/绘制Hermite三次插值样条int a44 =2,-2,1,1,-3,3,-2,-1,0,0,1,0,1,0,0,0;/Mh矩阵系数int b42;/边界点 for(int i=0;i<8;i+)b00=p1i0;b01=p1i1;/起点的坐标b10=p1i+10;b11=p1i+11;/终点的坐标

18、b20=p2i0;b21=p2i1;/起点的导数b30=p2i+10;b31=p2i+11;/终点的导数MultiMatrix(a,b);CPen MyPen,*pOldPen;MyPen.CreatePen(PS_SOLID,1,RGB(255,0,0);pOldPen=pDC->SelectObject(&MyPen);pDC->MoveTo(p1i0,p1i1);for(double t=0.0;t<=1;t+=1.0/400)int x=ROUND(pow(t,3)*result00+pow(t,2)*result10+ t*result20+result30);int y=ROUND(pow(t,3)*result01+pow(t,2)*result11+ t*result21+result31);pDC->LineTo(x,y);pDC->SelectObject(pOldPen);MyPen.DeleteObject();void CTestView:MultiMatrix(int a44,int b42)/矩阵相乘int i,j,k;for(i=0;i<4;i+)for(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论