← Lessons

quiz vs the machine

Silver1120

Algorithms

Polygon Area Shoelace

Sum cross products around the vertices to get signed area and the winding direction for free.

4 min read · intro · beat Silver to climb

Area from coordinates

The shoelace formula computes the area of any simple polygon directly from its vertex coordinates, with no need to decompose it into triangles by hand.

The cross product sum

Walk the vertices in order. For each edge from one vertex to the next, accumulate the cross product of the two position vectors. Sum these contributions around the whole boundary, then take half the absolute value.

  • The name comes from the crisscross pattern of multiplications.
  • Each term is the signed area of a triangle from the origin.

The sign is a bonus

Before taking the absolute value, the sign of the sum reveals the winding direction.

  • A positive total means counterclockwise vertex order.
  • A negative total means clockwise order.

This orientation check is handy for normalizing polygons and for point in polygon routines.

Requirements

The polygon must be simple, meaning its edges do not cross themselves. Self intersecting polygons return a blend of positive and negative regions rather than a meaningful single area.

Key idea

The shoelace formula sums cross products of consecutive vertices and halves the result for the area, while the sign of that sum reveals whether the polygon is wound clockwise or counterclockwise.

Check yourself

Answer to earn rating on the learn ladder.

1. What does the shoelace formula accumulate around the polygon?

2. What extra information does the sign of the sum provide?

3. Which condition must the polygon satisfy for a meaningful result?