实验11 matlab

上传人:wt****50 文档编号:56787472 上传时间:2018-10-15 格式:PPT 页数:25 大小:564KB
返回 下载 相关 举报
实验11 matlab_第1页
第1页 / 共25页
实验11 matlab_第2页
第2页 / 共25页
实验11 matlab_第3页
第3页 / 共25页
实验11 matlab_第4页
第4页 / 共25页
实验11 matlab_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《实验11 matlab》由会员分享,可在线阅读,更多相关《实验11 matlab(25页珍藏版)》请在金锄头文库上搜索。

1、实验十一 Bezier曲线的绘制,一、实验目的,初步了解Bezier曲线的定义,能利用MATLAB软件绘制二次Bezier曲线和三次Bezier曲线。,二、相关知识,Bezier广泛应用于外形设计的参数曲线逼近方法,它通过对一些特定点的控制来控制曲线的形状,我们称这些点为控制顶点。现在我们来给出Bezier曲线的数学表达式。 在空间给定 个点 ,称下列参数曲线为n次的Bezier曲线。其中 是Bernstein基函数,其表达式为:,二、相关知识,一般称折线 为曲线 的控制多边形;称点 为 的控制顶点。Bezier曲线与其控制多边形的关系可以这样认为:控制多边形 是 的大致形状的勾画; 是对其中

2、 是Bernstein基函数,其表达式为:,一般称折线 为曲线 的控制多边形;称点 为 的控制顶点。Bezier曲线与其控制多边形的关系可以这样认为:控制多边形 是 的大致形状的勾画; 是对 的逼近。 Bezier曲线有许多性质,我们这里仅讨论两条: (1)端点位置 我们指出, 和 是 的两个端点,这一点容易从 的表达式得到,即,(2)端点的切线 Bezier曲线 在 点与边 相切,在点 与边 相切,此性质可以从以下二式得证:Bezier曲线还有一些其它性质,这些将在计算机 图形学、计算几何等课程中专门讨论。 Bezier曲线有许多性质,我们这里仅讨论两条: (1)端点位置 我们指出, 和 是

3、 的两个端点,这一点容易从 的表达式得到,即,(2)端点的切线 Bezier曲线 在 点与边 相切,在点 与边 相切,此性质可以从以下二式得证:Bezier曲线还有一些其它性质,这些将在计算机 图形学、计算几何等课程中专门讨论。,现在我们讨论Bezier曲线的MATLAB绘制。先讨论2次Bezier曲线,即 的情形。此时有3个顶点,为了在MATLAB中计算方便,我们将Bezier曲线的一般表示式改写为矩阵形式,我们得到:,这样,对于确定的 ,我们取定区间 中的 值后,即可计算 的值,注意, 是与到:,这样,对于确定的 ,我们取定区间 中的 值后,即可计算 的值,注意, 是与 对应的,如果 是平

4、面上的点即2维坐标,则 也是2维坐标,如果 是空间的点即3维坐标,则 也是3维坐标,因此,对于每一组确定的 可绘制出一条2次Bezier曲线。完成平面2次Bezier曲线的MATLAB程序如下:,先编制完成Bezier曲线计算和绘制的函数bezier2.m,其参数是控制顶点的坐标。 % Bezier Square Curve Ploter % This file will create a Bezier square curve and dispay the plot. The parameter is the Vertex matrix. function X = bezier2(Verte

5、x) 对应的,如果 是平面上的点即2维坐标,则 也是2维坐标,如果 是空间的点即3维坐标,则 也是3维坐标,因此,对于每一组确定的 可绘制出一条2次Bezier曲线。完成平面2次Bezier曲线的MATLAB程序如下:,先编制完成Bezier曲线计算和绘制的函数bezier2.m,其参数是控制顶点的坐标。 % Bezier Square Curve Ploter % This file will create a Bezier square curve and dispay the plot. The parameter is the Vertex matrix. function X = b

6、ezier2(Vertex) BCon=1 -2 1;-2 2 0;1 0 0; % our 3 X 3 constant Matrix for i = 1:1:50 % for loop 1 - 50 insteps of 1 par = (i - 1)/49; XY(i,:) = par2 par 1*BCon*Vertex; end % yep! we have created our data,% we will display the vertices and the curve using % MATLABs built-in graphic functions clf % thi

