Definition · The doubled signed areaFor a closed polygon with vertices v₁, …, vₙ in order, the doubled signed area is 2A = Σᵢ (xᵢ·yᵢ₊₁ − xᵢ₊₁·yᵢ), with the index wrapping so that vₙ₊₁ is v₁. Its absolute value is twice the area enclosed; it is positive when the vertices are in counter-clockwise order, negative when clockwise, and zero when the polygon encloses no area.
Theorem · The shoelace formulaFor a simple polygon with vertices listed in order, Σᵢ (xᵢ·yᵢ₊₁ − xᵢ₊₁·yᵢ) is twice the enclosed area, signed by the orientation of the listing.
Take the polygon to be counter-clockwise; the clockwise case follows by reversing the list, which negates every term. Triangulate it by fanning from v₁, which is possible for any simple polygon. The signed area of the triangle v₁ vᵢ vᵢ₊₁ is orient(v₁, vᵢ, vᵢ₊₁) / 2, and summing those over i from 2 to n − 1 gives the area, because the fan covers the polygon and the signed areas of any parts that fall outside cancel against parts counted twice.
Now orient(v₁, vᵢ, vᵢ₊₁) expands to (xᵢ − x₁)(yᵢ₊₁ − y₁) − (yᵢ − y₁)(xᵢ₊₁ − x₁), which is (xᵢ yᵢ₊₁ − xᵢ₊₁ yᵢ) plus terms in x₁ and y₁. Summing over the fan, the x₁ and y₁ terms telescope to zero, and the edges v₁v₂ and vₙv₁ contribute nothing of their own since they lie in the fan's apex. What remains is Σᵢ (xᵢ yᵢ₊₁ − xᵢ₊₁ yᵢ), doubled area.
□
The triangulation step is where simplicity is used. A self-intersecting polygon still has a shoelace sum, and it is still well defined; what it means is a signed count of how many times each region is enclosed, which is the winding number by another name. The page checks whether the polygon is simple before making claims that require it.
Example · The same square, typed both waysType (0, 0), (5, 0), (5, 5), (0, 5) and the lab reports 2A = 50, area 25, counter-clockwise. Type (0, 0), (0, 5), (5, 5), (5, 0) — the same four corners in the opposite order — and it reports 2A = −50, area 25, clockwise. Nothing about the SHAPE changed; the sign is reporting the listing.
This is the lab's fourth worked example and it is there to make the sign concrete. A reader who has been taking absolute values without thinking will see a negative number, assume something has gone wrong, and be exactly wrong: the negative number is the answer to a question the absolute value throws away.
The second formula, and why it is worth running
The trapezoid rule computes Σᵢ (xᵢ − xᵢ₊₁)(yᵢ + yᵢ₊₁), which is algebraically the same total. Arithmetically it is not: it multiplies differences of x by sums of y, where the shoelace multiplies coordinates directly. A transposed subscript in either gives a plausible number, and the only thing that catches it is a route that would have to be wrong in exactly the same way. The lab prints both and marks a disagreement in red.
The arithmetic checker behind this kit adds a third route, fanning triangles from the first vertex and summing orientation determinants, and requires all three to agree on every preset and on hundreds of random convex polygons. Three routes to one integer is more than is strictly needed and it is the reason a page can print an area without hedging.
Zero area is an answer
Three collinear vertices give 2A = 0, and the lab's degenerate worked example is exactly that: (0, 0), (3, 3), (6, 6). The area is zero, there is no orientation to report, and there is no interior for a point to be inside. The page says all three of those things rather than dividing by zero or refusing the input. A degenerate case that still answers is what distinguishes a complete implementation from one that has never been given anything unusual.
It is worth noticing what does NOT break. The sum is still computed, still exactly, and still agrees between the two formulas. The orientation is the only field that has no value, and it says so in words instead of picking one. The next lesson's inside test also still answers on this polygon, and puts every point of the segment on the boundary.