Quick and easy way to calculate the area of any polygon — the shoelace formula

In my spare time, I enjoy watching a number of math channels on youtube, such as Numberphile, PBS infinite series,  and standupmaths.  Typically, most of the videos are about number theory or prime numbers and are not very useful to a mechanical engineer.  However, this video from mathologer discusses the shoelace formula for calculating the area of a polygon, which an engineer may find useful for calculating the area of a fluid channel or a beam section (see also the wikipedia entry for the shoelace formula).  It works for any polygon that does not intersect itself.  It may be useful in doing quick hand calculations, and it is easily scripted into a function for a computer to calculate.  One could also make a straight line approximation of a shape with curved lines to estimate its area.

The shoelace formula gets its name from the arrangement of the coordinates and how they are combined to calculate the area.  Arrange the x-y coordinates of the polygon in a (n+1)x2 matrix where the order is determined by a counterclockwise pattern around the perimeter and the starting point is also repeated as the last row in the matrix.

    \begin{equation*} \begin{bmatrix} x_1 & & & y_1 \\ & +\searrow & -\swarrow \\ x_2 & & & y_2 \\ & +\searrow & -\swarrow \\ x_3 & & & y_3 \\ & +\searrow & -\swarrow \\ \dots & & & \dots  \\ & +\searrow & -\swarrow \\ x_n & & & y_n \\ & +\searrow & -\swarrow \\ x_1 & & & y_1 \end{bmatrix} \end{equation*}

Again, notice that the order is counterclockwise and that the first point is repeated in the last line of the matrix (there are n+1 rows if the polygon has n points).

To calculate the area, we add when multiplying down and to the right and subtract pairs when multiplying down and to the left.  That is

    \begin{equation*} A= \begin{matrix} x_1 y_2 + x_2 y_3 + \dots +x_n y_1 \\ \\ - y_1 x_2 - y_2 x_3 - \dots - y_1 x_1 \end{matrix} \end{equation*}

In the example polygon shown above, we have

    \begin{equation*} \begin{bmatrix} 48 & 2 \\ 68 & 25 \\ 104 & 35 \\ 72 & 33 \\ 72 & 50 \\ 24 & 26 \\ 48 & 2 \end{bmatrix} \end{equation*}

Performing the calculation, we obtain

    \begin{equation*} A= \begin{matrix} 48 \times 25 + 68 \times 35 +104 \times 33 +72 \times 50 +72 \times 26 +24 \times 2 \\ \\ -2\times 68 -25\times 104 -35\times 72 -33\times 72 -50\times 24 -26\times 48 \end{matrix} \end{equation*}

    \begin{equation*} A = 12532-10080 = 2452 \end{equation*}

 

Leave a Reply

Your email address will not be published. Required fields are marked *