Calculate the largest, smallest diameter and the centroid of a polyshape (irregula rpolygon) from a set of points
8 次查看(过去 30 天)
显示 更早的评论
I have a set of points (x,y) for a polyshape (almost 120 coordinates), I want to find the largest, smallest diameter and the centroid of this irregular polygon.
1 个评论
采纳的回答
Matt J
2022-9-8
编辑:Matt J
2022-9-8
If the min and max feret diameters are what you want, then one approach would be,
pgon=nsidedpoly(4,'Radius',0.5); %input polyshape
fun=@(theta) feretDiam(pgon.Vertices,theta);
Theta=linspace(-pi,pi,1e4);
%Min Diameter
[~,i0]=min(fun(Theta));
[thetamin,minDiam]=fminsearch(@(t)fun(t),Theta(i0));
minDiam
%Max Diameter
[~,i0]=max(fun(Theta));
[thetamax,maxDiam]=fminsearch(@(t)-fun(t),Theta(i0));
maxDiam=-maxDiam
function d=feretDiam(V,theta)
p=V*[cos(theta);sin(theta)];
d=max(p,[],1)-min(p,[],1);
end
14 个评论
Matt J
2022-9-9
Can you please tell me what the problem in this code:
The code doesn't include the lines that compute thetamin and thetamax.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!