Shoelace formula

The shoelace formula, shoelace algorithm, or shoelace method (also known as Gauss’s area formula and the surveyor’s formula)[1] is a mathematical algorithm to determine the area of a simple polygon whose vertices are described by their Cartesian coordinates in the plane.[2] It is called the shoelace formula because of the constant cross-multiplying for the coordinates making up the polygon, like threading shoelaces.[2] It has applications in surveying and forestry,[3] among other areas.

The formula was described by Albrecht Ludwig Friedrich Meister (1724–1788) in 1769[4] and is based on the trapezoid formula which was described by Carl Friedrich Gauss and C.G.J. Jacobi.[5] 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.[6] 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.[7]

在这里插入图片描述

Shoelace scheme for determining the area of a polygon with point coordinates {\displaystyle (x_{1},y_{1}),…,(x_{n},y_{n})}{\displaystyle (x_{1},y_{1}),…,(x_{n},y_{n})}

1 The polygon area formulas

在这里插入图片描述

Basic idea: Any polygon edge determines the signed area of a trapezoid. All these areas sum up to the polygon area.

Given: A planar simple polygon with a positively oriented (counter clock wise) sequence of points {\displaystyle P_{i}=(x_{i},y_{i}),i=1,\dots ,n}{\displaystyle P_{i}=(x_{i},y_{i}),i=1,\dots ,n} in a Cartesian coordinate system.
For the simplicity of the formulas below it is convenient to set {\displaystyle P_{0}=P_{n},P_{n+1}=P_{1}}{\displaystyle P_{0}=P_{n},P_{n+1}=P_{1}}.

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 {\displaystyle A}A of the formulas is negative. In any case {\displaystyle |A|}|A| is the sought area of the polygon.[8]

1.1 Trapezoid formula

The trapezoid formula sums up a sequence of oriented areas {\displaystyle A_{i}={\tfrac {1}{2}}(y_{i}+y_{i+1})(x_{i}-x_{i+1})}{\displaystyle A_{i}={\tfrac {1}{2}}(y_{i}+y_{i+1})(x_{i}-x_{i+1})} of trapezoids with {\displaystyle P_{i}P_{i+1}}{\displaystyle P_{i}P_{i+1}} as one of its four edges (see below):

{\displaystyle {\begin{aligned}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{aligned}}}{\displaystyle {\begin{aligned}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{aligned}}}

1.2 Triangle formula

The triangle formula sums up the oriented areas {\displaystyle A_{i}}A_{i} of triangles {\displaystyle OP_{i}P_{i+1}}{\displaystyle OP_{i}P_{i+1}}:[9]

{\displaystyle {\begin{aligned}A&={\frac {1}{2}}\sum {i=1}^{n}(x{i}y_{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_{n}y_{1}-x_{1}y_{n}{\Big )}\end{aligned}}}{\displaystyle {\begin{aligned}A&={\frac {1}{2}}\sum {i=1}^{n}(x{i}y_{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_{n}y_{1}-x_{1}y_{n}{\Big )}\end{aligned}}}

1.3 Shoelace formula

在这里插入图片描述

Shoelace scheme, vertical form: With all the slashes drawn, the matrix loosely resembles a shoe with the laces done up, giving rise to the algorithm’s name.

The determinant formulas are 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:

{\displaystyle {\begin{aligned}2A&=\underbrace {{\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}}} \&={\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}}&{\text{(horizontal shoelace scheme)}}\&={\begin{vmatrix}x_{1}&y_{1}\x_{2}&y_{2}\\vdots &\vdots \x_{n}&y_{n}\x_{1}&y_{1}\end{vmatrix}}&{\text{(vertical form)}}\end{aligned}}}{\displaystyle {\begin{aligned}2A&=\underbrace {{\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}}} \&={\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}}&{\text{(horizontal shoelace scheme)}}\&={\begin{vmatrix}x_{1}&y_{1}\x_{2}&y_{2}\\vdots &\vdots \x_{n}&y_{n}\x_{1}&y_{1}\end{vmatrix}}&{\text{(vertical form)}}\end{aligned}}}

