%
disp(' ');
disp(' quadrilateral_area.m  ver 1.0  June 13, 2012 ');
disp(' ');
disp(' by Tom Irvine  Email: tom@vibrationdata.com ');
disp(' ');
disp(' This program calculates the area of a quadrilateral  ');
disp(' which may be irregular. ');
disp(' ');
%
close all;
clear THM
clear area;
clear x;
clear y;
%
disp(' Select coordinate entry method ');
disp('  1=manual   2=Matlab array ');
icm=input(' ');
disp(' ');
%
if(icm==1)
    for i=1:4
        out1=sprintf(' Enter x%d:  ',i);
        x(i)=input(out1);
        out2=sprintf(' Enter y%d:  ',i);
        y(i)=input(out2);  
        disp(' ')
    end
else
   THM=input(' Enter array name: '); 
   x=THM(:,1);
   y=THM(:,2);
end
%
a=sqrt((x(2)-x(1))^2+(y(2)-y(1))^2);
b=sqrt((x(3)-x(2))^2+(y(3)-y(2))^2);
c=sqrt((x(4)-x(3))^2+(y(4)-y(3))^2);
d=sqrt((x(1)-x(4))^2+(y(1)-y(4))^2);
p=sqrt((x(3)-x(1))^2+(y(3)-y(1))^2);
q=sqrt((x(4)-x(2))^2+(y(4)-y(2))^2);
%
area=0.25*sqrt(4*p^2*q^2-(a^2+c^2-b^2-d^2)^2);
%
out1=sprintf('\n area = %8.4g  \n',area);
disp(out1);
%
figure(1);
xp=[ x(1) x(2) x(3) x(4) x(1) ];
yp=[ y(1) y(2) y(3) y(4) y(1) ];
plot(xp,yp);
title(out1);
grid on;
xlabel('x');
ylabel('y');
%