matlab 填充 多边形,algorithm – 如何在MATLAB中从无序边数据创建填充多边形?

如果多边形为

convex,则可以使用函数

CONVHULL从顶点计算凸包,并使用绘图函数

PATCH绘制多边形.例如:

x = [0 1 0 1]; %# Unordered x coordinates of vertices

y = [0 1 1 0]; %# Corresponding y coordinates of vertices

hullIndices = convhull(x,y); %# Gives vertex indices running counterclockwise

%# around the hull

patch(x(hullIndices),y(hullIndices),'r'); %# Plot the polygon in red

如果您的多边形是凹的,那就变得更加棘手.您必须通过比较它们的端点并以顺时针或逆时针方式对它们进行排序来自行重新排序边线.

x = [0 1 0 1 0.5]; %# Unordered x coordinates of vertices

y = [0 1 1 0 0.5]; %# Corresponding y coordinates of vertices

edgeLines = [1 3;... %# Point 1 connects to point 3

1 4;... %# Point 1 connects to point 4

2 3;... %# Point 2 connects to point 3

2 5;... %# Point 2 connects to point 5

5 4]; %# Point 5 connects to point 4

dt = DelaunayTri(x(:),y(:),edgeLines); %# Create a constrained triangulation

isInside = inOutStatus(dt); %# Find the indices of inside triangles

faces = dt(isInside,:); %# Get the face indices of the inside triangles

vertices = [x(:) y(:)]; %# Vertex data for polygon

hPolygon = patch('Faces',faces,...

'Vertices',vertices,...

'FaceColor','r'); %# Plot the triangular faces in red

上面将显示多边形,边缘线围绕形成它的每个子三角形.如果只想在整个多边形的外部显示边线,可以添加以下内容:

set(hPolygon,'EdgeColor','none'); %# Turn off the edge coloring

xEdge = x(edgeLines).'; %'# Create x coordinates for the edge

yEdge = y(edgeLines).'; %'# Create y coordinates for the edge

hold on; %# Add to the existing plot

line(xEdge,yEdge,'Color','k'); %# Plot the edge in black

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值