• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            Plot B-Spline Curve by MATLAB

            Posted on 2011-12-30 18:02 eryar 閱讀(5313) 評論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE
            1. Plot B-Spline Basis Function

            When draw Bezier curve, you only need to know Bernstein basis function, life was easier.Bernstein basis function solely as a function of the number of control points. Now you have a lot more flexibility, but you also have a lot more to worry about. In addition to control points, the B-Spline basis function must account for the degree of the cruve, as well as the ranges defined by the knot vector. The resulting basis functions are defined not by Bernstein polynomials, but by the Cox-de Boor recursion formulas. [Ref. : Focus on Cruves and Surfaces]

            當畫Bezier曲線時,事情要簡單些,因Bezier曲線由Bernstein基函數確定,而Bernstein基函數只與控制頂點數有關。當畫B-Spline曲線時,有了更多的靈活性,即有了局部修改能力,但是你需要考慮的事就更多了。除了控制頂點外,B-Spline曲線的基函數必須解釋曲線的次數和節點矢量定義的范圍。即B-Spline曲線的基函數由Cox-de Boor遞歸方法定義:

            B-Spline Basis Function

            Imagine I want to draw a fourh-order(k=4) cubic curve with 4 control points and I choose a knot vector of [x]=[0,0,0,0,1,1,1,1]. The knot vector forces each control point to affect the entire curve.

            假如我想畫一個四個控制頂點形成的四階三次曲線,選擇節點矢量為[x]=[0,0,0,0,1,1,1,1]。節點矢量迫使每個控制頂點的改變影響到整個曲線。

            使用B樣條基函數的遞歸公式畫出各階基函數的圖形。MATLAB代碼如下:

               1:  %-------------------------------------------------------------------------
               2:  % Imagine I want to draw a fourth-order cubic curve with 4 control points
               3:  % and I choose a knot vector of [x]=[0,0,0,0,1,1,1,1].
               4:  %-------------------------------------------------------------------------
               5:   
               6:  t=0:0.01:1;    % knot vector range
               7:   
               8:  %-------------------------------------------------------------------------
               9:  % 1. First-order basis functions for k=4 [x]=[0,0,0,0,1,1,1,1]
              10:  % N11=0;
              11:  % N21=0;
              12:  % N31=0;
              13:  % N41=1;
              14:  %-------------------------------------------------------------------------
              15:   
              16:  N11=0;
              17:  N21=0;
              18:  N31=0;
              19:  N41=1;
              20:   
              21:  subplot(2,2,1);
              22:  plot(t,N11,t,N21,t,N31,t,N41);
              23:   
              24:  %-------------------------------------------------------------------------
              25:  % 2. Second-order basis functions for k=4 [x]=[0,0,0,0,1,1,1,1]
              26:  % N12=0;
              27:  % N22=0;
              28:  % N32=1-t;
              29:  % N42=t;
              30:  %-------------------------------------------------------------------------
              31:   
              32:  N12=0;  
              33:  N22=0;  
              34:  N32=1-t;
              35:  N42=t; 
              36:   
              37:  subplot(2,2,2);
              38:  plot(t,N12,t,N22,t,N32,t,N42)
              39:   
              40:  %-------------------------------------------------------------------------
              41:  % 3. Third-order basis functions for k=4 [x]=[0,0,0,0,1,1,1,1]
              42:  % N13=0;
              43:  % N23=(1-t)^2;
              44:  % N33=2t(1-t);
              45:  % N43=t^2;
              46:  %-------------------------------------------------------------------------
              47:   
              48:  N13=0;
              49:  N23=(1-t).^2;
              50:  N33=2*t.*(1-t);
              51:  N43=t.^2;
              52:   
              53:  subplot(2,2,3);
              54:  plot(t,N13,t,N23,t,N33,t,N43);
              55:   
              56:  %-------------------------------------------------------------------------
              57:  % 4. Fourth-order basis functions for k=4 [x]=[0,0,0,0,1,1,1,1]
              58:  % N14=(1-t)^3;
              59:  % N24=3t(1-t)^2;
              60:  % N34=3(1-t)t^2;
              61:  % N44=t^3;
              62:  %-------------------------------------------------------------------------
              63:   
              64:  N14=(1-t).^3;
              65:  N24=3*t.*(1-t).^2;
              66:  N34=3*(1-t).*t.^2;
              67:  N44=t.^3;
              68:   
              69:  subplot(2,2,4);
              70:  plot(t,N14,t,N24,t,N34,t,N44);
            .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

            用MATLAB畫出各階基函數如下圖所示:

            B-Spline basis functions graphics by MATLAB

            三次均勻B樣條基函數Ni,3(u)的圖形由MATLAB生成如下所示:

            Cubic B-Spline Basis Function by MATLAB

            生成此圖形的MATLAB代碼如下:

               1:  %------------------------------------------------------------------------------
               2:  % 均勻B樣條基最簡單的形式是取節點為整數:Ti=i(i=0,1,2,...,n), 
               3:  % 令:t-ti=u,則參數u的取值范圍為[0,1]。則得Ni,3(u)如下式:
               4:  %            | u^3 / 6;                      u=[0,1]
               5:  %            | (-3u^3 + 3u^2 + 3u + 1) / 6;  u=[0,1]
               6:  % Ni,3(u)  = | (3u^3 - 6u^2 + 4) / 6;        u=[0,1]
               7:  %            | (-u^3 + 3u^2 - 3u + 1) / 6;   u=[0,1]
               8:  %            
               9:  %------------------------------------------------------------------------------
              10:   
              11:  u=0:0.01:1;
              12:  N03=u.^3/6;
              13:  N13=(-3*u.^3 + 3*u.^2 + 3*u + 1)/6;
              14:  N23=(3*u.^3 - 6*u.^2 + 4) / 6;
              15:  N33=(-u.^3 + 3*u.^2 - 3*u + 1) / 6;
              16:   
              17:  line(u, N03, 'Color', 'r');
              18:  line(u+1, N13, 'Color', 'g');
              19:  line(u+2, N23, 'Color', 'b');
              20:  line(u+3, N33, 'Color', 'y');
            .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

             

            2. Plot B-Spline Curve

            已知平面上五個頂點矢量V0(0,1), V1(1,1), V2(1,0), V3(1,-1), V4(2,-1), 要求構造一條三次均勻B樣條曲線,并做出圖形.

            使用MATLAB代碼如下:

               1:  %-----------------------------------------------------------
               2:  % Plot Cubic Uniform B-Spline Curve.
               3:  % Just for Testing, Welcome your advice: eryar@163.com
               4:  %
               5:  % Date : 2011-12-28 21:31
               6:  % 
               7:  %-----------------------------------------------------------
               8:   
               9:  % Knot Vector range.
              10:  u=0:0.01:1;
              11:   
              12:  % Control Points.
              13:  % You can change the control point's number and value
              14:  % to test the effect.
              15:  V0=[0 1];
              16:  V1=[1 1];
              17:  V2=[1 0];
              18:  V3=[1 -1];
              19:  V4=[2 -1];
              20:   
              21:  % Basis Functions.
              22:  N03=(-u.^3 + 3*u.^2 - 3*u + 1) / 6;
              23:  N13=(3*u.^3 - 6*u.^2 + 4) / 6;
              24:  N23=(-3*u.^3 + 3*u.^2 + 3*u + 1)/6;
              25:  N33=u.^3/6;
              26:   
              27:  % Calculate every segment.
              28:  r0x=N03 * V0(1) + N13 * V1(1) + N23 * V2(1) + N33 * V3(1);
              29:  r0y=N03 * V0(2) + N13 * V1(2) + N23 * V2(2) + N33 * V3(2);
              30:  r1x=N03 * V1(1) + N13 * V2(1) + N23 * V3(1) + N33 * V4(1);
              31:  r1y=N03 * V1(2) + N13 * V2(2) + N23 * V3(2) + N33 * V4(2);
              32:   
              33:  % Plot the Control Polygon.
              34:  plot(V0(1), V0(2), 'Marker', 'o'); hold on;
              35:  plot(V0(1), V0(2), 'Marker', 'o'); hold on;
              36:  plot(V1(1), V1(2), 'Marker', 'o'); hold on;
              37:  plot(V2(1), V2(2), 'Marker', 'o'); hold on;
              38:  plot(V3(1), V3(2), 'Marker', 'o'); hold on;
              39:   
              40:  % Plot the Uniform B-Spline Curve.
              41:  line('XData', r0x, 'YData', r0y, 'Color', 'r');
              42:  line('XData', r1x, 'YData', r1y, 'Color', 'g');

            .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } 生成圖形如下所示:

            Cubic Uniform B-Spline by MATLAB

            如圖所示,B樣條曲線由兩段組成,控制頂點由“0”標出。

            試求由特征頂點V0=[-1,1], V1=[1,1], V2=[1,-1], V3=[-1,-1]決定的閉合的三次均勻B樣條曲線,并做出圖形。適當修改上述MATLAB代碼,即可得到所求B樣條曲線,如下圖所示:

            Closed Control Points B-Spline Curve

             

            3.結論:

            對于均勻B樣條基函數,由于節點矢量均勻遞增,所以在每兩個節點組成的區間的距離相等。利用基函數的的遞推公式可以計算出每個區間上的函數表達式。對于上例中的均勻B樣條基每個區間取值范圍都是從0到1,通過偏移X軸,可畫出B樣條的基函數。

            通過MATLAB畫出B樣條曲線的基函數,操作簡單,便于對B樣條基函數的理解。在理解B樣條基函數后,會對B樣條曲線的理解更加深刻。繼續加油??!

            国产精品女同一区二区久久| 久久无码人妻精品一区二区三区| 国产成人综合久久精品红| 日日狠狠久久偷偷色综合免费| 亚洲一级Av无码毛片久久精品| 亚洲第一极品精品无码久久| 日韩精品国产自在久久现线拍 | 亚洲精品乱码久久久久久久久久久久| 7777久久久国产精品消防器材| 久久婷婷国产麻豆91天堂| 亚洲精品99久久久久中文字幕| 91精品国产高清久久久久久io | 久久精品国产清高在天天线| 亚洲国产日韩欧美综合久久| 97超级碰碰碰久久久久| 久久99热这里只有精品国产| 国产91久久综合| 久久精品国产精品青草| 人妻精品久久无码区| 亚洲国产精品无码久久SM| 久久久不卡国产精品一区二区| 国产精品久久毛片完整版| 一本色道久久88精品综合| 日韩十八禁一区二区久久| 国产一级持黄大片99久久| 一本久久a久久精品vr综合| 中文成人无码精品久久久不卡 | 国产精品亚洲综合专区片高清久久久 | 久久av无码专区亚洲av桃花岛| 亚洲伊人久久综合中文成人网| 精品人妻伦一二三区久久| 久久婷婷五月综合成人D啪| 久久国产精品国语对白| 国产精品禁18久久久夂久| 亚洲精品无码久久久影院相关影片 | 99久久免费国产精品| 狠狠精品久久久无码中文字幕 | 日批日出水久久亚洲精品tv| 国产激情久久久久影院小草| 久久99精品久久久久久9蜜桃 | 中文国产成人精品久久不卡|