How quickly we forget - basic trig. Calculate the area of a polygon

You will find simple formulae in http://en.wikipedia.org/wiki/Polygon. Look for the various formulae A = ... in the section Area and centroid. You will find the appropriate formula depending whether you know the cartesian coordinates of the polygon vertices or the lengths of the sides and the (exterior) angles at the vertices.


The classic trigonometric formula for the area of the general triangle ABC, with $\overline{AB} = a$, $\overline{BC} = b$ and $\widehat{ABC} = \gamma$ is $$A=\frac{1}{2}ab\sin \gamma$$

Just let $AB$ be the next side of your convex polygon and let $C$ be any point inside it. Iterate over the sides and you should get what you want.

If your polygon is convex you may need to make sure that you detect overlaps between your triangles so that you can discount them appropriately. Even then you may end up overestimating the area of the shape (pardon the horrible image):

enter image description here

Even if you detect the overlap between the red and yellow and orange triangles and remove the overlapping areas from the sum the correct number of times, you're still counting once the white area outside the L shape but inside the red triangle.

What you want to try with convex polygons instead is partitioning the shape in triangles, then summing up those areas. (Personally I haven't studied any such algorithm.)


For regular polygons, the formula is well known. Try the following link: http://www.mathopenref.com/polygonregulararea.html

Or do it yourself. Consider all the triangles determined by the center and two neighbor vertices. Then (if the polygon has $n$ sides) you have $n$ congruent isosceles triangles. Find the area of one of these triangles and then multiply it by $n$.