Algorithm for Area of a closed polygon.

Demian M. Nave dnave at psc.edu
Wed Nov 12 21:23:16 PST 2003


Hi Ted,

> I want to be able to calculate the area inside a closed many-sided
> polygon.

As long as your polygon has no self-crossings or internal holes, this
algorithm is probably the simplest.  It will return twice the _signed_ area
of your polygon:

Let 'vertices' be an array of N pairs (x,y), indexed from 0
Let 'area' = 0.0
for i = 0 to N-1, do
  Let j = (i+1) mod N
  Let area = area + vertices[i].x * vertices[j].y
  Let area = area - vertices[i].y * vertices[j].x
end for
Return 'area'

If the vertices of your polygon are specified in counter-clockwise order
(i.e. by the right-hand rule), then the area will be positive.  Otherwise,
the area will be negative, assuming the polygon has non-zero area to begin
with.

Hope this helps.  Send another note to the mailing list if not. :-)

Cheers,
Demian

-- 
 Demian M. Nave              | dnave at psc.edu        | Ph 412 268-4574
 Pgh. Supercomputing Center  | www.psc.edu/~dnave   | Fx 412 268-8200
 4400 Fifth Avenue           | "When your work speaks for itself, don't
 Pittsburgh, PA 15213        |  interrupt." - Kanin

-------------
The compgeom mailing lists: see
http://netlib.bell-labs.com/netlib/compgeom/readme.html
or send mail to compgeom-request at research.bell-labs.com with the line:
send readme
Now archived at http://www.uiuc.edu/~sariel/CG/compgeom/maillist.html.



More information about the Compgeom-announce mailing list