Suvarna Garge (Editor)

Shoelace formula

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Shoelace formula

The shoelace formula or shoelace algorithm (also known as Gauss's area formula and the surveyor's formula) is a mathematical algorithm to determine the area of a simple polygon whose vertices are described by their Cartesian coordinates in the plane. The user cross-multiplies corresponding coordinates to find the area encompassing the polygon, and subtracts it from the surrounding polygon to find the area of the polygon within. It is called the shoelace formula because of the constant cross-multiplying for the coordinates making up the polygon, like tying shoelaces. It is also sometimes called the shoelace method. It has applications in surveying and forestry, among other areas.

Contents

The formula was described by Meister (1724-1788) in 1769 and by Gauss in 1795. It can be verified by dividing the polygon into triangles, and can be considered to be a special case of Green's theorem.

The area formula is derived by taking each edge AB, and calculating the (signed) area of triangle ABO with a vertex at the origin O, by taking the cross-product (which gives the area of a parallelogram) and dividing by 2. As one wraps around the polygon, these triangles with positive and negative area will overlap, and the areas between the origin and the polygon will be cancelled out and sum to 0, while only the area inside the reference triangle remains. This is why the formula is called the Surveyor's Formula, since the "surveyor" is at the origin; if going counterclockwise, positive area is added when going from left to right and negative area is added when going from right to left, from the perspective of the origin.

The area formula is valid for any non-self-intersecting (simple) polygon, which can be convex or concave.

Definition

The formula can be represented by the expression

A = 1 2 | i = 1 n 1 x i y i + 1 + x n y 1 i = 1 n 1 x i + 1 y i x 1 y n | = 1 2 | x 1 y 2 + x 2 y 3 + + x n 1 y n + x n y 1 x 2 y 1 x 3 y 2 x n y n 1 x 1 y n |

where

  • A is the area of the polygon,
  • n is the number of sides of the polygon, and
  • (xiyi), i = 1, 2,..., n are the vertices (or "corners") of the polygon.
  • Alternatively

    A = 1 2 | i = 1 n x i ( y i + 1 y i 1 ) | = 1 2 | i = 1 n y i ( x i + 1 x i 1 ) | = 1 2 | i = 1 n x i y i + 1 x i + 1 y i | = 1 2 | i = 1 n det ( x i x i + 1 y i y i + 1 ) |

    where xn+1 = x1 and x0 = xn, as well as yn+1 = y1 and y0 = yn.

    If the points are labeled sequentially in the counterclockwise direction, then the above determinants are positive and the absolute value signs can be omitted; if they are labeled in the clockwise direction, the determinants will be negative. This is because the formula can be viewed as a special case of Green's Theorem.

    Examples

    The user must know the points of the polygon in a Cartesian plane. For example, take a triangle with coordinates {(2, 1), (4, 5), (7, 8)}. Take the first x-coordinate and multiply it by the second y-value, then take the second x-coordinate and multiply it by the third y-value, and repeat, and repeat again, until you do it for all points. This can be defined by this formula:

    A tri. = 1 2 | x 1 y 2 + x 2 y 3 + x 3 y 1 x 2 y 1 x 3 y 2 x 1 y 3 |

    for xi and yi representing each respective coordinate. This formula is just the expansion of those given above for the case n = 3. Using it, one can find that the area of the triangle equals one half of the absolute value of 10 + 32 + 7 − 4 − 35 − 16, which equals 3. The number of variables depends on the number of sides of the polygon. For example, a pentagon will be defined up to x5 and y5:

    A pent. = 1 2 | x 1 y 2 + x 2 y 3 + x 3 y 4 + x 4 y 5 + x 5 y 1 x 2 y 1 x 3 y 2 x 4 y 3 x 5 y 4 x 1 y 5 |

    A quadrilateral will be defined up to x4 and y4:

    A quad. = 1 2 | x 1 y 2 + x 2 y 3 + x 3 y 4 + x 4 y 1 x 2 y 1 x 3 y 2 x 4 y 3 x 1 y 4 |

    More complex example

    Consider the polygon defined by the points (3,4), (5,11), (12,8), (9,5), and (5,6), and illustrated in the following diagram:

    The area of this polygon is:

    A = 1 2 | 3 × 11 + 5 × 8 + 12 × 5 + 9 × 6 + 5 × 4 4 × 5 11 × 12 8 × 9 5 × 5 6 × 3 | = 60 2 = 30

    Explanation of name

    The reason this formula is called the shoelace formula is because of a common method used to evaluate it. This method uses matrices. As an example, choose the triangle with vertices (2,4), (3,−8), and (1,2). Then construct the following matrix by “walking around” the triangle and ending with the initial point.

    First, draw diagonal down and to the right slashes (as shown below),

    and multiply the two numbers connected by each slash, then add all the products: (2 × −8) + (3 × 2) + (1 × 4) = −6. Do the same thing with slashes diagonal down and to the left (shown below with downwards slashes):

    (4 × 3) + (−8 × 1) + (2 × 2) = 8. Then take the difference of these two numbers: |(−6 )−( 8)| = 14. Halving this gives the area of the triangle: 7. Organizing the numbers like this makes the formula easier to recall and evaluate. With all the slashes drawn, the matrix loosely resembles a shoe with the laces done up, giving rise to the algorithm's name.

    References

    Shoelace formula Wikipedia