« HOME

A Geometric Derivation of the Shoelace Theorem

The Shoelace Theorem is a method for calculating the area of a simple (non-self-intersecting) polygon in the plane given only the coordinates of its vertices. For example:

A simple, irregular quadrilateral in the plane This polygon has area 12. The Shoelace Theorem says we can calculate the area by writing the coordinates in clockwise order in a column, repeat the first pair, then multiply diagonally adjacent coordinates, sum each column of products, take the difference and divide by two:

A worked example of calculating the area of the previous polygon If we notice this particular shape can be divided along a horizontal to become two triangles of base 6 and height 2, then we easily verify the area is in fact 12. Note if we write down the coordinates in counterclockwise order we get the negation of the area. When applying this theorem, always remember to divide by 2!

Theorem §

In general, if we have a simple polygon of nn vertices with coordinates (x1,y1),(x2,y2),(x_1, y_1), (x_2,y_2), \ldots listed in clockwise order and we define (xn+1,yn+1)=(x1,y1)(x_{n+1}, y_{n+1}) = (x_1,y_1) then the area is:

A=i=1nxi+1yii=1nxiyi+12A = \frac{\sum_{i=1}^n x_{i+1} y_{i} - \sum_{i=1}^n x_i y_{i+1}}{2}

This is a direct consequence of Green’s Theorem (and thus the ubiquitous Stoke’s Theorem), but understanding those theorems requires calculus. Thus we will use a more direct way of deriving the theorem.

Derivation §

Let’s consider the example quadrilateral again, where we label the vertices clockwise starting with (x1,y1)=(2,3)(x_1,y_1)=(2,3) on the left. One way to calculate its area is to draw a rectangle around it and subtract the area of the triangles that are formed.

However this doesn’t work for other shapes, where the number and position of triangles varies, and we even might need to introduce smaller rectangles as well.

Let’s consider the top edges of our quadrilateral. By extending one of them down to the x-axis, we form a trapezoid.

It’s easy to calculate the area of this trapezoid: it’s just the width times the average height, or (x2x1)(y1+y22)(x_2-x_1)(\frac{y_1+y_2}{2}). By adding all the top edges together, we almost get the total area of our shape, but this sum unfortunately includes all the area swept down to the x-axis.

We can use the same trick with the bottom edges to find the area of this extra region.

For the bottom edges, we notice that we have to do the trapezoid width subtraction the other way around, because for bottom edges xi+1<xix_{i+1} < x_i. Thus the total area is:

(x2x1)(y1+y22)+(x3x2)(y2+y32)(x3x4)(y4+y32)(x4x1)(y1+y42)\textstyle (x_2-x_1)(\frac{y_1+y_2}{2}) + (x_3-x_2)(\frac{y_2+y_3}{2}) - (x_3-x_4)(\frac{y_4+y_3}{2}) - (x_4-x_1)(\frac{y_1+y_4}{2})

Now we make a few observations. First, if we replace x1x_1 and y1y_1 with x5x_5 and y5y_5, but only in the last term, then each term involves only vertices ii and i+1i + 1. (Remember x1=xn+1x_1 = x_{n+1}.) Second, we see that if we distribute in the negative sign on bottom edges, they look just like top edges, i.e. each term is just 12(xi+1xi)(yi+1+yi)\frac{1}{2}(x_{i+1}-x_i)(y_{i+1}+y_{i}). Whether a term is a top or bottom edge depends only on whether xi<xi+1x_i < x_{i+1}. If it is, then it’s a top edge and we want to add it to the sum, if it’s not, then it’s a bottom edge and we want to subtract it. All of this together means we can write the area as:

12i=1n(xi+1xi)(yi+1+yi)\frac{1}{2}\sum_{i=1}^n (x_{i+1}-x_i)(y_{i+1}+y_{i})

Multiplying this out gives us:

12i=1nxi+1yi+1+xi+1yixiyi+1xiyi\frac{1}{2}\sum_{i=1}^n x_{i+1}y_{i+1} + x_{i+1} y_{i} - x_i y_{i+1} - x_i y_{i}

Now we notice that there are xi+1yi+1x_{i+1}y_{i+1} terms and xiyi-x_{i}y_{i} terms. When we take the wrap-around into account, we see each of these is summing the exact same numbers, just with opposite signs. Thus the total is zero and we can just drop those terms. Rewriting the remaining two terms in their own sums yields:

i=1nxi+1yii=1nxiyi+12\frac{\sum_{i=1}^n x_{i+1} y_{i} - \sum_{i=1}^n x_i y_{i+1}}{2}

This is the formula we are after. We still have a few issues to resolve before we call this a theorem, however.

Negative y-coordinates §

When we were calculating the area of an edge-trapezoid, we implicitly assumed both y-coordinates were non-negative. That’s because if they weren’t our trapezoid would be some other shape:

In this case we aren’t calculating the area of this shape, so our logic breaks down. To resolve this we notice that our formula is vertically shift invariant, i.e. we can add a constant to all the y-coordinates, and the formula gives the same result. To see this, recall this form of the formula:

12i=1n(xi+1xi)(yi+1+yi)\frac{1}{2}\sum_{i=1}^n (x_{i+1}-x_i)(y_{i+1}+y_{i})

If we add a constant CC to all y-coordinates, we get:

12i=1n(xi+1xi)(yi+1+yi+2C)\frac{1}{2}\sum_{i=1}^n (x_{i+1}-x_i)(y_{i+1}+y_{i} + 2C)

=12i=1n(xi+1xi)(yi+1+yi)+2C(xi+1xi)= \frac{1}{2}\sum_{i=1}^n (x_{i+1}-x_i)(y_{i+1}+y_{i}) + 2C(x_{i+1}-x_i)

=12i=1n(xi+1xi)(yi+1+yi)+Ci=1n(xi+1xi)= \frac{1}{2}\sum_{i=1}^n (x_{i+1}-x_i)(y_{i+1}+y_{i}) + C* \sum_{i=1}^n(x_{i+1}-x_i)

Now we see that with the wrap-around i=1n(xi+1xi)\sum_{i=1}^n(x_{i+1}-x_i) is just zero, and so we can add whatever constant we want without changing the value of the formula. When we are deriving the theorem we can shift the shape up until all y-coordinates are positive. Of course, when we actually use the theorem to calculate an area, we don’t need to do this, as we just showed the same area is calculated regardless.

Non-convex shapes §

For the shapes we’ve seen so far, “top” and “bottom” have been quite clear. But what about more complicated shapes?

Some of the edges in these shapes aren’t completely above or below the shape. Does the theorem still work for these shapes?

Naturally, the answer is yes, but it requires some more subtle reasoning to see why this is true. First, we’ll take our shape and divide it into strips vertically at each of its vertices. We’ll color the shape gray, top edges green, and bottom edges red.

Each vertical section looks like a series of trapezoids and triangles stacked on each other, where the horizontal edges of the trapezoids are the edges of the original polygon and the vertical edges are the vertical edges of the strip. Because we list the vertices in clockwise order, each edge has the polygon’s interior to the right, as it would be if we imagined ourselves walking along each edge from vertex to vertex in order. Thus in each of the regions in the strip on the polygon’s interior will have a green edge above and a red edge below each part of the strip the intersects our shape. The area of that region of the strip is just the difference between the trapezoid from the top edge to the x-axis and the analogous bottom edge trapezoid. By summing up over all the pieces of every strip, we find the total area is all the top edge areas minus all the bottom edge areas, which is exactly what our formula computes.