メインコンテンツ

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

bsplinepolytraj

B スプラインを使用した多項式軌跡の生成

説明

[q,qd,qdd,pp] = bsplinepolytraj(controlPoints,tInterval,tSamples) は、controlPoints で定義される制御多角形に収まる区分的 3 次 B スプライン軌跡を生成します。tInterval で与えられる開始時間から終了時間までの軌跡が等間隔にサンプリングされます。この関数は、入力時間サンプル tSamples における位置、速度、および加速度を返します。また、この関数は、時間に対する多項式軌跡の区分的多項式 pp も返します。

すべて折りたたむ

一連の 2 次元 "xy" 制御点を指定して、関数 bsplinepolytraj を使用します。これらの制御点を使用して、多角形の内側に B スプラインで軌跡が作成されます。軌跡の開始時間と終了時間も指定します。

cpts = [1 4 4 3 -2 0; 0 1 2 4 3 1];
tpts = [0 5];

B スプライン軌跡を計算します。関数は、制御点を使用してウェイポイントを通る多項式の軌跡の位置 (q)、速度 (qd)、加速度 (qdd)、時間ベクトル (tvec)、および多項式係数 (pp) を出力します。

tvec = 0:0.01:5;
[q,qd,qdd,pp] = bsplinepolytraj(cpts,tpts,tvec);

結果をプロットします。制御点とその内側の結果の軌跡を表示します。

figure
plot(cpts(1,:),cpts(2,:),'*--')
hold on
plot(q(1,:),q(2,:))
xlabel("X")
ylabel("Y")
legend("Control Points","B-Spline Trajectory")
axis padded
hold off

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 2 objects of type line. These objects represent Control Points, B-Spline Trajectory.

B スプライン軌跡の各要素の位置をプロットします。これらの軌跡は、時間でパラメーター化された 3 次区分的多項式です。

figure
plot(tvec,q);
hold on
ax = gca;
ax.ColorOrderIndex = 1;
scatter([0:length(cpts)-1],cpts,'*')
xlabel("Time")
ylabel("Position")
title("X- and Y-Trajectories and Control Points")
axis padded
legend("X-positions","Y-positions","X-control points","Y-control points",Location="southwest")
hold off

Figure contains an axes object. The axes object with title X- and Y-Trajectories and Control Points, xlabel Time, ylabel Position contains 4 objects of type line, scatter. These objects represent X-positions, Y-positions, X-control points, Y-control points.

B スプラインで内挿するウェイポイントを作成します。

wpts1 = [0 1 2.1 8 4 3];
wpts2 = [0 1 1.3 .8 .3 .3];
wpts = [wpts1; wpts2];
L = length(wpts) - 1;

制御多角形の内側の点の計算に使用する行列を作成します。

r = zeros(L+1, size(wpts,1));
A = eye(L+1);
for i= 1:(L-1)
    A(i+1,(i):(i+2)) = [1 4 1];
    r(i+1,:) = 6*wpts(:,i+1)';
end

終点をオーバーライドし、r0rL を選択します。

A(2,1:3) = [3/2 7/2 1]; 
A(L,(L-1):(L+1)) = [1 7/2 3/2]; 

r(1,:) = (wpts(:,1) + (wpts(:,2) - wpts(:,1))/2)';
r(end,:) = (wpts(:,end-1) + (wpts(:,end) - wpts(:,end-1))/2)';

dInterior = (A\r)';

完全な制御多角形を作成し、bsplinepolytraj を使用して新しい制御点で多項式を計算します。

cpts = [wpts(:,1) dInterior wpts(:,end)];
t = 0:0.01:1;
q = bsplinepolytraj(cpts, [0 1], t);

結果をプロットします。元のウェイポイント、計算された多角形、および内挿された B スプラインを表示します。

figure;
hold all
plot(wpts1, wpts2, 'o');
plot(cpts(1,:), cpts(2,:), 'x-');
plot(q(1,:), q(2,:));
legend('Original waypoints', 'Computed control polygon', 'B-spline');

Figure contains an axes object. The axes object contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent Original waypoints, Computed control polygon, B-spline.

[1] Farin, Section 9.1

入力引数

すべて折りたたむ

B スプライン軌跡の制御多角形の点。np 列の行列として指定します。ここで、n は軌跡の次元で、p は制御点の数です。

例: [1 4 4 3 -2 0; 0 1 2 4 3 1]

データ型: single | double

軌跡の開始時間と終了時間。2 要素ベクトルとして指定します。

例: [0 10]

データ型: single | double

軌跡の時間サンプル。ベクトルとして指定します。出力の位置 q、速度 qd、および加速度 qdd は、これらの時間間隔でサンプリングされます。

例: 0:0.01:10

データ型: single | double

出力引数

すべて折りたたむ

tSamples で指定された時間サンプルにおける軌跡の位置。ベクトルとして返されます。

データ型: single | double

tSamples で指定された時間サンプルにおける軌跡の速度。ベクトルとして返されます。

データ型: single | double

tSamples で指定された時間サンプルにおける軌跡の加速度。ベクトルとして返されます。

データ型: single | double

区分的多項式。区分的軌跡の各セクションの多項式を定義する構造体として返されます。mkpp を使用して独自の区分的多項式を作成するか、ppval を使用して指定した時間の多項式を評価できます。構造体には次のフィールドが含まれます。

  • form: 'pp'.

  • breaks: 区分的軌跡が形を変える時間の p 要素ベクトル。p はウェイポイントの数です。

  • coefs: 多項式の係数の n(p–1) 行 order 列の行列。n(p–1) は、軌跡の次元と pieces の数の積です。n 行の各セットは、各変動軌跡を記述した多項式の係数を定義します。

  • pieces: p–1。ブレーク数から 1 を引いた値。

  • order:多項式の次数 + 1。たとえば、3 次多項式の次数は 4 です。

  • dim: n.制御点の位置の次元。

参照

[1] Farin, Gerald E. Curves and Surfaces for Computer Aided Geometric Design: A Practical Guide. San Diego, CA: Academic Press, 1993.

拡張機能

すべて展開する

C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。

バージョン履歴

R2019a で導入