Area of Arbitrary Polygon

In this post I look at various ways of calculating the area of an arbitrary polygon with n-vertices.

  1. By Integral
  2. Trapezoid formula
  3. Triangle formula
  4. Shoelace formula



1. Calculating Area by Integral

\[\int _A dA=\iint dx\,dy\]

The edges of the polygon may be expressed as follows.

\[\begin{cases}x = x_i + (x_{i+}-x_i)\,t \\ y = y_i + (y_{i+}-y_i)\,t \end{cases}\quad \mbox{with} \quad \begin{cases} i = 0,1,2,\cdots,n-1 \\ i+=i+1\mod n \end{cases}\quad \mbox{and} \quad 0 \le t \le 1\]

We can convert the area integral into a line integral by employing Green's theorem, which states that:

Let C be a positively oriented, piecewise smooth, simple closed curve in a plane, and let D be the region bounded by C. If L and M are functions of (x, y) defined on an open region containing D and have continuous partial derivatives there, then

\[\iint \left( \frac{\partial M}{\partial x} - \frac{\partial L}{\partial y} \right) dx\,dy= \oint \left( L\,dx + M\,dy \right)\]

By substitution of \(M(x,y)=x\) and \(L(x,y)=0\) we can restate the area equation as follows:

\[A = \iint dx\,dy \\= \oint x\,dy\]

We have defined the y-coordinate of each edge as:

\[y = y_i + (y_{i+}-y_i)\,t\]

Based on which we can say that:

\[\frac{dy}{dt} = (y_{i+}-y_i)\]

It follows that:

\[\begin{equation}\begin{split} A &=  \oint x\,dy \\&= \sum_{i=0}^{n-1} \int_0^1 \left[x_i + (x_{i+}-x_i)\,t\right](y_{i+}-y_i)\,dt\\&=\sum_{i=0}^{n-1}(y_{i+}-y_i)\left[x_i\left.t\right|_0^1 + (x_{i+}-x_i)\frac{1}{2}\left.t^2\right|_0^1\right]\\&=\frac{1}{2}\sum_{i=0}^{n-1}(y_{i+}-y_i) (2x_i+x_{i+}-x_i )\\& =\frac{1}{2}\sum_{i=0}^{n-1}(x_{i+}+x_i)(y_{i+}-y_i)\end{split}\end{equation}\]

The last line when expanded looks like below:

\[\begin{equation}\begin{split}y_1x_1+y_1x_0-y_0x_1-y_0x_0\\+y_2x_2+y_2x_1-y_1x_2-y_1x_1\\+y_3x_3+y_3x_2-y_2x_3-y_2x_2\\\cdot\,\cdot\,\cdot\,\cdot\,\\+y_n(x_n+x_{n-1})-y_{n-1}(x_n+x_{x-1})\end{split}\end{equation}\]

Remembering that \(x_n=x_0\) and \(y_n=y_0\), the the area of a polygon may be expressed as: 

\[A =\frac{1}{2}\sum_{i=0}^{n-1} (x_iy_{i+}-x_{i+}y_i)\]

The formula above is consistent with the following three calculation methods, which are intuitively easier to comprehend. I have simply presented the formulas, straight from the Wikipedia here, which explains in detail.

Note that, in keeping with the original Wiki post, the sequence of points are numbered from i=1 to i=n, as opposed to i=0 to i=n-1, ie \({\displaystyle P_{i}=(x_{i},y_{i}),i=1,\dots ,n}{\displaystyle P_{i}=(x_{i},y_{i}),i=1,\dots ,n}\).

Also, for the simplicity it is assumed that: \({\displaystyle P_{0}=P_{n},P_{n+1}=P_{1}}\).

2. Trapezoid formula

\[{\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}}}\]

3. Triangle fomula

\[{\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}}}\]

4. Shoelace formula

\[{\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}}}\]


Useful References

geometry - Why doesn't a simple mean give the position of a centroid in a polygon? - Mathematics Stack Exchange

Shoelace formula - Wikipedia


0 件のコメント:

コメントを投稿

Numerical Integration: 2nd and 4th order Runge-Kutta schemes

Second-order Runge-Kutta scheme (RK2) There are several variations of the second order Runge-Kutta schemes of numerical integration. They ar...