ArticleslgStudy

computer science

Shoelace formula

Shoelace formula is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Shoelace formula rather than just read about it. In short: The shoelace formula, also known as Gauss's area formula and the surveyor's formula, is a mathematical algorithm to determine the area of a simple polygon whose vertices are described by their Cartesian coordinates in the plane. It is called the shoelace formula because of the constant cross-multiplying for the coordinates making up the polygon, like threading shoelaces.

Shoelace formula — main illustration
Shoelace formula — illustration

Key takeaways

  • Shoelace formula belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Shoelace formula to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Shoelace formula from memory before moving on to harder problems.

Reference excerpt

The shoelace formula, also known as Gauss's area formula and the surveyor's formula, is a mathematical algorithm to determine the area of a simple polygon whose vertices are described by their Cartesian coordinates in the plane. It is called the shoelace formula because of the constant cross-multiplying for the coordinates making up the polygon, like threading shoelaces. It has applications in surveying and forestry, among other areas. The formula was described by Albrecht Ludwig Friedrich Meister (1724–1788) in 1769 and is based on the trapezoid formula which was described by Carl Friedrich Gauss and C.G.J. Jacobi. The triangle form of the area formula can be considered to be a special case of Green's theorem. The area formula can also be applied to self-overlapping polygons since the meaning of area is still clear even though self-overlapping polygons are not generally simple. Furthermore, a self-overlapping polygon can have multiple "interpretations" but the Shoelace formula can be used to show that the polygon's area is the same regardless of the interpretation.

The polygon area formulas

Given: A planar simple polygon with a positively oriented (counterclockwise) sequence of points Pi=(xi,yi),i=1,…,n in a Cartesian coordinate system. For the simplicity of the formulas below it is convenient to set P0=Pn,Pn+1=P1. The formulas: The area of the given polygon can be expressed by a variety of formulas, which are connected by simple operations (see below): If the polygon is negatively oriented, then the result A of the formulas is negative. In any case |A| is the sought area of the polygon.

Trapezoid formula The trapezoid formula sums up a sequence of oriented areas Ai=12(yi+yi+1)(xi−xi+1) of trapezoids with PiPi+1 as one of its four edges (see below): A=12∑i=1n(yi+yi+1)(xi−xi+1)=12((y1+y2)(x1−x2)+⋯+(yn+yn+1)(xn−xn+1))

Triangle formula The triangle formula sums up the oriented areas Ai of triangles OPiPi+1: B=12∑i=1n(xiyi+1−xi+1yi)=12∑i=1n|xixi+1yiyi+1|=12∑i=1n|xiyixi+1yi+1|=12(x1y2−x2y1+x2y3−x3y2+⋯+xny1−x1yn)

Shoelace formula

The triangle formula is the base of the popular shoelace formula, which is a scheme that optimizes the calculation of the sum of the 2×2-determinants by hand: 2A=|x1x2y1y2|+|x2x3y2y3|+⋯+|xnx1yny1|=|x1x2x3⋯xnx1y1y2y3⋯yny1| Sometimes this determinant is transposed (written vertically, in two columns), as shown in the diagram.

Other formulas A=12∑i=1nyi(xi−1−xi+1)=12(y1(xn−x2)+y2(x1−x3)+⋯+yn(xn−1−x1)) A=12∑i=1nxi(yi+1−yi−1)

Exterior algebra A particularly concise statement of the formula can be given in terms of the exterior algebra. Let 𝐯1,𝐯2,…,𝐯n be the consecutive vertices of the polygon. The Cartesian coordinate expansion of the outer product with respect to the standard ordered orthonormal plane basis (𝐱,𝐲) gives 𝐯i∧𝐯i+1=(xiyi+1−xi+1yi)𝐱∧𝐲 and the oriented area is given as follows. A=12∑i=1nvi∧vi+1=12∑i=1n(xiyi+1−xi+1yi)𝐱∧𝐲 Note that the area is given as a multiple of the unit area 𝐱∧𝐲.

Example

For the area of the pentagon with P1=(1,6),P2=(3,1),P3=(7,2),P4=(4,4),P5=(8,5) one gets 2A=|1361|+|3712|+|7424|+|4845|+|8156|=(1−18)+(6−7)+(28−8)+(20−32)+(48−5)=33A=16.5 The advantage of the shoelace form: Only 6 columns have to be written for calculating the 5 determinants with 10 columns.

Deriving the formulas

Trapezoid formula

The edge Pi,Pi+1 determines the trapezoid (xi,yi),(xi+1,yi+1),(xi,0),(xi+1,0) with its oriented area

Ai=12(yi+yi+1)(xi−xi+1) In case of xi<xi+1 the number Ai is negative, otherwise positive or Ai=0 if xi=xi+1. In the diagram the orientation of an edge is shown by an arrow. The color shows the sign of Ai: red means Ai<0, green indicates Ai>0. In the first case the trapezoid is called negative in the second case positive. The negative trapezoids delete those parts of positive trapezoids, which are outside the polygon. In case of a convex polygon (in the diagram the upper example) this is obvious: The polygon area is the sum of the areas of the positive trapezoids (green edges) minus the areas of the negative trapezoids (red edges). In the non convex case one has to consider the situation more carefully (see diagram). In any case the result is A=∑i=1nAi=12∑i=1n(yi+yi+1)(xi−xi+1)

