You are currently browsing the tag archive for the ‘Shoelace Algorithm’ tag.

The Shoelace Algorithm to find areas of polygons

This is a nice algorithm, formally known as Gauss’s Area formula, which allows you to work out the area of any polygon as long as you know the Cartesian coordinates of the vertices.  The case can be shown to work for all triangles, and then can be extended to all polygons by first splitting them into triangles and following the same approach.

Let’s see if we can work out the algorithm ourselves using the construction at the top of the page.  We want the area of the triangle (4), and we can see that this will be equivalent to the area of the rectangle minus the area of the 3 triangles (1) (2) (3).

Let’s start by adding some other coordinate points for the rectangle:

Therefore the area of the rectangle will be:

(1) + (2) +(3) +(4): (x3-x2)(y1-y3)

And the area of triangles will be:

(1): 0.5(x3-x2)(y2-y3)

(2): 0.5(x1-x2)(y1-y2)

(3): 0.5(x3-x1)(y1-y3)

Therefore the area of triangle (4) will be:

Area = (x3-x2)(y1-y3) – 0.5(x3-x2)(y2-y3) – 0.5(x1-x2)(y1-y2) – 0.5(x3-x1)(y1-y3)

Therefore we have our algorithm!  Let’s see if it works with the following coordinates added:

x1 = 2  x = 1  x = 3
y1 = 3 y = 2  y = 1

Area = (x3-x2)(y1-y3) – 0.5(x3-x2)(y2-y3) – 0.5(x1-x2)(y1-y2) – 0.5(x3-x1)(y1-y3)

Area = (3-1)(3-1) – 0.5(3-1)(2-1) – 0.5(2-1)(3-2) – 0.5(3-2)(3-1)

Area = 4 – 1 – 0.5 – 1 = 1.5 units squared

We could check this using Pythagoras to find all 3 sides of the triangle, followed by the Cosine rule to find an angle, followed by the Sine area of triangle formula, but let’s take an easier route and ask Wolfram Alpha (simply type “area of a triangle with coordinates (1,2) (2,3) (3,1)).  This does indeed confirm an area of 1.5 units squared.  Our algorithm works.  We can of course simplify the area formula by expanding brackets and simplifying.  If we were to do this we would get the commonly used version of the area formula for triangles.

The general case for finding areas of polygons

The general formula for the area of an n-sided polygon is given above.

For a triangle this gives:

For a quadrilateral this gives:

For a pentagon this gives:

You might notice a nice shoelace like pattern (hence the name) where x coordinates criss cross with the next y coordinate along.  To finish off let’s see if it works for an irregular pentagon.

If we arbitrarily assign our (x1, y1) as (1,1) and then (x2, y2) as (3,2), and continue in a clockwise direction we will get the following:

area = absolute of 0.5( 1×2 + 3×4 + 3×1 + 4×0 + 2×1 – 3×1 – 3×2 – 4×4 – 2×1 – 1×0)

area = 4.

Let’s check again with Wolfram Alpha – and yes it does indeed have an area of 4.

It could be a nice exploration task to take this further and to explore how many different methods there are to find the area of polygons – and compare their ease of use, level of mathematics required and aesthetic appeal.

Website Stats

  • 6,517,184 views

Recent Posts

Follow IB Maths Resources from British International School Phuket on WordPress.com