If you have a few years of experience in Computer Science or research, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

## 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 and a vector is a displacement from to . A displacement is both direction and distance:

A 2D-vector is represented as an object . And if   and have coordinates and respectively, then the vector is .

### 2.2. Matrix and Determinant

We may assume the matrix to be a 2D array of numbers. The matrix has rows and columns. And if 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 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: .

## 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: . Also, we can refer to linear algebra and compute the determinant of a square matrix, consisting of vectors and as columns: .

Similarly, the area of the triangle can be calculated as: .

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

.

.

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

.

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 vertices can be decomposed to 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 be an arbitrary point. are the vertices of the polygon. We can compute the area as the sum of all areas of triangles . Importantly, we assume that 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 :

We have to compute the area of five triangles: .

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 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 . Assume we have a polygon represented with the set of points . Thus, the formula that computes the area of the polygon:

, where with .

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 . Thus, the index .

## 5. Green’s Formula

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

Let be our polygon line segments. Let be a region, bounded with . Notice, is our target region. The goal is to compute its area . Suppose and are functions, defined on . Then, Green’s Theorem states:

So, in order to compute the area of polygon , we need to choose and such that: . The appropriate choice is and . Thus, if is our target polygon area, the formula transforms to .

Importantly, is our polygon line segments and . And the area: . Also, we assume all line segments are oriented counter-clockwise.

To compute each integral in the sum, we can represent each line segment: , , .

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

.

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

.

## 6. Example of the Polygon Area Calculation

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

.

Importantly, we’ve chosen a point for calculating the areas.

We may notice, that during the calculations areas of are positive. But, areas of are negative. This happens, because our target point is on the bottom-left from our polygon and the orientation of the points in triangles switches after triangle . 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.

If you have a few years of experience in Computer Science or research, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.