1. Overview

There exist lots of formulas to compute the area of different mathematical shapes. A polygon consists of a finite number of connected straight-line segments. Also, we can represent it as a set of consequential points that form the entire polygon.

There are different formulas to compute the area of regular polygons and several techniques for decomposition. However, the area of non-regular polygons is a bit hard to compute.

In this tutorial, we’ll learn how to calculate the area of an arbitrary 2D polygon. Also, we’ll use some basic operation of linear algebra.

2. Main Definitions and Operations

2.1. Vector

A vector in a 2D space is a geometric object. For points \mathbf{A} and \mathbf{B} a vector \mathbf{\upsilon} is a displacement from \mathbf{A} to \mathbf{B}. A displacement is both direction and distance:

A 2D-vector is represented as an object \upsilon = (a_{1}, a_{2}). And if A  and B have coordinates (x_{1}, y_{1}) and (x_{2}, y_{2}) respectively, then the vector is \upsilon = (x_{2} - x_{1}, y_{2} - y_{1}).

2.2. Matrix and Determinant

We may assume the matrix to be a 2D array of numbers. The matrix has m rows and n columns. And if m = n then the matrix is square. Importantly, for square matrices exist a special number, called the determinant.

We can calculate the determinant of a matrix in several ways. However, in this article, we need to have knowledge about computing the determinant of a 2 \times 2 matrix. We can compute the determinant of such a matrix by firstly calculating the product of the top-left-to-bottom-right diagonal. This is also called the main diagonal. And then we have to subtract the product of bottom-left-to-top-right diagonal from the main diagonal one.

For instance: \begin{vmatrix}a&b\\c&d\end{vmatrix} = a \times d - b \times c.

3. Area of Triangle

Importantly, the triangle is a polygon with 3 vertices. Firstly, we’ll show how to compute the area of a triangle. Linear algebra produces simple formulas for the area of a parallelogram and triangle. To compute them, we only have to know their vertices coordinates on a 2D-surface.

So, suppose we have a parallelogram:

To compute the area of a parallelogram, we can compute: S_{ABDC} = |\upsilon||\omega|\sin{\phi}. Also, we can refer to linear algebra and compute the determinant of a square matrix, consisting of vectors \upsilon and \omega as columns: S_{ABDC} = \begin{vmatrix} \upsilon \times \omega\end{vmatrix}.

Similarly, the area of the triangle can be calculated as: S_{ABC} = 1 / 2 * \begin{vmatrix} \upsilon \times \omega\end{vmatrix}.

For instance, let’s take the coordinates of a triangle and compute its area:

 

S_{ABC} = 1 / 2 * \begin{vmatrix} \upsilon \times \omega\end{vmatrix} = 1/2 * \begin{vmatrix}(B - A) \times (C - A)\end{vmatrix}.

S_{ABC} = 1 / 2 * \begin{vmatrix}(3 - 0)&(6 - 0)\\(6 - 1)&(2 - 1)\end{vmatrix} = 1/2 * \begin{vmatrix}3&6\\5&1\end{vmatrix} = 1/2 * (3 * 1 - 5 * 6) = -27 / 2.

The area is negative as we used vectors \upsilon and \omega ordered clockwise. If we use them ordered counter-clockwise then the area will be positive:

S_{ABC} = 1 / 2 * \begin{vmatrix}(6 - 0)&(3 - 0)\\(2 - 1)&(6 - 1)\end{vmatrix} = 1/2 * \begin{vmatrix}6&3\\1&5\end{vmatrix} = 1/2 * (6 * 5 - 1 * 3) = 27 / 2.

This formula for area is a very efficient computation. Moreover, we may notice that it involves no roots and no trigonometric functions. There are just two multiplications, five additions, and possibly one division by two.

4. Area of Polygon

4.1. Idea of Computation

Similarly, there also exists a method to compute the area of the 2D polygon. Remember, the polygon is called simple when it has no self-intersections. The simple polygon with \mathbf{n} vertices can be decomposed to \mathbf{n} triangles. Thus, we can compute all the signed areas of triangles of the decomposed polygon and sum up all the areas to get the area of the entire polygon. Importantly, the area of the polygon can be either positive or negative as well. So, it depends on the chosen point for decomposition and order of the vertices.

Let’s now go deeply with an explanation of calculations. Let P be an arbitrary point. A_{0}, A_{1} ... A_{n - 1} are the vertices of the polygon. We can compute the area as the sum of all areas of triangles \triangle P A_{i} A_{i + 1}. Importantly, we assume that A_{0} = A_{n - 1} to close the polygon.

4.2. Why It Works

Remember, the orientation of points of each triangle in decomposed polygon matters. Let’s look at the example of the polygon and point P:

We have to compute the area of five triangles: \triangle P A_{0} A_{1}, \triangle P A_{1} A_{2}, \triangle P A_{2} A_{3}, \triangle P A_{3} A_{4}, \triangle P A_{4} A_{0}.

As we may notice, the orientation of the first 4 triangles is counter-clockwise. Therefore, the area of these triangles will be positive. But, we see, that we compute the area of extra space, which is not the polygon area. However, triangles \triangle P A_{4} A_{0} is oriented clockwise. Thus, its area will be negative and will compensate for extra areas.

