Main Content

sortregions

polyshape の領域の並べ替え

説明

polyout = sortregions(polyin,criterion,direction) は、指定した criteriondirection に従って領域が並べ替えられた polyshape オブジェクトを返します。たとえば、polyout = sortregions(polyin,'area','ascend') は、固体領域が polyin と同じであり、面積の昇順でリストされている polyshape を返します。

polyout = sortregions(polyin,'centroid',direction,'ReferencePoint',point) は、各領域の重心と基準点との距離に基づいて領域が並べ替えられた polyshape を返します。

すべて折りたたむ

多角形の各領域をまず並べ替えて、それらを識別およびアクセスできるようにします。

2 つの固体領域と 1 つの穴がある多角形を作成します。

t = 0.05:0.5:2*pi;
x1 = cos(t);
y1 = sin(t);
x2 = 0.5*cos(t);
y2 = 0.5*sin(t);
x3 = 2*cos(t);
y3 = 2*sin(t);
polyin = polyshape({x1,x2,x3},{y1,y2,y3})
polyin = 
  polyshape with properties:

      Vertices: [41x2 double]
    NumRegions: 2
      NumHoles: 1

plot(polyin)

Figure contains an axes object. The axes object contains an object of type polygon.

この多角形の領域を周囲長に基づいて昇順に並べ替えます。次に、関数 regions を使用して、polyshape オブジェクトの配列 R を作成することができます。R の各要素は polyout の各領域に対応します。R の要素は polyout の領域と同じ順序でインデックス付けされ、このインデックスに基づいて各領域へのアクセスや計算ができるようになります。

polyout = sortregions(polyin,'perimeter','ascend');
R = regions(polyout);
plot(R)

Figure contains an axes object. The axes object contains 2 objects of type polygon.

smallregion = area(R(1))
smallregion = 0.7541
bigregion = area(R(2))
bigregion = 9.0488

入力引数

すべて折りたたむ

入力 polyshape。スカラー、ベクトル、行列または多次元配列として指定します。

データ型: polyshape

並べ替え基準。次の値のいずれかとして指定します。

  • 'area' — 領域の面積の順に並べ替え。

  • 'perimeter' — 領域の周囲長の順に並べ替え。

  • 'numsides' — 各領域の辺の数の順に並べ替え。

  • 'centroid' — 各領域の重心と基準点 (0,0) との距離の順に並べ替え。

並べ替える方向。'ascend' または 'descend' として指定します。

基準点。2 要素の行ベクトルとして指定します。1 番目の要素は基準点の x 座標で、2 番目の要素は y 座標です。

バージョン履歴

R2017b で導入