MATLAB ヘルプ センター
polyshape の重心
polyshape
[x,y] = centroid(polyin)
[x,y] = centroid(polyin,I)
[x,y] = centroid(polyin) は、polyshape の重心の x 座標と y 座標を返します。
x
y
polyin
例
[x,y] = centroid(polyin,I) は、polyin の I 番目の境界の重心の座標を返します。
I
この構文は、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
各領域の重心を個別に計算するには、2 番目の引数で各領域の境界インデックスを指定します。
[x,y] = centroid(polyin,[1 2]); plot(polyin) hold on plot(x(1),y(1),'r*',x(2),y(2),'r*') hold off
あるいは、最初に領域を個別の polyshape オブジェクトに分離して各領域の重心を計算することもできます。関数 regions を使用して、polyshape オブジェクトの配列を作成します。この配列の各要素は、三角形領域のうちの 1 つを定義する polyshape です。
regions
polyarray = regions(polyin)
polyarray = 2×1 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
double
single
int8
int16
int32
int64
uint8
uint16
uint32
uint64
polyshape の重心の x 座標。スカラー、ベクトル、行列または多次元配列として返されます。入力が polyshape オブジェクトの配列である場合、x には各 polyshape の重心の x 座標が含まれます。
polyshape の重心の y 座標。スカラー、ベクトル、行列または多次元配列として返されます。入力が polyshape オブジェクトの配列である場合、y には各 polyshape の重心の y 座標が含まれます。
すべて展開する
使用上の注意および制限:
コード生成用に動的メモリ割り当てを有効にしなければなりません。
R2017b で導入
area | perimeter | polyshape
area
perimeter
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
ヨーロッパ
アジア太平洋地域
最寄りの営業オフィスへのお問い合わせ