7、s will clear the figure plot(Vertex(:,1),Vertex(:,2),ro,XY(:,1),XY(:,2),b-) % this will create a plot of both the Vertices and curve, % the vertices will be red o while the curve is blue line % if you are impatient you can save the file and run the BCon=1 -2 1;-2 2 0;1 0 0; % our 3 X 3 constant Matr

8、ix for i = 1:1:50 % for loop 1 - 50 insteps of 1 par = (i - 1)/49; XY(i,:) = par2 par 1*BCon*Vertex; end % yep! we have created our data,% we will display the vertices and the curve using MATLABs built-in graphic functions clf % this will clear the figure plot(Vertex(:,1),Vertex(:,2),ro,XY(:,1),XY(:

9、,2),b-) % this will create a plot of both the Vertices and curve, % the vertices will be red o while the curve is blue line % if you are impatient you can save the file and run the % script agin in MATLAB line(Vertex(:,1),Vertex(:,2),color,g) % add the control polygon. xlabel( x value) ;ylabel (y va

10、lue) ; title(Square Bezier Curve) legend(Vertex,Curve,Control Polygon) % you can move the legend on the plot,然后,在命令行定义Bez2Vertex= 0 0 ; 0.3 0.7 ; 1.0 0.2,即定义 , , ,再在命令行输入bezier2(Bez2Vertex)则可得到如下的图形: % if you are impatient you can save the file and run the % script agin in MATLAB line(Vertex(:,1),Ve

11、rtex(:,2),color,g) % add the control polygon. xlabel( x value) ;ylabel (y value) ; title(Square Bezier Curve) legend(Vertex,Curve,Control Polygon) % you can move the legend on the plot,然后,在命令行定义Bez2Vertex= 0 0 ; 0.3 0.7 ; 1.0 0.2,即定义 , , ,再在命令行输入bezier2(Bez2Vertex)则可得到如下的图形:,通过改变控制顶点的坐标,即可得到所需要的2次Be

12、zier曲线。 接着我们讨论3次Bezier曲线,我们也采用将表达式改写为矩阵形式的方法,我们得到:,这样,我们就可以用与前面几乎相同的程序来绘制3次Bezier曲线了。如设 , , , ,则可得到如下的3次Bezier曲线。,注意:图中“o”表示控制顶点,直线表示控制多边形,曲线即为Bezier曲线。 当我们需要的曲线较为复杂时,仅用一段Bezier曲线难以表示,此时,我们可以采用拼接的方法,通过重复使用较为简单的绘制方法来绘制出较为复杂的图形。 在拼接时,我们首先要求曲线是连续的,我们以二段3次Bezier曲线的拼接为例来讨论。,设控制顶点分别为 和 ,则当 与 重合时,即能保证曲线连续,

13、我们称两段曲线这样的连续为零阶几何连续,在此基础上,如果我们保证 与 重合,且 和 均不为零且同向,则我们可以保证曲线在 处是在拼接时,我们首先要求曲线是连续的,我们以二段3次Bezier曲线的拼接为例来讨论。,设控制顶点分别为 和 ,则当 与 重合时,即能保证曲线连续,我们称两段曲线这样的连续为零阶几何连续,在此基础上,如果我们保证 与 重合,且 和 均不为零且同向,则我们可以保证曲线在 处是光滑的,此时,我们称该曲线在 处为一阶几何连续。在稍微复杂一点的条件下,我们还可以使曲线在拼接处有相同的曲率。同时,Bezier曲线还有其它的生成算法,这些都留待以后去讨论。,三、实验内容,1设 , , ,绘制以 为顶点的2次Bezier曲线。 2设 , , ,绘制以为顶点的3次Bezier曲线。 3已知有7个顶点 , , , , , , ,用二段3次Bezier曲线来绘制出分别以P0P1P2P3 和P3P4P5P6为控制顶点的Bezier曲线。,4*推导4次Bezier曲线计算公式的矩阵形式。 5*编制MATLAB程序绘制以 , , 为控制顶点的4次Bezier曲线。 6完成实验报告。,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号