Main Content

centroid

説明

[x,y] = centroid(polyin) は、polyshape の重心の x 座標と y 座標を返します。

[x,y] = centroid(polyin,I) は、polyinI 番目の境界の重心の座標を返します。

この構文は、polyin がスカラーの polyshape オブジェクトである場合のみサポートされます。

すべて折りたたむ

複数の領域がある多角形に関連付けられた重心を計算します。

2 つの固体領域をもつ多角形を作成し、その重心を計算します。

x1 = [0 1 2];
y1 = [0 1 0];
x2 = [2 3 4];
y2 = [1 2 1];
polyin = polyshape({x1,x2},{y1,y2});
[x,y] = centroid(polyin);
plot(polyin)
hold on
plot(x,y,'r*')
hold off

Figure contains an axes object. The axes object contains 2 objects of type polygon, line. One or more of the lines displays its values using only markers

各領域の重心を個別に計算するには、2 番目の引数で各領域の境界インデックスを指定します。

[x,y] = centroid(polyin,[1 2]);
plot(polyin)
hold on
plot(x(1),y(1),'r*',x(2),y(2),'r*')
hold off

Figure contains an axes object. The axes object contains 3 objects of type polygon, line. One or more of the lines displays its values using only markers

あるいは、最初に領域を個別の polyshape オブジェクトに分離して各領域の重心を計算することもできます。関数 regions を使用して、polyshape オブジェクトの配列を作成します。この配列の各要素は、三角形領域のうちの 1 つを定義する polyshape です。

polyarray = regions(polyin)
polyarray = 
  2x1 polyshape array with properties:

    Vertices
    NumRegions
    NumHoles

[x,y] = centroid(polyarray)
x = 2×1

     1
     3

y = 2×1

    0.3333
    1.3333

入力引数

すべて折りたたむ

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

データ型: polyshape

境界インデックス。スカラー整数または整数のベクトルとして指定します。I の各要素は、入力 polyshape の 1 つの境界に対応します。

データ型: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

出力引数

すべて折りたたむ

polyshape の重心の x 座標。スカラー、ベクトル、行列または多次元配列として返されます。入力が polyshape オブジェクトの配列である場合、x には各 polyshape の重心の x 座標が含まれます。

polyshape の重心の y 座標。スカラー、ベクトル、行列または多次元配列として返されます。入力が polyshape オブジェクトの配列である場合、y には各 polyshape の重心の y 座標が含まれます。

拡張機能

バージョン履歴

R2017b で導入