There's a simple algorithm for calculating the area of a polygon:
1. Choose one point P1. Interpret this point as 3D point by setting the z-coordinate to 0.
2. For all remaining (n-1) points Pi:
- interpret Pi and Pi+1 as 3D points by setting the z-coordinate to 0.
- calculate the vector product (Pi-P1)x(Pi+1-P1)
- add up the resulting vectors
3. the length of the vector sum is the total area of the polygon
The concept behind this is that the length of the vector you get from each vector product corresponds to the area of the triangle of the three involved points. At concave points, however, the vector will point in the opposite direction, and therefore the area will be subtracted rather than added. If you draw a few example polygons you'll see that it is indeed necessary to subtract these areas rather than add them.
P.S.: you don't actually have to introduce 3D vectors, as the vector product will always have it's x and y coordinate at 0, so you only need to calculate the z-coordinate, which happens to be the 2D determinant of the two 2D vectors (Pi-P1) and (Pi+1-P1).
P.P.S.: fixed the index values. See for instance paragraph 2.0.1 in here:
http://www.faqs.org/faqs/graphics/algorithms-faq/[
^]
Another P.S.:
I've tried to pinpoint the source of this algorithm, but found that what I described here is a specialized version that I actually used to determine the orientation of a polygon, not it's area, although it does calculate the area as described. In fact, if you're just interested in the area, the first point can be any point, including (0,0), and the firmula you get, then can be found on various sites, e. g.
http://mathworld.wolfram.com/PolygonArea.html[
^] or here:
https://en.wikipedia.org/wiki/Shoelace_formula[
^]