1 / 25

实验十一 Bezier 曲线的绘制

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

ban
Download Presentation

实验十一 Bezier 曲线的绘制

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 实验十一 Bezier曲线的绘制

  2. 一、实验目的 • 初步了解Bezier曲线的定义,能利用MATLAB软件绘制二次Bezier曲线和三次Bezier曲线。

  3. 二、相关知识 • Bezier广泛应用于外形设计的参数曲线逼近方法,它通过对一些特定点的控制来控制曲线的形状,我们称这些点为控制顶点。现在我们来给出Bezier曲线的数学表达式。 • 在空间给定 个点 ,称下列参数曲线为次的Bezier曲线。 • 其中 是Bernstein基函数,其表达式为:

  4. 二、相关知识 • 一般称折线 为曲线 的控制多边形;称点 为 的控制顶点。Bezier曲线与其控制多边形的关系可以这样认为:控制多边形 是 的大致形状的勾画; 是对 • 其中 是Bernstein基函数,其表达式为:

  5. 一般称折线 为曲线 的控制多边形;称点 为 的控制顶点。Bezier曲线与其控制多边形的关系可以这样认为:控制多边形 是 的大致形状的勾画; 是对 的逼近。 • Bezier曲线有许多性质,我们这里仅讨论两条: • (1)端点位置 • 我们指出, 和 是 的两个端点,这一点容易从 的表达式得到,即

  6. (2)端点的切线 • Bezier曲线 在 点与边 相切,在点 与边 相切,此性质可以从以下二式得证: • Bezier曲线还有一些其它性质,这些将在《计算机 • 图形学》、《计算几何》等课程中专门讨论。 • Bezier曲线有许多性质,我们这里仅讨论两条: • (1)端点位置 • 我们指出, 和 是 的两个端点,这一点容易从 的表达式得到,即

  7. (2)端点的切线 • Bezier曲线 在 点与边 相切,在点 与边 相切,此性质可以从以下二式得证: • Bezier曲线还有一些其它性质,这些将在《计算机 • 图形学》、《计算几何》等课程中专门讨论。

  8. 现在我们讨论Bezier曲线的MATLAB绘制。先讨论2次Bezier曲线,即 的情形。此时有3个顶点 ,为了在MATLAB中计算方便,我们将Bezier曲线的一般表示式改写为矩阵形式,我们得到:

  9. 这样,对于确定的 ,我们取定区间 中 的 值后,即可计算 的值,注意, 是与 到:

  10. 这样,对于确定的 ,我们取定区间 中的 值后,即可计算 的值,注意, 是与 对应的,如果 是平面上的点即2维坐标,则 也是2维坐标,如果 是空间的点即3维坐标,则 也是3维坐标,因此,对于每一组确定的 可绘制出一条2次Bezier曲线。完成平面2次Bezier曲线的MATLAB程序如下:

  11. 先编制完成Bezier曲线计算和绘制的函数bezier2.m,其参数是控制顶点的坐标。先编制完成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(Vertex) • 对应的,如果 是平面上的点即2维坐标,则 • 也是2维坐标,如果 是空间的点即3维坐标,则 也是3维坐标,因此,对于每一组确定的 可绘制出一条2次Bezier曲线。完成平面2次Bezier曲线的MATLAB程序如下:

  12. 先编制完成Bezier曲线计算和绘制的函数bezier2.m,其参数是控制顶点的坐标。先编制完成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(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,:) = [par^2 par 1]*BCon*Vertex; • end % yep! we have created our data

  13. % 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(:,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 Matrix • for i = 1:1:50 % for loop 1 - 50 insteps of 1 • par = (i - 1)/49; • XY(i,:) = [par^2 par 1]*BCon*Vertex; • end % yep! we have created our data

  14. % 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(:,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 value') ; • title('Square Bezier Curve') • legend('Vertex','Curve','Control Polygon') • % you can move the legend on the plot

  15. 然后,在命令行定义Bez2Vertex=[ 0 0 ; 0.3 0.7 ; 1.0 0.2],即定义 , , ,则可得到如下的图形: • % 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 value') ; • title('Square Bezier Curve') • legend('Vertex','Curve','Control Polygon') • % you can move the legend on the plot

  16. 然后,在命令行定义Bez2Vertex=[ 0 0 ; 0.3 0.7 ; 1.0 0.2],即定义 , , ,则可得到如下的图形:

  17. 通过改变控制顶点的坐标,即可得到所需要的2次Bezier曲线。通过改变控制顶点的坐标,即可得到所需要的2次Bezier曲线。 • 接着我们讨论3次Bezier曲线,我们也采用将表达式改写为矩阵形式的方法,我们得到:

  18. 这样,我们就可以用与前面几乎相同的程序来绘制3次Bezier曲线了。如设 , , , ,则可得到如下的3次Bezier曲线。

  19. 注意:图中“o”表示控制顶点,直线表示控制多边形,曲线即为Bezier曲线。注意:图中“o”表示控制顶点,直线表示控制多边形,曲线即为Bezier曲线。 • 当我们需要的曲线较为复杂时,仅用一段Bezier曲线难以表示,此时,我们可以采用拼接的方法,通过重复使用较为简单的绘制方法来绘制出较为复杂的图形。 • 在拼接时,我们首先要求曲线是连续的,我们以二段3次Bezier曲线的拼接为例来讨论。

  20. 设控制顶点分别为 和 ,则当 与 重合时,即能保证曲线连续,我们称两段曲线这样的连续为零阶几何连续,在此基础上,如果我们保证 与 重合,且 和 均不为零且同向,则我们可以保证曲线在 处是 在拼接时,我们首先要求曲线是连续的,我们以二段3次Bezier曲线的拼接为例来讨论。

  21. 设控制顶点分别为 和 ,则当 与 重合时,即能保证曲线连续,我们称两段曲线这样的连续为零阶几何连续,在此基础上,如果我们保证 与 重合,且 和 均不为零且同向,则我们可以保证曲线在 处是光滑的,此时,我们称该曲线在 处为一阶几何连续。在稍微复杂一点的条件下,我们还可以使曲线在拼接处有相同的曲率。同时,Bezier曲线还有其它的生成算法,这些都留待以后去讨论。

  22. 三、实验内容 • 1.设 , , ,绘制以为顶点的2次Bezier曲线。 • 2.设 , , , 绘制以为顶点的3次Bezier曲线。 • 3.已知有7个顶点 , , • , , , • , ,用二段3次Bezier曲线来绘制出分别以和为控制顶点的Bezier曲线。

  23. 4*.推导4次Bezier曲线计算公式的矩阵形式。 • 5*.编制MATLAB程序绘制以 , , , 为控制顶点的4次Bezier曲线。 • 6.完成实验报告。

More Related