Area of a Polygon from Coordinates (the Shoelace Formula)

Takes the vertices in order and finds the area of the polygon with the shoelace formula. There is no need to cut the shape into triangles: multiplying neighbouring coordinates and alternating the signs is enough. The perimeter is also shown.

The usual way to find the area of a polygon is to cut it into triangles and add them up. If the coordinates of the vertices are known, none of that is necessary. The shoelace formula gives the answer in one pass.

S=12i=1n(xiyi+1xi+1yi)S = \dfrac{1}{2}\left| \sum_{i=1}^{n} (x_i y_{i+1} - x_{i+1} y_i) \right|

When ii reaches nn, the next vertex wraps back to the first. A polygon is closed, so the edge from the last vertex to the first counts like any other, and there is no need to repeat the first point at the end of the list.

The name comes from how the calculation looks. Writing the x and y values in two columns and multiplying diagonally produces crossing lines, like the lacing of a shoe.

Why it gives the area

Each term in the sum is twice the area of the triangle formed by the origin and one edge — but signed. An edge that runs anticlockwise as seen from the origin contributes positively, one that runs clockwise contributes negatively.

Going once around the polygon, every region counted in error by one edge is subtracted again by an edge running the other way. What survives the cancellation is exactly the inside of the polygon. This holds whether the origin lies inside the shape or outside it.

Listing the vertices clockwise makes the sum negative, and since area has no direction, the absolute value is taken.

Example

The default input has five vertices: (0, 0), (4, 0), (6, 3), (3, 5) and (0, 3).

The terms come to 0×04×0=00 \times 0 - 4 \times 0 = 0, then 4×36×0=124 \times 3 - 6 \times 0 = 12, then 6×53×3=216 \times 5 - 3 \times 3 = 21, then 3×30×5=93 \times 3 - 0 \times 5 = 9, and finally 0×00×3=00 \times 0 - 0 \times 3 = 0.

They add to 42, so the area is half of that, 21. The perimeter works out at about 17.8167.

Points to watch

List the vertices in the order the edges connect them. Reordering describes a different shape and gives a different answer.

Self-intersecting polygons are not handled correctly. In a figure-of-eight, the far lobe is traversed in the opposite direction and cancels part of the near one.

This is the formula behind land area calculations in surveying and mapping. No triangulation is required, and the procedure is identical however many vertices there are.