Triangle form, determinant form

Eliminating the brackets and using ∑i=1nxiyi=∑i=1nxi+1yi+1 (see convention Pn+1=P1 above), one gets the determinant form of the area formula: A=12∑i=1n(xiyi+1−xi+1yi)=12∑i=1n|xixi+1yiyi+1| Because one half of the i-th determinant is the oriented area of the triangle O,Pi,Pi+1 this version of the area formula is called triangle form.

Other formulae With ∑i=1nxiyi+1=∑i=1nxi−1yi (see convention P0=Pn,Pn+1=P1 above) one gets 2A=∑i=1n(xiyi+1−xi+1yi)=∑i=1nxiyi+1−∑i=1nxi+1yi=∑i=1nxi−1yi−∑i=1nxi+1yi Combining both sums and excluding yi leads to A=12∑i=1nyi(xi−1−xi+1) With the identity ∑i=1nxi+1yi=∑i=1nxiyi−1 one gets A=12∑i=1nxi(yi+1−yi−1) Alternatively, this is a special case of Green's theorem with one function set to 0 and the other set to x, such that the area is the integral of xdy along the boundary.

Manipulations of a polygon A(P1,…,Pn) indicates the oriented area of the simple polygon P1,…,Pn with n≥4 (see above). A is positive/negative if the orientation of the polygon is positive/negative. From the triangle form of the area formula or the diagram below one observes for 1<k<n: A(P1,…,Pn)=A(P1,…,Pk−1,Pk+1,…,Pn)+A(Pk−1,Pk,Pk+1) In case of k=1orn one should first shift the indices. Hence:

Moving Pk affects only A(Pk−1,Pk,Pk+1) and leaves A(P1,...,Pk−1,Pk+1,...,Pn) unchanged. There is no change of the area if Pk is moved parallel to Pk−1Pk+1‾. Purging Pk changes the total area by A(Pk−1,Pk,Pk+1), which can be positive or negative. Inserting point Q between Pk,Pk+1 changes the total area by A(Pk,Q,Pk+1), which can be positive or negative. Example:

P1=(3,1),P2=(7,2),P3=(4,4), P4=(8,6),P5=(1,7), Q=(4,3)

With the above notation of the shoelace scheme one gets for the oriented area of the

blue polygon: A(P1,P2,P3,P4,P5)=12|374813124671|=20.5 green triangle: A(P2,P3,P4)=12|74872462|=−7 red triangle: A(P1,Q,P2)=12|34731321|=−3.5 blue polygon minus point P3: A(P1,P2,P4,P5)=12|3781312671|=27.5 blue polygon plus point Q between P1,P2: A(P1,Q,P2,P3,P4,P5)=12|34748131324671|=17 One checks, that the following equations hold: A(P1,P2,P3,P4,P5)=A(P1,P2,P4,P5)+A(P2,P3,P4)=20.5 A(P1,P2,P3,P4,P5)+A(P1,Q,P2)=A(P1,Q,P2,P3,P4,P5)=17

… excerpt ends here. Continue reading the full article.

Illustrations

Shoelace formula: Shoelace scheme for determining the area of a polygon with point coordinates (x1,y1),...,(xn,yn)
Shoelace scheme for determining the area of a polygon with point coordinates (x1,y1),...,(xn,yn)
Shoelace formula: Basic idea: Any polygon edge determines the signed area of a trapezoid. All these areas sum up to the polygon area.
Basic idea: Any polygon edge determines the signed area of a trapezoid. All these areas sum up to the polygon area.
Shoelace formula: Example
Example
Shoelace formula: Horizontal shoelace form for the example.
Horizontal shoelace form for the example.
Shoelace formula: Deriving the trapezoid formula
Deriving the trapezoid formula

Worked examples

Example 1 — a first encounter with Shoelace formula

Start with the simplest possible case. Write down what Shoelace formula claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Shoelace formula before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Shoelace formula ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Shoelace formula

In research
Shoelace formula appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Shoelace formula in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Shoelace formula is common in secondary-school and first-year university syllabi. It links to neighbouring topics Area, Geometric algorithms, Surveying, so understanding it makes those chapters shorter.
In everyday life
Look for Shoelace formula outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Shoelace formula” →

How to study Shoelace formula in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Shoelace formula means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Shoelace formula out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Shoelace formula in simple terms?

The shoelace formula, also known as Gauss's area formula and the surveyor's formula, is a mathematical algorithm to determine the area of a simple polygon whose vertices are described by their Cartesian coordinates in the plane. It is called the shoelace formula because of the constant cross-multip…

Why does Shoelace formula matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Shoelace formula?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Shoelace formula.

Tags

  • Area
  • Geometric algorithms
  • Surveying

Keep exploring