centroid
polyshape
的矩心
说明
示例
多边形的矩心
计算包含多个区域的多边形的矩心。
创建包含两个实心区域的多边形,然后计算多边形的矩心。
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
要分别计算每个区域的矩心,请在第二个参量中指定每个区域的边界索引。
[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
对象组成的数组,数组中的每个元素是一个 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
输入参数
polyin
— 输入 polyshape
标量 | 向量 | 矩阵 | 多维数组
输入 polyshape
,指定为标量、向量、矩阵或多维数组。
数据类型: polyshape
I
— 边界索引
整数标量 | 整数向量
边界索引,指定为整数标量或由整数组成的向量。I
的每个元素对应于输入 polyshape
的一个边界。
数据类型: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
输出参量
x
— x 坐标
标量 | 向量 | 矩阵 | 多维数组
polyshape
的矩心的 x 坐标,以标量、向量、矩阵或多维数组形式返回。如果输入是由 polyshape
对象组成的数组,则 x
包含每个 polyshape
的矩心的 x 坐标。
y
— y 坐标
标量 | 向量 | 矩阵 | 多维数组
polyshape
的矩心的 y 坐标,以标量、向量、矩阵或多维数组形式返回。如果输入是由 polyshape
对象组成的数组,则 y
包含每个 polyshape
的矩心的 y 坐标。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
必须启用动态内存分配才能进行代码生成。
名称-值对组必须为编译时常量。
版本历史记录
在 R2017b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)