How to find vertices of a polygon with convex or concaved sides?

12 次查看(过去 30 天)
I have a bunch of polygons with convex or concaved shapes, and I would like to find the vertices of each point, then plot a line from point to point. In blue, I have the polygon that I generated, and then I manually found the vertices and plotted a line between them.
The polygons can have different numbers of sides (but can be predicted with reasonable accuracy), and can be either concave or convex.
I tried using Ramer-Douglas -Pecker algorithm but it doesn’t work for shapes that are too concave or convex like the one above. My end goal is to find how much out of tolerance the blue line is from flatness.
Heres an example where RPD worked, even then it is slightly offset.
Is there a better approach than what I am currently doing?
  2 个评论
Matt J
Matt J 2025-5-29
编辑:Matt J 2025-5-29
It's not clear how you are defining a "vertex". For a convex polygon, a vertex or extreme point would normally be any point that doesn't lie in the middle of a straight boundary edge. By that definition, every point on your blue square-like shape would be a vertex, because it has no straight edges. Perhaps you instead mean a point with a non-unique tangent line?
Hasan
Hasan 2025-5-29
Thanks for responding, I meant a corner which makes it a non-unique tangent line

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2025-5-29
编辑:Matt J 2025-5-29
This assumes that flattening the sides always gives a convex shape, like in your examples.
load data
qConcave=getCorners(pConcave);
qConvex=getCorners(pConvex);
subplot(1,2,1)
plot(pConcave,'FaceColor','none','EdgeColor','b'); hold on
plot(qConcave,'FaceColor','none','EdgeColor','r'); hold off
subplot(1,2,2)
plot(pConvex,'FaceColor','none','EdgeColor','b'); hold on
plot(qConvex,'FaceColor','none','EdgeColor','r'); hold off
function pOut=getCorners(pIn, N,tol)
arguments
pIn polyshape
N=1000;
tol=5;
end
theta=linspace(0,360,N+1); theta(end)=[];
V=pIn.Vertices;
M=size(V,1);
[~,I]=max( V*[cosd(theta); sind(theta)] ,[],1,'linear');
T=zeros(M,N);
T(I)=1;
counts = sum(T,2);
j=counts>median(counts)+tol;
pOut=polyshape(V(j,:));
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by