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
總結
以上是生活随笔為你收集整理的matlab 填充 多边形,algorithm – 如何在MATLAB中从无序边数据创建填充多边形?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 驾照c1多少钱啊?
- 下一篇: 但愿人长久的作者是谁啊?