How to calculate the perimeter of a polygon without using built-in function in matlab

5 vues (au cours des 30 derniers jours)
clear;clc;
P = [1 1 ;1 2; 2 1 ; 3 1 ;3 5 ; 4 2 ; 4 3 ; 4 4 ; 2 4 ; 1 4 ; 1 3 ];%the original is not in order (random)
% How to calcute the perimeter of boundary from this 2D data?
Capture.PNG

Réponse acceptée

ha ha
ha ha le 18 Mai 2019
clear;clc;
P = [1 1 ;1 2; 2 1 ; 3 1 ;3 5 ; 4 2 ; 4 3 ; 4 4 ; 2 4 ; 1 4 ; 1 3 ];%the original is not in order (random)
hold on;scatter(P(:,1),P(:,2),31,'.k');xlim ([0 7]);ylim ([0 7]);%plot data
x=P(:,1);y=P(:,2);
k = boundary(x,y,1);
X=x(k);
Y=y(k);
plot(X,Y);
points=[X Y];%point in sequence order to compute the perimeter
perimeter = 0;
for i = 1:size(points, 1)-1
perimeter = perimeter + norm(points(i, :) - points(i+1, :));
end
perimeter = perimeter + norm(points(end, :) - points(1, :)); % Last point to first

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by