Professional Documents
Culture Documents
Polyprop
Polyprop
Polyprop
function[N] = numsides(x)
if size(x,2) ~= 2
[N] = 0;
error('Invalid Input (Matrix must have 2 columns)'); % Error message if inpu
t matrix does not have 2 columns
return;
end
if length(x) < 3
[N]=0;
error('Input Invalid (must have at least 3 points)'); % Error message if the i
nput matrix has less than 3 rows (3 coordinates)
else
[N] = length(x); % length(x) equals number of points. Also number of sides
end
end
function[A] = area(x)
a=0;
for i = 1:(length(x)-1);
a = a + abs((x(i,1).*x(i+1,2) - x(i+1,1).*x(i,2))); % Formula for area of a
polygon
end
[A] = .5.*a;
end
function [P] = polyper(x)
per = 0;
for i = 2:length(x)
per = per + (((x(i-1,1)-x(i,1)).^2)+((x(i-1,2)-x(i,2)).^2)).^(1./2);
end
[P] =per + (((x(length(x),1)-x(1,1)).^2)+(((x(length(x),2)-x(1,2)).^2))).^(1./2)
;
end
function[C] = polycen(x)
Cx = 0;
A= area(x);
b = length(x)-1;
for i = 1:b;
Cx=Cx+((x(i,1)+x(i+1,1)).*(((x(i,1)).*(x(i+1,2)))-((x(i+1,1)).*(x(i,2)))));
%summation for finding the horrizontial center of the polygon
end