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

조회 수: 5 (최근 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