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

4 次查看(过去 30 天)
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

采纳的回答

ha ha
ha ha 2019-5-18
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computational Geometry 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by