Shoelace formula
{{Short description|Mathematical algorithm for calculating area of a simple polygon}}
{{Use dmy dates|date=July 2022}}
The shoelace formula, also known as Gauss's area formula and the surveyor's formula,{{cite journal |author=Bart Braden |title=The Surveyor's Area Formula |journal=The College Mathematics Journal |volume=17 |issue=4 |year=1986 |pages=326–337 |url=https://www.maa.org/sites/default/files/pdf/pubs/Calc_Articles/ma063.pdf |doi=10.2307/2686282 |jstor=2686282 |archive-url=https://web.archive.org/web/20140629065751/https://www.maa.org/sites/default/files/pdf/pubs/Calc_Articles/ma063.pdf |archive-date=29 June 2014 |url-status=dead}} 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.{{cite web|last=Dahlke|first=Karl|title=Shoelace Formula|url=http://www.mathreference.com/la-det,shoe.html|accessdate=9 June 2008}} It has applications in surveying and forestry,Hans Pretzsch, [https://books.google.com/books?id=ZLNZMCSuUAQC&pg=PA232 Forest Dynamics, Growth and Yield: From Measurement to Model], Springer, 2009, {{isbn|3-540-88306-1}}, p. 232. among other areas.
The formula was described by Albrecht Ludwig Friedrich Meister (1724–1788) in 1769{{citation
| last = Meister | first = A. L. F.
| journal = Nov. Com. Gött.
| language = Latin
| page = 144
| title = Generalia de genesi figurarum planarum et inde pendentibus earum affectionibus
| url = https://books.google.com/books?id=fOE_AAAAcAAJ
| volume = 1
| year = 1769}}. and is based on the trapezoid formula which was described by Carl Friedrich Gauss and C.G.J. Jacobi.Max Koecher, Aloys Krieg: Ebene Geometrie, Springer-Verlag, 2013, ISBN 3662068095, 9783662068090, p. 116 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.{{citation
| author = P.W. Shor
| author2 = C.J. Van Wyk
| journal = Comput. Geom. Theory Appl.
| pages = 31–50
| title = Detecting and decomposing self-overlapping curves
| volume = 2
| year = 1992| issue = 1
| doi = 10.1016/0925-7721(92)90019-O
| doi-access = free
}} 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.{{cite conference
| author = Ralph P. Boland
| author2 = Jorge Urrutia
| conference = 12th Canadian Conference on Computational Geometry.
| pages = 159–162
| title = Polygon Area Problems
| year = 2000}}
The polygon area formulas
Given: A planar simple polygon with a positively oriented (counter clock wise) sequence of points in a Cartesian coordinate system.
For the simplicity of the formulas below it is convenient to set .
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 of the formulas is negative. In any case is the sought area of the polygon.Antti Laaksonen: Guide to Competitive Programming: Learning and Improving Algorithms Through Contests, Springer, 2018, ISBN 3319725475, 9783319725475, p. 217
= Trapezoid formula =
The trapezoid formula sums up a sequence of oriented areas of trapezoids with as one of its four edges (see below):
A &= \frac 1 2 \sum_{i=1}^n (y_i + y_{i+1})(x_i - x_{i+1})\\
&=\frac 1 2 \Big((y_1+y_2)(x_1-x_2)+ \cdots +(y_n+y_1)(x_n-x_1)\Big)
\end{align}
= Triangle formula =
The triangle formula sums up the oriented areas of triangles :Mauren Abreu de Souza, Humberto Remigio Gamba, Helio Pedrini: Multi-Modality Imaging: Applications and Computational Techniques, Springer, 2018, ISBN 331998974X, 9783319989747, p. 229
A &= \frac 1 2 \sum_{i=1}^n (x_iy_{i+1}-x_{i+1}y_i)
=\frac 1 2\sum_{i=1}^{n}\begin{vmatrix} x_i & x_{i+1} \\ y_i & y_{i+1} \end{vmatrix}
=\frac 1 2\sum_{i=1}^{n}\begin{vmatrix} x_i & y_i \\ x_{i+1} & y_{i+1} \end{vmatrix}\\
&=\frac 1 2 \Big(x_1 y_2- x_2 y_1 +x_2 y_3- x_3 y_2+\cdots +x_ny_1-x_1y_n\Big)
\end{align}
= 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:
&=
\begin{vmatrix} x_1 & x_2 \\
y_1 & y_2 \end{vmatrix} +
\begin{vmatrix} x_2 & x_3 \\
y_2 & y_3 \end{vmatrix} +\cdots +
\begin{vmatrix} x_n & x_1 \\
y_n & y_1 \end{vmatrix} \\[10mu]
&= \begin{vmatrix} x_1 & x_2 &x_3 \cdots &x_n&x_1\\
y_1 & y_2 &y_3 \cdots &y_n&y_1 \end{vmatrix}
\end{align}
Sometimes this determinant is transposed (written vertically, in two columns), as shown in the diagram.
= Other formulas =
A &=\frac 1 2 \sum_{i=1}^n y_i(x_{i-1}-x_{i+1})\\
& =\frac 1 2
\Big(y_1(x_n-x_2)+y_2(x_1-x_3)+
\cdots+y_n(x_{n-1}-x_1)\Big)
\end{align}
= Exterior Algebra =
A particularly concise statement of the formula can be given in terms of the exterior algebra. Let 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 and the oriented area is given as follows.
A = \frac{1}{2} \sum_{i=1}^{n} v_i \wedge v_{i+1}
= \frac{1}{2} \sum_{i=1}^{n} (x_i y_{i+1} - x_{i+1} y_i) \; \mathbf{x} \wedge \mathbf{y}
Note that the area is given as a multiple of the unit area .
Example
For the area of the pentagon with
&P_1=(1,6),P_2=(3,1), P_3=(7,2),\\
&P_4=(4,4), P_5=(8,5)
\end{align}
one gets
2A &=
\begin{vmatrix} 1 & 3 \\ 6 & 1 \end{vmatrix} +
\begin{vmatrix} 3 & 7 \\ 1 & 2 \end{vmatrix} +
\begin{vmatrix} 7 & 4 \\ 2 & 4 \end{vmatrix} +
\begin{vmatrix} 4 & 8 \\ 4 & 5 \end{vmatrix} +
\begin{vmatrix} 8 & 1 \\ 5 & 6 \end{vmatrix} \\
& =(1-18)\;+(6-7)\;+(28-8)\;+(20-32)\;+(48-5)=33 \\
A&= 16.5
\end{align}
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 determines the trapezoid with its oriented area
:
In case of
carefully (see diagram). In any case the result is
= Triangle form, determinant form =
File:Trapezformel-3eckform.svg
Eliminating the brackets and using
=\frac 1 2\sum_{i=1}^{n}\begin{vmatrix} x_i & x_{i+1} \\ y_i & y_{i+1} \end{vmatrix}
Because one half of the i-th determinant is the oriented area of the triangle
= Other formulas =
With
=\sum_{i=1}^n x_iy_{i+1} - \sum_{i=1}^n x_{i+1}y_i
=\sum_{i=1}^n x_{i-1}y_i - \sum_{i=1}^n x_{i+1}y_i
Combining both sums and excluding
With the identity
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(P_{k-1}, P_k, P_{k+1})
In case of
Hence:
- Moving
P_k affects onlyA(P_{k-1},P_k,P_{k+1}) and leavesA(P_1,...,P_{k-1},P_{k+1}, ...,P_n) unchanged. There is no change of the area ifP_k is moved parallel to\overline{P_{k-1}P_{k+1}} . - Purging
P_k changes the total area byA(P_{k-1},P_k,P_{k+1}) , which can be positive or negative. - Inserting point
Q betweenP_k,P_{k+1} changes the total area byA(P_k,Q,P_{k+1}) , which can be positive or negative.
Example:
:
:
With the above notation of the shoelace scheme one gets for the oriented area of the
- blue polygon:
A(P_1,P_2,P_3,P_4,P_5)=\tfrac 1 2
\begin{vmatrix} 3 & 7 & 4 & 8 & 1 & 3\\
1 & 2 & 4 & 6 & 7 & 1 \end{vmatrix}= 20.5
- green triangle:
A(P_2, P_3, P_4)=\tfrac 1 2
\begin{vmatrix} 7 & 4 & 8 & 7\\
2 & 4 & 6 & 2 \end{vmatrix} = -7
- red triangle:
A(P_1,Q,P_2)=\tfrac 1 2
\begin{vmatrix} 3 & 4 & 7 & 3\\
1 & 3 & 2 & 1 \end{vmatrix} = -3.5
- blue polygon minus point
P_3 :A(P_1, P_2, P_4, P_5)=\tfrac 1 2
\begin{vmatrix} 3 & 7 & 8 & 1 & 3\\
1& 2 & 6 & 7 & 1 \end{vmatrix}= 27.5
- blue polygon plus point
Q betweenP_1,P_2 :A(P_1, Q, P_2, P_3, P_4, P_5)=\tfrac 1 2
\begin{vmatrix} 3 & 4 & 7 & 4& 8 & 1 &3\\
1 & 3 & 2 & 4& 6 & 7 &1 \end{vmatrix} = 17
One checks, that the following equations hold:
Generalization
In higher dimensions the area of a polygon can be calculated from its vertices using the exterior algebra form of the Shoelace formula (e.g. in 3d, the sum of successive cross products):
This formulation can also be generalized to calculate the volume of an n-dimensional polytope from the coordinates of its vertices, or more accurately, from its hypersurface mesh.{{Cite journal|last1=Allgower|first1=Eugene L.|last2=Schmidt|first2=Phillip H.|date=1986|title=Computing Volumes of Polyhedra|url=https://www.ams.org/journals/mcom/1986-46-173/S0025-5718-1986-0815838-7/S0025-5718-1986-0815838-7.pdf|journal=Mathematics of Computation|volume=46|issue=173|pages=171–174|doi=10.2307/2008221|jstor=2008221 |issn=0025-5718|doi-access=free}} For example, the volume of a 3-dimensional polyhedron can be found by triangulating its surface mesh and summing the signed volumes of the tetrahedra formed by each surface triangle and the origin:
{{Math proof|Apply the divergence theorem to the vector field
So
For each triangular face
denote the outward normal vector by
The flux of
For each point
So the integrand is constant
where
The total flux is the sum of the fluxes through all faces:
}}
See also
External links
- [https://www.youtube.com/watch?v=0KjG8Pg6LGk Mathologer video about Gauss's shoelace formula]