Home > voicebox > polygonarea.m

polygonarea

PURPOSE ^

POLYGONAREA Calculate the area of a polygon

SYNOPSIS ^

function a=polygonarea(p)

DESCRIPTION ^

POLYGONAREA Calculate the area of a polygon

 Inputs:
    P(n,2) is the polygon vertices

 Outputs:
    A is teh area of teh polygon

 The area is positive if the vertices go anti-clockwise around the polygon.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function a=polygonarea(p)
0002 %POLYGONAREA Calculate the area of a polygon
0003 %
0004 % Inputs:
0005 %    P(n,2) is the polygon vertices
0006 %
0007 % Outputs:
0008 %    A is teh area of teh polygon
0009 %
0010 % The area is positive if the vertices go anti-clockwise around the polygon.
0011 %
0012 
0013 %      Copyright (C) Mike Brookes 2009
0014 %      Version: $Id: polygonarea.m 713 2011-10-16 14:45:43Z dmb $
0015 %
0016 %   VOICEBOX is a MATLAB toolbox for speech processing.
0017 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0018 %
0019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0020 %   This program is free software; you can redistribute it and/or modify
0021 %   it under the terms of the GNU General Public License as published by
0022 %   the Free Software Foundation; either version 2 of the License, or
0023 %   (at your option) any later version.
0024 %
0025 %   This program is distributed in the hope that it will be useful,
0026 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0027 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0028 %   GNU General Public License for more details.
0029 %
0030 %   You can obtain a copy of the GNU General Public License from
0031 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0032 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0034 p(end+1,:)=p(1,:);      % append an extra point
0035 a=0.5*sum((p(1:end-1,1)-p(2:end,1)).*(p(1:end-1,2)+p(2:end,2)),1);
0036 if ~nargout
0037     plot(p(:,1),p(:,2),'b-');
0038     mnx=[1.05 -0.05;-0.05 1.05]*[min(p);max(p)];
0039     set(gca,'xlim',mnx(:,1)','ylim',mnx(:,2)');
0040     title(sprintf('Area = %.2g',a));
0041 end

Generated on Tue 10-Oct-2017 08:30:10 by m2html © 2003