I was recently asked to find an algorithm to calculate the area of a polygon. I was given the co-ordinates of the vertices in order and I was told to assume that the polygon did not intersect itself. I was able to come up with some solution which involved triangulating the polygon, however that solution was no good as it would not work with certain types of polygons. How would you come up with this algorithm? Remember that your solution has to also work for polygons that are wierdly shaped. You cannot assume that the polygon is convex. Here are some examples….

Suppose the vertices of the polygon are given by where the n^{th} set of co-ordinates is equal to the first, then the area of the polygon is given by the nice formula

.
A really nice solution to this problem is using Green’s Theorem. This theorem equates a line integral around the boundary of a simple region to a double integral. The theorem states that if **C** is a piecewise smooth, simple, closed curve in a plane and it encloses a region **D**, then

If we can choose **L** and **M** such that , then the double integral on the right hand side in Green’s Theorem will just calculate the area of the region **D**. One option is to take and .

If **D** is the polygon and **C** is the boundary, all we need to do to calculate the area of **D** is to calculate the line integral on the left hand side in Green’s Theorem. Consider the path integral from to of . The path is parametrized by a function from to the line joining to , and is given by

So the path integral becomes

So we are integrating from 0 to 1, the function

This simplifies to

and this is simply

. So if we take the line integral over the closed path

**C**, we get the formula for the area which is written above. Of course, if we get a negative number for the area, this would mean that

**C** was not positively oriented and we should take the absolute value to get the area.

Source: Area Measurement: Planimeters & Green’s Theorem