(整理)B样条曲线正算、反算、贝塞尔曲线拼接、曲面、车身CAD作业答案. 下载本文

内容发布更新时间 : 2024/5/2 3:55:37星期一 下面是文章的全部内容请认真阅读。

精品文档 1、

贝塞尔曲线的拼接用matlab画

代码如下: % By lyqmath clc; 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)); end

plot(r(1,:),r(2,:),p(1,:),p(2,:),'-or') 5、B样条曲线的正算

function Byt8(p0,p1,p2,p3,p4,p5,p6,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(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) p1(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([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.^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)*(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])

9876543210024681012

6、B样条曲线的反算

function Byangtiao8(p) t=0:0.005:1; hold on for 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'); end

plot([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)]);

7、双三次B样条曲面的算法

// TestView.cpp : implementation of the CTestView class //

#include \#include \

#define ROUND(a) int(a+0.5)//四舍五入 #include \数学头文件 #include \#include \

#ifdef _DEBUG

#define new DEBUG_NEW #undef THIS_FILE

static char THIS_FILE[] = __FILE__; #endif

///////////////////////////////////////////////////////////////////////////// // CTestView

IMPLEMENT_DYNCREATE(CTestView, CView)

BEGIN_MESSAGE_MAP(CTestView, CView) //{{AFX_MSG_MAP(CTestView) ON_COMMAND(ID_MENUDrawHermite, OnMENUDrawHermite) 精品文档