4.3. Formula to Compute the Polygon Area

To make the final computation formula more explicit, we may choose a specific point P(0, 0). Assume we have a polygon represented with the set of n points A_{0}, A_{1} ... A_{n - 1}. Thus, the formula that computes the area of the polygon:

S_{polygon} = 1 / 2 \times \sum\limits_{i=0}^{n - 1} (x_{i} * y_{i + 1} - y_{i} * x_{i + 1}), where \upsilon_{i} = (x_{i}, y_{i}) with i\mod n.

This is the sum of all triangle areas, that can be formed with each line segment of a polygon. Remember, we have to include all polygon edges, and the last triangle of the sum will be triangle \triangle P A_{n - 1} A_{0}. Thus, the index i = i_{actual}\mod n.

5. Green’s Formula

Finally, let’s prove the above formula. Referring to mathematical analysis, we should know about Green’s Theorem.

Let C be our polygon line segments. Let D be a region, bounded with C. Notice, D is our target region. The goal is to compute its area A. Suppose P(x, y) and Q(x, y) are functions, defined on D. Then, Green’s Theorem states:

\int_C\left(P(x,y)dx+Q(x,y)dy\right) = \int\!\!\!\int_D\left(\frac{\partial}{\partial x}Q(x,y)-\frac{\partial}{\partial y}P(x,y)\right)\,dA

So, in order to compute the area of polygon A, we need to choose P(x, y) and Q(x, y) such that: \frac{\partial}{\partial x}Q(x,y)-\frac{\partial}{\partial y}P(x,y) = 1. The appropriate choice is P(x, y) = 0 and Q(x, y) = x. Thus, if A is our target polygon area, the formula transforms to A = \int_C xdy.

Importantly, C is our polygon line segments C_{0}, C_{1} ... C_{n - 1} and C = C_{0} \cup C_{1} \cup ... \cup C_{n - 1}. And the area: A = \int_C xdy = \int_{C_{0}} xdy + \int_{C_{1}} xdy+ ... + \int_{C_{n - 1}} xdy. Also, we assume all line segments are oriented counter-clockwise.

To compute each integral in the sum, we can represent each line segment: C_{i}  = (x_{i + 1} - x_{i}) * t + x_{i}, (y_{i + 1} - y_{i}) * t + y_{i}, 0 \leq t \leq 1.

The last thing that we need to do is to substitute the parameterization:

\int_{C_{i}} xdy = \int_{0}^{1} {((x_{i + 1} - x_{i}) * t + x_{i}) * ( y_{i + 1} - y_{i})}dt.

And the final formula, that computes the target polygon area:

A = 1 / 2 \times \sum\limits_{i=0}^{n - 1} {(x_{i + 1} - x_{i}) * ( y_{i + 1} - y_{i})} = 1 / 2 \times \sum\limits_{i=0}^{n - 1} (x_{i} * y_{i + 1} - y_{i} * x_{i + 1}).

6. Example of the Polygon Area Calculation

For instance, let’s take the polygon below and use the above formula to compute its area:

S_{polygon} = 1 / 2 \times\sum\limits_{i=0}^{n - 1} (x_{i} * y_{i + 1} - y_{i} * x_{i + 1}) = 1 / 2 \times (\begin{vmatrix} A_{1} \times A_{2}\end{vmatrix} + \begin{vmatrix} A_{2} \times A_{3}\end{vmatrix} + \begin{vmatrix} A_{3} \times A_{4}\end{vmatrix} + \begin{vmatrix} A_{4} \times A_{5}\end{vmatrix} + \begin{vmatrix} A_{5} \times A_{1}\end{vmatrix}) = 1 / 2 \times (\begin{vmatrix}7&8\\1&5\end{vmatrix} + \begin{vmatrix}8&5\\5&4\end{vmatrix} + \begin{vmatrix}5&2\\4&5\end{vmatrix} + \begin{vmatrix}2&1\\5&1\end{vmatrix} + \begin{vmatrix}1&7\\1&1\end{vmatrix}) = 1 / 2 \times ((7 * 5 - 1 * 8) + (8 * 4 - 5 * 5) + (5 * 5 - 4 * 2) + (2 * 1 - 5 * 1) + (1 * 1 - 7 * 1)) = 1 / 2 \times (30 - 8 + 32 - 25 + 25 - 8 + 2 - 5 + 1 - 7) = 37 / 2.

Importantly, we’ve chosen a point P (0, 0) for calculating the areas.

We may notice, that during the calculations areas of \triangle P A_{0} A_{1}, \triangle P A_{1} A_{2}, \triangle P A_{2} A_{3} are positive. But, areas of \triangle P A_{3} A_{4}, \triangle P A_{4} A_{0} are negative. This happens, because our target point P (0, 0) is on the bottom-left from our polygon and the orientation of the points in triangles switches after triangle \triangle P A_{2} A_{3}. As a result, it compensates for extra computed areas.

7. Conclusion

In this article, we’ve introduced a way to calculate the area of a 2D polygon. Moreover, we’ve touched some major topics of linear algebra. Furthermore, we also introduced methods to calculate the area of the triangle and parallelogram, as they are specific types of polygons.

Comments are closed on this article!