# The Shoelace Formula

This has been hanging around in my ‘to write’ folder for several years.

The tl;dr of the shoelace formula is:

- suppose you have a plane polygon with $n$ vertices
- the vertices of which (in order) are $(x_i, y_i)$ for $i = 0,1,2\dots,(n-1)$
- then the area is $\frac{1}{2}\sum_{i=0}^n x_i y_{(i+1) \mod n} - x_i y_{(i-1) \mod n}$ (*)

That is, you can work out the area of a polygon by ‘shoelacing’ its coordinates - multiply the $x$ coordinate of each point by the difference between the next and previous $y$ values, add up the results and halve.

Nice enough. Why does it work?

I think the proof on the wikipedia page is relatively clear, but I wanted to show a different way.

Let’s start with a triangle - and I’m going to move into three dimensions, so its vertices are at $P_i = (x_i, y_i, 1)$, for $i=0,1,2$.

The volume of the tetrahedron formed by the three points and the origin is:

\[\frac{1}{6}\left| \begin{array}{ccc} x_0 & y_0 & 1 \\\\ x_1 & y_1 & 1 \\\\ x_2 & y_2 & 1 \end{array}\right|.\]This is $\frac{1}{6}\left(x_0y_1 + x_1y_2 + x_2y_0 - x_0y_2 - x_1y_0 - x_2y_1\right)$ – look familiar?

But the volume of a tetrahedron is also $\frac{1}{3}Bh$, where $B$ is the base area - which we’re trying to find - and $h$ the vertical height - which is 1.

So $\frac{1}{6}\left(x_0y_1 + x_1y_2 + x_2y_0 - x_0y_2 - x_1y_0 - x_2y_1\right) = \frac{1}{3}B$, and $B$ is exactly the what we said it was at the start of the article.

For a triangle, at least.

Suppose you add an extra point, $(x_3, y_3)$, to make the shape a pyramid. You can split this up into two tetrahedra: one the same as before, the other with the points (in order) $(x_2,y_2), (x_3,y_3),(x_0,y_0)$.

Calculating the volumes separately, you’ll notice that the first has a $+x_2y_0$ and a $-x_0y_2$; the second has a $+x_0y_2$ and a $-x_2y_0$, so the only terms involving non-adjacent vertices cancel out – leaving us, again, with the formula in (*).

You may need to convince yourself of this; I leave that as an exercise.

## A selection of other posts

subscribe via RSS