1.4 Other formulas

{\displaystyle {\begin{aligned}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{aligned}}}{\displaystyle {\begin{aligned}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{aligned}}}
{\displaystyle A={\frac {1}{2}}\sum {i=1}^{n}x{i}(y_{i+1}-y_{i-1})}{\displaystyle A={\frac {1}{2}}\sum {i=1}^{n}x{i}(y_{i+1}-y_{i-1})}
A particularly concise statement of the formula can be given in terms of the exterior algebra. If {\displaystyle v_{1},\dots ,v_{n}}{\displaystyle v_{1},\dots ,v_{n}} are the consecutive vertices of the polygon (regarded as vectors in the Cartesian plane) then

{\displaystyle A={\frac {1}{2}}\cdot \left|\sum {i=1}^{n}v{i}\wedge v_{i+1}\right|.}{\displaystyle A={\frac {1}{2}}\cdot \left|\sum {i=1}^{n}v{i}\wedge v_{i+1}\right|.}

在这里插入图片描述

Example

在这里插入图片描述

Horizontal shoelace form for the example.

2 Example

For the area of the pentagon with

{\displaystyle {\begin{aligned}&P_{1}=(1,6),P_{2}=(3,1),P_{3}=(7,2),\&P_{4}=(4,4),P_{5}=(8,5)\end{aligned}}}{\displaystyle {\begin{aligned}&P_{1}=(1,6),P_{2}=(3,1),P_{3}=(7,2),\&P_{4}=(4,4),P_{5}=(8,5)\end{aligned}}}
one gets
{\displaystyle {\begin{aligned}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{aligned}}}{\displaystyle {\begin{aligned}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{aligned}}}
The advantage of the shoelace form: Only 6 columns have to be written for calculating the 5 determinants with 10 columns.

3 Deriving the formulas

3.1 Trapezoid formula

在这里插入图片描述

Deriving the trapezoid formula

The edge {\displaystyle P_{i},P_{i+1}}{\displaystyle P_{i},P_{i+1}} determines the trapezoid {\displaystyle (x_{i},y_{i}),(x_{i+1},y_{i+1}),(x_{i},0),(x_{i+1},0)}{\displaystyle (x_{i},y_{i}),(x_{i+1},y_{i+1}),(x_{i},0),(x_{i+1},0)} with its oriented area

