Calculate the largest, smallest diameter and the centroid of a polyshape (irregula rpolygon) from a set of points

5 ビュー (過去 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
Matt J 2022 年 9 月 8 日
編集済み: Matt J 2022 年 9 月 8 日
It is not self-evident how you are defining "largest and smallest diameter". Do you mean the minimum and maximum feret diameter?

サインインしてコメントする。

採用された回答

Matt J
Matt J 2022 年 9 月 8 日
編集済み: Matt J 2022 年 9 月 8 日
For the centroid, polyshape has a method centroid.
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
minDiam = 0.7071
%Max Diameter
[~,i0]=max(fun(Theta));
[thetamax,maxDiam]=fminsearch(@(t)-fun(t),Theta(i0));
maxDiam=-maxDiam
maxDiam = 1.0000
function d=feretDiam(V,theta)
p=V*[cos(theta);sin(theta)];
d=max(p,[],1)-min(p,[],1);
end
  14 件のコメント
Tesla
Tesla 2022 年 9 月 9 日
Can you please tell me what the problem in this code:
pgon=nsidedpoly(4,'Radius',0.5); %input polyshape
fun=@(theta) feretDiam(pgon.Vertices,theta);
[~,xmin,ymin]=fun(thetamin);
Unrecognized function or variable 'thetamin'.
[~,xmax,ymax]=fun(thetamax);
plot(pgon);
line(xmin,ymin,'LineStyle','--');
line(xmax,ymax,'LineStyle','--');
function [d,xb,yb]=feretDiam(V,theta)
udir=[cos(theta);sin(theta)];
p=V*udir;
umax=max(p,[],1);
umin=min(p,[],1);
d=umax-umin;
if nargout>1
umax=udir.*umax;
umin=udir.*umin;
xb=[umin(1,:);umax(1,:)];
yb=[umin(2,:);umax(2,:)];
end
end
Matt J
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 ExchangeElementary Polygons についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by