Main Content

このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。

closestPoint

参照パス上のグローバル点への最近傍点の検索

R2020b 以降

説明

pathPoints = closestPoint(refPath,points) は、指定した各位置 (x,y)、points への参照パス上の最近傍点を検索します。

[pathPoints,inWindow] = closestPoint(refPath,points) は、points 内の対応する xy 座標の各点が検索ウィンドウ内に投影されているかどうかを示す logical ベクトル inWindow をオプションで返します。

[_] = closestPoint(refPath,points,searchWindow) は、最近傍点の検索に使用するパスの区間を定義する非減少行ベクトル searchWindow をオプションで受け入れます。

すべて折りたたむ

一連のウェイポイントから参照パスを生成します。

waypoints = [0 0; 50 20; 100 0; 150 10];
refPath = referencePathFrenet(waypoints);

この参照パスから trajectoryGeneratorFrenet オブジェクトを作成します。

connector = trajectoryGeneratorFrenet(refPath);

パスの原点と、パスに沿って 30 メートルのポイントとの間の 5 秒の軌跡を、フレネ状態として生成します。

initCartState = refPath.SegmentParameters(1,:);
initFrenetState = global2frenet(refPath,initCartState);
termFrenetState = initFrenetState + [30 zeros(1,5)];
frenetTraj = connect(connector,initFrenetState,termFrenetState,5);

この軌跡をグローバル状態に変換します。

globalTraj = frenet2global(refPath,frenetTraj.Trajectory);

この参照パスと軌跡を表示します。

show(refPath);
axis equal
hold on
plot(globalTraj(:,1),globalTraj(:,2),'b')

グローバル点を指定し、参照パス上の最近傍点を求めます。

globalPoints = waypoints(2:end,:) + [20 -50];
nearestPathPoint = closestPoint(refPath,globalPoints);

グローバル点と、参照パス上の最近傍点を表示します。

plot(globalPoints(:,1),globalPoints(:,2),'r*','MarkerSize',10)
plot(nearestPathPoint(:,1),nearestPathPoint(:,2),'b*','MarkerSize',10)

参照パスに沿った最初の 2 つの最近傍点の間の弧の長さを内挿します。

arclengths = linspace(nearestPathPoint(1,6),nearestPathPoint(2,6),10);
pathStates = interpolate(refPath,arclengths);

内挿されたパス上の点を表示します。

plot(pathStates(:,1),pathStates(:,2),'g')
legend(["Waypoints","Reference Path","Trajectory to 30m",...
        "Global Points","Closest Points","Interpolated Path Points"])

Figure contains an axes object. The axes object contains 6 objects of type line. One or more of the lines displays its values using only markers These objects represent Waypoints, Reference Path, Trajectory to 30m, Global Points, Closest Points, Interpolated Path Points.

入力引数

すべて折りたたむ

参照パス。referencePathFrenet オブジェクトとして指定します。

グローバル点。行が [x y] の形式である P 行 2 列の数値行列として指定します。P は点の数です。位置はメートル単位です。

最近傍点を決定するパス上の検索ウィンドウ。2 要素の行ベクトルとして指定します。

出力引数

すべて折りたたむ

参照パス上の最近傍点。行の形式が [x y theta kappa dkappa s] である N 行 6 列の数値行列として返されます。ここで次のようになっています。

  • x y および theta — グローバル座標で表された SE(2) の状態 (x と y はメートル単位、theta はラジアン単位)

  • kappa — 曲率 (半径の逆数、m-1 単位)

  • dkappa — 弧の長さに対する曲率の微分 (m-2 単位)

  • s — 弧の長さ (パスの原点からパスに沿った距離、メートル単位)

N は参照パスに沿ってサンプリングされた点の数です。

points 内の対応する xy 座標に最も近い各点が検索ウィンドウ内に投影されているかどうかを示します。N 要素の logical 列ベクトルとして返されます。N は points 内の点の数です。検索ウィンドウ内に点が投影されている場合は true、ウィンドウの最後にある場合は false です。

拡張機能

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

バージョン履歴

R2020b で導入