{\displaystyle A_{i}={\tfrac {1}{2}}(y_{i}+y_{i+1})(x_{i}-x_{i+1})}{\displaystyle A_{i}={\tfrac {1}{2}}(y_{i}+y_{i+1})(x_{i}-x_{i+1})}
In case of {\displaystyle x_{i}<x_{i+1}}{\displaystyle x_{i}<x_{i+1}} the number {\displaystyle A_{i}}A_{i} is negative, otherwise positive or {\displaystyle A_{i}=0}{\displaystyle A_{i}=0} if {\displaystyle x_{i}=x_{i+1}}{\displaystyle x_{i}=x_{i+1}}. In the diagram the orientation of an edge is shown by an arrow. The color shows the sign of {\displaystyle A_{i}}A_{i}: red means {\displaystyle A_{i}<0}{\displaystyle A_{i}<0}, green indicates {\displaystyle A_{i}>0}{\displaystyle A_{i}>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

{\displaystyle A=\sum {i=1}^{n}A{i}={\frac {1}{2}}\sum {i=1}^{n}(y{i}+y_{i+1})(x_{i}-x_{i+1})}{\displaystyle A=\sum {i=1}^{n}A{i}={\frac {1}{2}}\sum {i=1}^{n}(y{i}+y_{i+1})(x_{i}-x_{i+1})}

3.2 Triangle form, determinant form

在这里插入图片描述

Triangle form: The color of the edges indicate, which triangle area is positive (green) and negative (red) respectively.

Eliminating the brackets and using {\textstyle \sum {i=1}^{n}x{i}y_{i}=\sum {i=1}^{n}x{i+1}y_{i+1}}{\textstyle \sum {i=1}^{n}x{i}y_{i}=\sum {i=1}^{n}x{i+1}y_{i+1}} (see convention {\displaystyle P_{n+1}=P_{1}}{\displaystyle P_{n+1}=P_{1}} above), one gets the determinant form of the area formula:

{\displaystyle A={\frac {1}{2}}\sum {i=1}^{n}(x{i}y_{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}}}{\displaystyle A={\frac {1}{2}}\sum {i=1}^{n}(x{i}y_{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}}}
Because one half of the i-th determinant is the oriented area of the triangle {\displaystyle O,P_{i},P_{i+1}}{\displaystyle O,P_{i},P_{i+1}} this version of the area formula is called triangle form.

3.3 Other formulas

With {\textstyle \sum {i=1}^{n}x{i}y_{i+1}=\sum {i=1}^{n}x{i-1}y_{i}\ }{\textstyle \sum {i=1}^{n}x{i}y_{i+1}=\sum {i=1}^{n}x{i-1}y_{i}\ } (see convention {\displaystyle P_{0}=P_{n},P_{n+1}=P_{1}}{\displaystyle P_{0}=P_{n},P_{n+1}=P_{1}} above) one gets

{\displaystyle 2A=\sum {i=1}^{n}(x{i}y_{i+1}-x_{i+1}y_{i})=\sum {i=1}^{n}x{i}y_{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}}{\displaystyle 2A=\sum {i=1}^{n}(x{i}y_{i+1}-x_{i+1}y_{i})=\sum {i=1}^{n}x{i}y_{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 {\displaystyle y_{i}}{\displaystyle y_{i}} leads to
{\displaystyle A={\frac {1}{2}}\sum {i=1}^{n}y{i}(x_{i-1}-x_{i+1})}{\displaystyle A={\frac {1}{2}}\sum {i=1}^{n}y{i}(x_{i-1}-x_{i+1})}
With the identity {\textstyle \sum {i=1}^{n}x{i+1}y_{i}=\sum {i=1}^{n}x{i}y_{i-1}}{\textstyle \sum {i=1}^{n}x{i+1}y_{i}=\sum {i=1}^{n}x{i}y_{i-1}} one gets
{\displaystyle A={\frac {1}{2}}\sum {i=1}^{n}x{i}(y_{i+1}-y_{i-1})}{\displaystyle A={\frac {1}{2}}\sum {i=1}^{n}x{i}(y_{i+1}-y_{i-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.

4 Manipulations of a polygon

{\displaystyle A(P_{1},\dots ,P_{n})}{\displaystyle A(P_{1},\dots ,P_{n})} indicates the oriented area of the simple polygon {\displaystyle P_{1},\dots ,P_{n}}{\displaystyle P_{1},\dots ,P_{n}} with {\displaystyle n\geq 4}n\geq 4 (see above). {\displaystyle A}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 {\displaystyle 1<k<n}{\displaystyle 1<k<n}:

{\displaystyle A(P_{1},\dots ,P_{n})=A(P_{1},\dots ,P_{k-1},P_{k+1},\dots ,P_{n})+A(P_{k-1},P_{k},P_{k+1})}{\displaystyle A(P_{1},\dots ,P_{n})=A(P_{1},\dots ,P_{k-1},P_{k+1},\dots ,P_{n})+A(P_{k-1},P_{k},P_{k+1})}
In case of {\displaystyle k=1;{\text{or}};n}{\displaystyle k=1;{\text{or}};n} one should first shift the indices.
Hence:

Moving {\displaystyle P_{k}}P_k affects only {\displaystyle A(P_{k-1},P_{k},P_{k+1})}{\displaystyle A(P_{k-1},P_{k},P_{k+1})} and leaves {\displaystyle A(P_{1},…,P_{k-1},P_{k+1},…,P_{n})}{\displaystyle A(P_{1},…,P_{k-1},P_{k+1},…,P_{n})} unchanged. There is no change of the area if {\displaystyle P_{k}}P_k is moved parallel to {\displaystyle {\overline {P_{k-1}P_{k+1}}}}{\displaystyle {\overline {P_{k-1}P_{k+1}}}}.
Purging {\displaystyle P_{k}}P_k changes the total area by {\displaystyle A(P_{k-1},P_{k},P_{k+1})}{\displaystyle A(P_{k-1},P_{k},P_{k+1})}, which can be positive or negative.
Inserting point {\displaystyle Q}Q between {\displaystyle P_{k},P_{k+1}}{\displaystyle P_{k},P_{k+1}} changes the total area by {\displaystyle A(P_{k},Q,P_{k+1})}{\displaystyle A(P_{k},Q,P_{k+1})}, which can be positive or negative.
Example:

{\displaystyle P_{1}=(3,1),P_{2}=(7,2),P_{3}=(4,4),}{\displaystyle P_{1}=(3,1),P_{2}=(7,2),P_{3}=(4,4),}
{\displaystyle P_{4}=(8,6),P_{5}=(1,7),\ Q=(4,3)}{\displaystyle P_{4}=(8,6),P_{5}=(1,7),\ Q=(4,3)}

在这里插入图片描述

Manipulations of a polygon

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

blue polygon:
{\displaystyle 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}}=15.5}{\displaystyle 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}}=15.5}
green triangle:
{\displaystyle A(P_{2},P_{3},P_{4})={\tfrac {1}{2}}{\begin{vmatrix}7&4&8&7\2&4&6&2\end{vmatrix}}=-7}{\displaystyle 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:
{\displaystyle A(P_{1},Q,P_{2})={\tfrac {1}{2}}{\begin{vmatrix}3&4&7&3\1&3&2&1\end{vmatrix}}=-3.5}{\displaystyle 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 {\displaystyle P_{3}}P_{3}:
{\displaystyle 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}{\displaystyle 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 {\displaystyle Q}Q between {\displaystyle P_{1},P_{2}}P_{1},P_{2}:
{\displaystyle 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}{\displaystyle 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:

{\displaystyle A(P_{1},P_{2},P_{3},P_{4},P_{5})=A(P_{1},P_{2},P_{4},P_{5})+A(P_{2},P_{3},P_{4})=20.5}{\displaystyle A(P_{1},P_{2},P_{3},P_{4},P_{5})=A(P_{1},P_{2},P_{4},P_{5})+A(P_{2},P_{3},P_{4})=20.5}
{\displaystyle A(P_{1},P_{2},P_{3},P_{4},P_{5})+A(P_{1},Q,P_{2})=A(P_{1},Q,P_{2},P_{3},P_{4},P_{5})=17}{\displaystyle A(P_{1},P_{2},P_{3},P_{4},P_{5})+A(P_{1},Q,P_{2})=A(P_{1},Q,P_{2},P_{3},P_{4},P_{5})=17}

5 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):

{\displaystyle A={\frac {1}{2}}\left|\sum {i=1}^{n}v{i}\wedge v_{i+1}\right|}{\displaystyle A={\frac {1}{2}}\left|\sum {i=1}^{n}v{i}\wedge v_{i+1}\right|}
(when the vertices are not coplanar this computes the vector area enclosed by the loop, i.e. the projected area or “shadow” in the plane in which it is greatest).
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.[10] 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:

{\displaystyle V={\frac {1}{6}}\left|\sum {F}v{a}\wedge v_{b}\wedge v_{c}\right|}{\displaystyle V={\frac {1}{6}}\left|\sum {F}v{a}\wedge v_{b}\wedge v_{c}\right|}
where the sum is over the faces and care has to be taken to order the vertices consistently (all clockwise or anticlockwise viewed from outside the polyhedron). Alternatively, an expression in terms of the face areas and surface normals may be derived using the divergence theorem (see Polyhedron § Volume).

6 See also

Planimeter
Polygon area
Pick’s theorem
Heron’s formula

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值