Transforming a numerically unstable line integral into a (more) stable one Given a closed planar curve $\Gamma(t) = \big(x(t), y(t)\big)$, say $t \in [0,1]$, and a point $P = (x_P, y_P)$ in its interior,  I'm interested in computing the following integral:
$$\frac{1}{2\pi} \int_0^1 f(t) \frac{R(t) \cdot N(t)}{\|R(t)\|^2} dt,$$
where $f(t)$ is a known function, $R(t) = \Gamma(t) - P$ and $N(t)$ is the unnormalised normal vector at $\Gamma(t)$ pointing away from the interior. Now, for a point $P$ close to the boundary (which results in a small $\|R\|$), the denominator becomes an issue when trying to compute/approximate the integral using a numerical approach. I'm therefore looking for a way to transform this integral into something that is easier to work with from a numerical point of view.
So far, I found that the integral is similar to the one that can be used to compute the winding number for $P$ in $\Gamma(t)$. Recall that the winding number $w$ is essentially the number of (counter-clockwise) rotations an observer standing at $P$ makes while tracking an object traversing the curve from start to end. Note that without loss of generality, we can assume $P$ to be at the origin (i.e. we can move the curve — with $P$ in it — such that $P$ ends up at the origin). Then, if we express $\Gamma(t)$ as $\big(r(t), \theta(t)\big)$, with $r^2(t) = x^2(t) + y^2(t)$ and $\theta(t) = \mathrm{atan}\big(y(t), x(t)\big)$, we get
$$2\pi w = \theta(1) - \theta(0) = \oint_\Gamma d\theta = \int_0^1 \frac{d\theta}{dt} dt = \int_0^1 \frac{x(t)\frac{dy}{dt} - y(t)\frac{dx}{dt}}{x^2(t) + y^2(t)} dt.$$
Note that the tangent vector of $\Gamma(t)$ is $\frac{d\Gamma}{dt} = \left( \frac{dx}{dt}, \frac{dy}{dt} \right)$, and assuming $\Gamma(t)$ to be parameterised counter-clockwise, the normal follows as $N(t) = \left( \frac{dy}{dt}, -\frac{dx}{dt} \right)$. Therefore, we obtain
$$w = \frac{1}{2\pi} \int_0^1 \frac{R(t) \cdot N(t)}{\|R(t)\|^2} dt,$$
which is similar to the integral I'm interested in. Why this detour? Well, I wondered whether this approach could perhaps be applied in reverse and obtain an integral $\oint_\Gamma \ldots d\theta$, which would be great as such an integral is (much) easier to work with from a numerical perspective (i.e. no nasty denominator).
Finally, the following alternative way of expressing $w$ might be helpful:
$$w= \frac{1}{2\pi} \oint_\Gamma \frac{R(t) \cdot N(t)}{\|R(t)\|^2 \|\frac{d\Gamma}{dt}\|} d\Gamma = \frac{1}{2\pi} \oint_\Gamma \frac{1}{\|R(t)\|} \left( \frac{R(t)}{\|R(t)\|} \cdot \frac{N(t)}{\|N(t)\|} \right) d\Gamma = \frac{1}{2\pi} \oint_\Gamma \frac{1}{\|R(t)\|} \cos \varphi(t) d\Gamma,$$
where $\varphi(t)$ is the angle between $R(t)$ and $N(t)$.
 A: The following is a "brutal" approximation.
Rewrite the integral as
$$
  \frac{1}{2\pi}\int_0^1 f(t) \frac{R(t) \cdot N(t) \, ||N(t)||}{||R(t)||^2||N(t)||} \, dt
=
  \frac{1}{2\pi}\int_0^1 f(t) \frac{||N(t)||}{||R(t)||} \cos\bigl(\theta(t)\bigr) \, dt
$$
where $\theta(t)$ is the acute angle between $N(t)$ and $R(t)$. Then chop the domain of the integrand into four portions:

*

*A portion where $||R(t)||$ is large.


*A portion where $||R(t)||$ is small and $\cos\bigl(\theta(t)\bigr)$ is small.


*Another portion where $||R(t)||$ is small and $\cos\bigl(\theta(t)\bigr)$ is small.


*A portion where $||R(t)||$ is small and $\cos\bigl(\theta(t)\bigr)$ is large.
Then integrate over portions (1) and (4), and ignore (2) & (3).
(Think of $\Gamma$ as the unit circle.  Imagine $p = (1-\delta,0)$ for small $\delta > 0$.  Then "zoomed up close" to $p$, $\Gamma$ looks like the line $x=1$.)
A: (This one is a bit of a handwaving guess - details may need checking.)
Rewrite the integral as
$$\begin{align*}
  \frac{1}{2\pi}\int_0^1 f(t) \frac{R(t) \cdot N(t) \, ||N(t)||}{||R(t)||^2||N(t)||} \, dt
&=
  \frac{1}{2\pi}\int_0^1 f(t) \frac{||N(t)||}{||R(t)||} \cos\bigl(\theta(t)\bigr) \, dt
\\ &=
  \text{Re} \left[ \frac{1}{2\pi}\oint_\Gamma g(z) \, dz \right]
\end{align*}$$
where $g(z) = \displaystyle f(z) \frac{||N(z)||}{||R(z)||} e^{iz}$.
Find the points $\{a_k\}_k$ on the interior of $\Gamma$ where $g$ is not holomorphic.  This would be $p$ and perhaps others.
Apply the Residue theorem
$$
  \oint_\Gamma g(z) \, dz
  =
  2\pi i \sum_k \text{Res}(g, a_k)
$$
