# v_polygonarea

## PURPOSE

V_POLYGONAREA Calculate the area of a polygon

## SYNOPSIS

function a=v_polygonarea(p)

## DESCRIPTION

    V_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=v_polygonarea(p)
    0002 %V_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: v_polygonarea.m 10865 2018-09-21 17:22:45Z 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 Lesser General Public License as published by
    0022 %   the Free Software Foundation; either version 3 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 Lesser General Public License for more details.
    0029 %
    0030 %   You can obtain a copy of the GNU Lesser General Public License from
    0031 %   https://www.gnu.org/licenses/ .
    0032 %
    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