Main Content

2 次元および 3 次元のスプライン曲線の作成

この例では、Curve Fitting Toolbox™ のcscvnコマンドを使用して、2 次元および 3 次元の 3 次スプライン曲線を作成する方法を示します。

点の選択

この例では、点のリストから、その点の出現順に滑らかな曲線を描画する方法を示します。まず、平面の点をランダムにいくつか選択し、"列"ごとに 1 点ずつそれを行列に格納します。

npts = 10; xy = [randn(1,npts); randn(1,npts)]; plot(xy(1,:),xy(2,:),'ro','LineWidth',2); text(xy(1,:), xy(2,:),[repmat(' ',npts,1), num2str((1:npts)')]) ax = gca; ax.XTick = []; ax.YTick = [];

Figure contains an axes object. The axes object contains 11 objects of type line, text.

点の接続

次に、cscvnコマンドを使用して曲線を作成し、fnpltを使用してそれをプロットします。

holdonfnplt(cscvn(xy),'r',2) holdoff

Figure contains an axes object. The axes object contains 12 objects of type line, text.

getcurveコマンドを使用して、点のリストを対話的に入力することもできます。

3 次元のスプライン曲線

3 次元のスプライン曲線も同じく簡単に作成できます。今回は、あまりランダムでないものを作成します。まずは点を生成します。

《不扩散核武器条约》= 13;t = linspace(0 8 *π,《不扩散核武器条约》);z = linspace(-1,1,npts); omz = sqrt(1-z.^2); xyz = [cos(t).*omz; sin(t).*omz; z]; plot3(xyz(1,:),xyz(2,:),xyz(3,:),'ro','LineWidth',2); text(xyz(1,:),xyz(2,:),xyz(3,:),[repmat(' ',npts,1), num2str((1:npts)')]) ax = gca; ax.XTick = []; ax.YTick = []; ax.ZTick = []; boxon

Figure contains an axes object. The axes object contains 14 objects of type line, text.

点の接続

次に、cscvnで得られる、これらの点を通る 3 次元のスプライン曲線を示します。リストの最後に最初の点を追加すると、滑らかな "閉じた"曲線が得られます。

holdonfnplt(cscvn(xyz(:,[1:end 1])),'r',2) holdoff

Figure contains an axes object. The axes object contains 15 objects of type line, text.