Polygon Area by the Shoelace Formula

Area, direction and centre from corner coordinates.

  • Exact fractions
  • Centroid included
  • Crossing edges flagged
A small rounded clay field with a soft clay cord pulled around five rounded pegs, forming a lopsided five-cornered shape.

The guide

A polygon's area is a sum of signed trapezoids, and the sign tells you which way you walked

The shoelace formula turns a list of corners into an exact area, a direction and a centre, and it fails in one precise, checkable way when the outline crosses itself.

  • 87/2 the area of the plot with corners (0,0), (7,1), (8,5), (3,7), (-1,4)
  • (5/3, 5/3) the centroid of the L shape, whose area is 12
  • 0 the signed sum of the bowtie (0,0), (2,2), (2,0), (0,2)
  • 42 + 5/2 - 1 Pick's count for the plot: inside, outline, then take one away
Read the full guide Fold the guide 8 min · 14 sources

A polygon is a promise: walk from corner to corner in order, and the last step returns you to the start. If you know the corners, you know everything about the shape, including its area. The surprise is how little work that takes. One multiplication per pair of neighbouring corners, one running total, one halving. The recipe has many names. It is called the shoelace formula, Gauss’s area formula and the surveyor’s formula, and it earns the first name from the criss-cross of multiplications that looks like a laced boot. It has applications in surveying and forestry, and a description of it dates to 1769, when Albrecht Ludwig Friedrich Meister set it out.

Why adding trapezoids gives an area

Take one edge of the polygon. Drop straight lines from its two ends to the horizontal axis and you have a trapezoid. If the edge runs left to right, call its area positive; if it runs right to left, call it negative. Do that for every edge and add the results. On the top of a shape the trapezoids reach up from the axis and count positive. On the bottom they run the other way and count negative, which cancels the part of the top trapezoids that lies outside the shape. What is left is exactly the polygon. Nothing is approximated, and the trapezoid sum is the first of the standard forms of the formula.

Collect the terms and the trapezoid sum turns into a sum of two-by-two determinants. Half of each determinant is the signed area of the triangle formed by two neighbouring corners and the origin. So the formula can be read either as trapezoids under the edges or as thin triangles fanned out from the origin. Both readings give the same total. There is a third reading, from calculus. Green’s theorem turns an area into a line integral around the boundary, and one choice of its two functions makes the area equal to the integral of x times dy along the outline. The shoelace sum is that integral worked out exactly for straight edges.

For corners (x1, y1) up to (xn, yn), the signed area is half the sum over every corner of x_i times y_(i+1) minus x_(i+1) times y_i. The closing step is the easy one to forget. The last corner pairs with the first, so a polygon of five corners has five terms, not four.

The sign is the direction of travel, and the weights find the centre

Walk the corners counter-clockwise and the sum comes out positive. Walk the same corners clockwise and every term flips, so the sum is the same size with a minus sign. A unit square listed as (0,0), (1,0), (1,1), (0,1) gives 1, and the same square listed backwards gives -1. That is not a nuisance to be tidied away. The sign is a free test of orientation, and orientation is a question programs ask constantly. The sign of a single two-by-two determinant, the cross product of two edge vectors, says whether a turn is to the left or the right. The signed area adds up all of those turns at once.

The area is the absolute value of the sum, halved. The centroid is the part that does not care about the direction, and that deserves a closer look. The centroid of a polygon is its balance point, the mean position of every point inside it. For a polygon whose edges do not cross, each coordinate is a weighted sum over the edges. Every edge contributes the sum of its two end coordinates, multiplied by its cross product, and the total is divided by six times the signed area.

The weights have a plain meaning. Each cross product is twice the signed area of a thin triangle fanned out from the origin, and it is multiplied by the position of that triangle’s two outer corners. Big triangles pull the centroid toward themselves, small ones barely move it. A clockwise list flips the sign of both the cross products and the signed area, so it gives the same centroid as the counter-clockwise one.

The centroid is not the average of the corners. Put three corners near one end of a long thin shape and the average of the corners sits there too, while the balance point stays near the middle of the material. The formula divides by the signed area, so it needs a non-zero sum, and a zero sum gets a plain message rather than a guess.

A worked example you can reproduce: the L shape with corners (0,0), (4,0), (4,2), (2,2), (2,4), (0,4) is a 4 by 4 square with a 2 by 2 square taken from one corner. Its six cross products are 0, 8, 4, 4, 8 and 0, the last one being the closing step. They sum to 24, so the area is 12. The centroid works out to (5/3, 5/3), and cutting the L into a 4 by 2 rectangle and a 2 by 2 square gives the same point: 8 times 2 plus 4 times 1, over 12, is 5/3 on each axis.

When the edges cross

The formula assumes a simple polygon, one whose edges meet only where neighbours share a corner. Feed it an outline that crosses itself and it still returns a number, which is the problem. The number is real, but it is no longer the area of one region. Each region of a self-crossing outline is multiplied by a factor called its density, which is the number of turns the outline makes around it. A simple polygon has density 1 everywhere inside, which is why the formula works. The middle pentagon of a pentagram has density 2, so it counts twice.

