帮助中心帮助中心
对 polyshape 区域进行排序
polyshape
polyout = sortregions(polyin,criterion,direction)
polyout = sortregions(polyin,'centroid',direction,'ReferencePoint',point)
示例
polyout = sortregions(polyin,criterion,direction) 返回根据指定的 criterion 和 direction 对区域进行排序后的 polyshape 对象。例如,polyout = sortregions(polyin,'area','ascend') 返回实心区域与 polyin 相同并按面积升序排列后的 polyshape。
polyin
criterion
direction
polyout = sortregions(polyin,'area','ascend')
polyout = sortregions(polyin,'centroid',direction,'ReferencePoint',point) 返回根据每个区域的矩心到参考点的距离对区域进行排序后的 polyshape。
'centroid'
point
全部折叠
首先对多边形的区域进行排序,以确定和访问每个区域。
创建包含两个实心区域和一个孔的多边形。
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)
根据多边形每个区域的周长按升序对区域进行排序。然后可以使用 regions 函数创建一个 polyshape 对象数组 R,R 的每个元素对应于 polyout 的一个区域。R 的元素与 polyout 的区域按同样的顺序进行索引,因此您可以根据索引来访问和计算每个区域。
regions
R
polyout
polyout = sortregions(polyin,'perimeter','ascend'); R = regions(polyout); plot(R)
smallregion = area(R(1))
smallregion = 0.7541
bigregion = area(R(2))
bigregion = 9.0488
输入 polyshape,指定为标量、向量、矩阵或多维数组。
数据类型: polyshape
'area'
'perimeter'
'numsides'
排序标准,指定为下列值之一:
'area' - 按区域的面积排序。
'perimeter' - 按区域的周长排序。
'numsides' - 按每个区域的边数排序。
'centroid' - 按每个区域的矩心到参考点 (0,0) 的距离排序。
'ascend'
'descend'
排序方向,指定为 'ascend' 或 'descend'。
[0 0]
参考点,指定为二元素行向量。第一个元素是参考点的 x 坐标,第二个元素是 y 坐标。
在 R2017b 中推出
sortboundaries | polyshape | regions
sortboundaries
您点击的链接对应于以下 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:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office