re. finding perimeter of a 2D shape
Afficher commentaires plus anciens
Hi, I have coordinates of a 2D shape (x,y) and I am trying to determine the perimeter of the shape. I had initially tried the below code on circles etc, using the alpha shape function and perimeter with a given alpha radius of 2.5 and it worked fine. But my current shape I cant seem to use the alpha radius, as with alpha radius the perimeter is coming as zero. But without it works but I dont know if the result if correct as while plotting the figure seems a bit incomplete ie, the area within the contour is not completely filled. I am attaching the shape file, Thank you, Nithin
the code:
[Data.num] = xlsread('Profgraph.xls', 'sheet2');
nx50 = Data.num(1:end,1 ); ny50 = Data.num(1:end,2);
shp = alphaShape(nx50,ny50);
shp.Alpha=2.5;
plot(shp)
totalperim = perimeter(shp)
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 14 Juin 2018
Is an alpha value of 2.5 going to be appropriate for all data sets? Probably not.
You probably want to use the criticalAlpha and/or alphaSpectrum function to find an appropriate alpha value for your data set. Using the example from the alphaSpectrum page:
% Generate sample data and plot it
th = (pi/12:pi/12:2*pi)';
x1 = [reshape(cos(th)*(1:5), numel(cos(th)*(1:5)),1); 0];
y1 = [reshape(sin(th)*(1:5), numel(sin(th)*(1:5)),1); 0];
x = [x1; x1+15;];
y = [y1; y1];
plot(x,y,'.')
axis equal
hold on
% Build an alphaShape using the default alpha value
shp = alphaShape(x,y);
% Determine alpha values that produce unique shapes
alphaspec = alphaSpectrum(shp);
% Iterate through the alpha values. Show each one in turn
% with a 0.1 second pause between each shape
for k = 1:length(alphaspec)
shp.Alpha = alphaspec(k);
h = plot(shp);
title(sprintf('Alpha value of %.16f', alphaspec(k)));
pause(0.1)
delete(h)
end
The alpha values returned by criticalAlpha are in the alphaspec variable.
1 commentaire
Nithin
le 15 Juin 2018
Catégories
En savoir plus sur Bounding Regions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!