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

5 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

ha ha
ha ha am 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

Weitere Antworten (0)

Kategorien

Mehr zu Computational Geometry finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by