I want to compute a integral of a polynomial $f(x, y)$ over a polygon domain $D$ of $n$ sides.


$$
I(f) = \int\_{D} f(x, \ y) \ dx \ dy
$$


The vertex of this polygon are


$$\vec{p}\_{i} = (x\_i, \ y\_i) \ \ \ \ \ \ \ \ \forall \ i = 1, \ 2, \ \cdots , \ n$$


The main aproach is transform this integral over the domain in a integral over the boundary using Green's theorem.


$$
\int\_{D} \left(\dfrac{\partial Q}{\partial x} - \dfrac{\partial P}{\partial y}\right)\ dA = \oint\_{C} P \ dx + Q \ dy
$$


Where the path $C$ is


$$
\partial D = C = C\_1 \cup C\_2 \cup \cdots \cup C\_{n} = \bigcup\_{i=1}^{n} C\_{i}
$$


And $C\_{i}$ is defined by the linear parametrization with $t \in \left[0, \ 1\right] $


$$
\vec{p}(t) = \left(1-t\right)\cdot \vec{p}\_{i} + t \cdot \vec{p}\_{i+1}
$$
$$
x(t) = \left(1-t\right) \cdot x\_{i} + t \cdot x\_{i+1}
$$
$$
y(t) = \left(1-t\right) \cdot y\_{i} + t \cdot y\_{i+1}
$$


And therefore the integral $I$ is just


$$
I = \sum\_{i = 1}^{n} \int\_{C\_i} P \ dx + Q \ dy = \sum\_{i = 1}^{n} \int\_{0}^{1} \left(P, \ Q\right) \cdot \dfrac{d\vec{p}}{dt} \ dt
$$


$$
\boxed{ I =
\sum\_{i = 1}^{n} \int\_{0}^{1} \left(P, \ Q\right) \cdot \left(\vec{p}\_{i+1}-\vec{p}\_{i}\right) \ dt}
$$


To compute this integral, I can choose whatever I want for $P$ and $Q$ such that


$$
f(x, \ y) = \dfrac{\partial}{\partial x} Q(x, \ y) - \dfrac{\partial}{\partial y} P(x, \ y)
$$


And then compute the sum.


**The question:** Why the expression is not unique?


Like, if I choose a pair $(P\_1, \ Q\_1)$, I get a function $g\_1(x\_1, \ y\_1, \ \cdots, \ x\_{n}, \ y\_{n})$.
But if I choose another pair $(P\_2, \ Q\_2)$, I get $g\_2(x\_1, \ y\_1, \ \cdots, \ x\_{n}, \ y\_{n})$ with


$$
g\_1 \ne g\_2
$$


**Example:** In the video [Michael Penn - Overkill - The area of a rectangle](https://youtu.be/Y2cBpBLJlfU) we have $f(x, y) = 1$.


Then he chose $P = 0$ and $Q = x$ to get


$$
I(1) = \sum\_{i = 1}^{n} \dfrac{(x\_{i+1}+x\_{i})(y\_{i+1}-y\_{i})}{2}
$$


But if I choose $P=-y$ and $Q = 0$ I get


$$
I(1) = \sum\_{i=1}^{n} \dfrac{(x\_{i+1}-x\_{i})(y\_{i+1}+y\_{i})}{2}
$$



Double integral in a polygon domain
In the example, I got that


$$
I(1) = \sum\_{i=1}^{n} \dfrac{(x\_{i+1}+x\_{i})(y\_{i+1}-y\_{i})}{2} = \sum\_{i=1}^{n} \dfrac{(x\_{i+1}-x\_{i})(y\_{i+1}+y\_{i})}{2}
$$


And it's indeed correct. If I expand around $j$, I get that


$$
I(1) = \sum\_{i=1}^{j-2} \square + x\_{j}\left(y\_{j+1}-y\_{j-1}\right) + y\_{j}\left(x\_{j-1}-x\_{j+1}\right)+ \sum\_{i=j+1}^{n} \square
$$


To say that


$$
\dfrac{\partial}{\partial x\_{j}} I(1) = y\_{j+1} - y\_{j-1}
$$
$$
\dfrac{\partial}{\partial y\_{j}} I(1) = x\_{j-1} - x\_{j+1}
$$


For other polynomials $f$, it's harder to get a closed formula to that.