A figure of eight is the cleanest failure. Its two lobes are walked in opposite directions, so one lobe has density 1 and the other has density -1, and their areas cancel. The bowtie with corners (0,0), (2,2), (2,0), (0,2) covers two triangles of area 1 each, and its cross products are 0, -4, 4 and 0. The sum is 0.

The honest reply is that the edges cross and the sum is a signed total, not an area. So the tool tests every non-adjacent pair of edges, exactly, and says so in plain words. For n corners that is n times (n minus 3) divided by 2 pairs, which is 2 for the bowtie and about two million for 2,000 corners. The test uses orientation signs, the same cross product that gives the direction of travel. Two segments cross properly when each one’s endpoints lie on opposite sides of the other. Touching and overlapping along a line are checked separately, because a corner resting on another edge also breaks the simple-polygon rule.

An independent check for whole-number corners

When every corner has whole-number coordinates there is a second way to get the area that uses no multiplication of coordinates at all. Count the grid points strictly inside the polygon, call that i, and the grid points on its outline, call that b. Then the area equals i plus b over 2, minus 1. This is Pick’s theorem, set out by Georg Pick in an eight-page paper of 1899 titled Geometrisches zur Zahlenlehre. It attracted little attention until Hugo Steinhaus included it in his book Mathematical Snapshots. One proof cuts the polygon into triangles that have no grid points except their corners, shows each has area exactly one half, and then uses Euler’s formula to count them.

The five-corner plot with corners (0,0), (7,1), (8,5), (3,7), (-1,4) has cross products 0, 27, 41, 19 and 0, so the sum is 87 and the area is 87/2. Every edge has a greatest common divisor of 1 between its run and its rise, so b is 5. Pick’s theorem then says i is 87/2 minus 5/2 plus 1, which is 42. Counting the grid points one by one gives 42 as well, and 42 plus 5/2 minus 1 is 87/2 again.

The theorem needs a simple polygon, so it is not offered for a crossing outline. Because the grid points are counted one at a time, the check shares no arithmetic with the shoelace sum, which makes it a real second opinion. The tool counts the points directly only when the bounding box holds a manageable number of grid points, and otherwise reports the formula’s answer and says why it skipped the count.

Why every digit is kept, and what the tool leaves out

Floating-point arithmetic is where this formula quietly goes wrong. The products of coordinates are large even when the area is small, and the subtraction at the heart of each term throws away the digits that matter. Take a rectangle 4 wide and 3 tall whose corner sits at (1000000000000, 2000000000000). Its area is 12. The same sum in ordinary double-precision numbers, in two different languages, gave 0.

The cause is size. Each product is about 2 times 10 to the 24, far past 9007199254740991, the largest safe whole number in a double, so the products round, and the rounded products cancel to nothing. The page runs the sum with integers of any length instead. MDN describes BigInt as the type for whole numbers too large or too small for the ordinary number type, and it cannot be mixed with ordinary numbers by accident.

Decimals and fractions are handled the same way. Every coordinate is read as text, held as a numerator over a denominator, and put over the common denominator of the whole list. Python’s fractions module works on the same principle for rational numbers, and it served as the independent reference for the checks.

Edge lengths are square roots, which are rarely fractions. The page keeps the squared length exact and finds the decimal with an integer square root: multiply the squared length by 10 to the power of twice the places wanted, take the integer square root, and shift the point back. No floating-point square root is used, and a length is shown as an exact fraction whenever the square is a perfect square. Long sums can take time, so the heavy work runs in a web worker, which MDN describes as a script running in a background thread so the page stays responsive. A cancel button ends the job, and a ten second limit stops a runaway input.

The formula assumes a flat plane. It does not measure curved boundaries, and it does not apply on a sphere or on a map projection, where area depends on how the map stretches the ground. For a land parcel the numbers you type are the numbers you get: a legal area comes from a surveyor’s measured record, not from a calculator. The ray-casting test for a point inside a polygon is known to go wrong near the boundary in finite-precision arithmetic, which is one more reason the lattice count here uses whole numbers and exact comparisons. The same care is why the page never rounds a coordinate before it is used.

Finally, a simple polygon has no holes. A shape with a hole is two outlines, an outer one and an inner one. Enter each on its own, keep each one simple, and subtract the inner area from the outer.

Sources

Every source consulted for this guide. Links checked November 9, 2026.

  1. Shoelace formula Wikipedia
  2. Pick's theorem Wikipedia
  3. Polygon Wikipedia
  4. Centroid Wikipedia
  5. Simple polygon Wikipedia
  6. Curve orientation Wikipedia
  7. Green's theorem Wikipedia
  8. Winding number Wikipedia
  9. Point in polygon Wikipedia
  10. Integer square root Wikipedia
  11. Georg Pick (1859 - 1942) - Biography MacTutor History of Mathematics, University of St Andrews
  12. BigInt - JavaScript MDN Web Docs
  13. Web Workers API MDN Web Docs
  14. fractions - Rational numbers Python Software Foundation