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

5 visualizaciones (últimos 30 días)
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

Respuesta aceptada

ha ha
ha ha el 18 de Mayo de 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

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by