[comp.sys.sgi] Area of a Polygon

davis@bedlam.esd.sgi.com (Tom Davis) (02/05/91)

There's a simple formula to find the (signed) area of a polygon.  The
sign will be positive or negative depending on whether the points
describe a counter-clockwise or clockwise polygon, respectively.

Assume the polygon has n points: (x[0], y[0]), (x[1], y[1]), ... (x[n-1], y[n-1]).
For notational convenience, define x[n] = x[0] and y[n] = y[0].  Then the area
is given by:

           n-1
           __
A =       \     (x[i]*(y[i+1] - y[i]) - y[i]*(x[i+1] - x[i]))/2
          /__
          i = 0

I hope this helps.  If you can't remember the formula (I usually can't),
it's just a trivial application of Stokes Theorem, where the surface is
just the x-y plane.

andru@electron.lcs.mit.edu (Andrew Myers) (02/05/91)

In article <Feb.3.19.12.39.1991.10354@pilot.njin.net> psomu@pilot.njin.net (Prabhakar Somu) writes:
>Hi,
>
>   I am trying to find the area of an arbitrarily shaped polygon
>drawn on the overlay plane on a 4D 70GT(running Irix 3.2). 
[...]

    There's no need to use graphics to find the area of a polygon.
    Given Xi, Yi, the area is


    sum from i=1,n with j=i+1 except j=1 when i=n:

	(1/2) (Xj Yi - Xi Yj)

    Of course, the 1/2 can be factored out.

    This will give negative values for clockwise polygons, if I've
    got the signs right, so take the absolute value if appropriate.

Andrew