Polygon Collision Detection Function using Dirac Delta Distribution and Divergence Therom, help. I would like to find a way of doing polygon collision detection that handles concave/irregular polygons in a very performant matter.  I would be great if you guys could check my math and reasoning up to the point I'm stuck at, and also help me figure out the last question.
So starting off with what we know, we know that we can find the area of any two dimensional polygon shape B by using the Divergence Theorem:
$$
\iint_B\vec{\nabla}\cdot\vec{F}dA = \oint_{\partial B}(\vec{F}\cdot\hat{n})ds
$$
where $\hat{n}$ is the normal of the boundary of the pologyon. We can use this therom to find the area based soley on the positions of the vertices of B:
$$
\iint_BdA = \frac{1}{2}\oint_{\partial B}\vec{v} \cdot \hat{n}ds = \frac{1}{2}\oint_{\partial B} \vec{v} \cdot d\vec{r}_{\bot}
$$
$$
 = \frac{1}{2}\sum_{i=1}^{j}\int_0^1[(1-t)\vec{P}_i+t\vec{P}_{i+1}] \cdot (\vec{P}_{(i+1)\bot} - \vec{P}_{(i)\bot})dt = \frac{1}{2}\sum_{i=1}^j\vec{P}_i \cdot \vec{P}_{(i+1)\bot}
$$
Where $\vec{v} = x(t)\hat{i}+y(t)\hat{j}$ and $\vec{P}_i$ is the positions of the vertices of the polygon and $\vec{v}_{\bot}$ is the normal of $\vec{v}$.  Also $(i+1)$ will loop around to $i=1$ in the summation once $i = j$.  
What we just did is found the amount of intesity of $f(\vec{x})=1$ inside $B$, right? Assuming yes, then the idea is that we can replace $f(\vec{x})=1$ with any funtion and find the total intesity of $f(\vec{x})$ inside the region B. 
So with that in mind, we can find a funtion $f(\vec{x})$ whose value would be 1 if $\vec{x}$ is inside the polygon B and zero otherwise. I would like to find an algerbraic representation of this $f(\vec{x})$ based on the $\vec{P}_i$ as we did above for the area. So going down that same route:
$$
f(\vec{x}) = \iint_B\delta^2(\vec{s}-\vec{x})d^2s = \oint_{\partial B}\vec{\gamma}\cdot d\vec{b}_{\bot}
$$
Where $\vec{b}$ is the paramterization of B under the  $\vec{s}$ coordinates. I would like to find $\vec{\gamma}$ such that:
$$
\vec{\nabla} \cdot \vec{\gamma} = \delta^2(\vec{x}-\vec{s})
$$
Is it possible to find a representation of $\vec{\gamma}$ in terms of the Heavi-side step function or other generalized distributions?
Thanks for your time.
 A: As a starting point, consider the Green's function of the two-dimensional Laplacian:
$$f(x,s) = \log(\|x-s\|).$$
Its gradient $\gamma(x,s) = \frac{x-s}{\|x-s\|^2}$ is by construction divergence-free, so if $s$ is outside the polygon,
$$\int_{\delta B} \gamma\cdot \hat{n}\,dS=0,$$
and when $s$ is inside,
$$\int_{\delta B} \gamma\cdot \hat{n}\,dS=2\pi.$$
Moreover, if $J\gamma$ denotes rotation of $\gamma$ by ninety degrees, we have
$$J\gamma = \nabla \arctan\left(\frac{x_y-s_y}{x_x-s_x}\right)$$
so over an edge $E$ connecting $P_i$ to $P_{i+1}$ we get
$$\int_E \gamma\cdot \hat{n}\, dS = \int_E J\gamma \cdot dt = \theta,$$
where 
$$\theta = \arctan\left(\frac{{P_{i+1}}_y-s_y}{{P_{i+1}}_x-s_x}\right)-\arctan\left(\frac{{P_{i}}_y-s_y}{{P_{i}}_x-s_x}\right)$$
is the (signed) angle $(P_i,s,P_{i+1})$.
As a final note, by thresholding appropriately the above can be used not only to detect when a point is inside a polygon, but also when a point is inside an arbitrary collection of line segments in the rough shape of a polygon: see for instance this recent publication.
