← Lessons

quiz vs the machine

Silver1090

Algorithms

Polygon Area with the Shoelace Formula

Sum cross products around a polygon to get its exact area in one pass.

4 min read · intro · beat Silver to climb

Lacing around the boundary

The shoelace formula computes the area of any simple polygon from the coordinates of its vertices in order. Picture writing the coordinates in two columns and drawing diagonal lines between them like laces on a shoe. Each crossing pair contributes a product, and the pattern gives the formula its name.

How it works

Walk around the polygon vertex by vertex and accumulate a running sum:

  • For each edge, take the cross product of consecutive vertex coordinates.
  • Add all these signed terms together.
  • Halve the absolute value of the total to get the area.

The signed total before taking the absolute value also reveals orientation: a positive sum means the vertices were listed counterclockwise, a negative sum means clockwise.

Why it is reliable

The method visits each vertex once, so it is linear in the number of vertices. It works for convex and concave shapes alike, as long as the boundary does not cross itself. With integer coordinates every term is exact, which makes the formula a dependable building block inside larger geometry code.

Key idea

Summing the cross products of consecutive vertices and halving the magnitude yields a simple polygon's exact area and its orientation.

Check yourself

Answer to earn rating on the learn ladder.

1. What does the sign of the unhalved shoelace sum tell you?

2. Which polygons can the shoelace formula handle?

3. How many passes over the vertices does the formula need?