I'm having a little trouble calculating the winding number of a circle about a point using parametric equations.
The definition of a circle of radius $r$ and center coordinates $x_0$ and $y_0$ is the following two parametric equations:
$$x(t) = r * \sin 2 \pi t + x_0$$ $$y(t) = r * \cos 2 \pi t + y_0$$
Factoring in the point $p$, the parametric equations would look like the following:
$$x(t) = r * \sin 2 \pi t + x_0 - p_x$$ $$y(t) = r * \cos 2 \pi t + y_0 - p_y$$
The Winding Number is defined as:
$${1 \over 2\pi}\int_C {x \over r^2}dy - {y \over r^2} dx$$
where $r$ in this integral is defined as:
$$r^2 = x^2 + y^2$$
(not the radius of the circle)
$x$ and $y$ are equal to $x(t)$ and $y(t)$, respectively.
In order to integrate this differential equation, we must substitute $x(t)$ for $x(y)$ and $y(t)$ for $y(x)$.
$${1 \over 2\pi}\int_C {x(y) \over r^2}dy - {y(x) \over r^2} dx$$
However, finding $x(y)$ and $y(x)$ are irrelevant because this is a line integral, where
$$\int_C x(y)dy = \int_b^a x(y(t)) * y'(t)dt = \int_b^a x(t)y'(t)dt$$
and
$$\int_C y(x)dx = \int_b^a y(x(t)) * x'(t)dt = \int_b^a y(t)x'(t)dt$$
The final integral is now in respect to $t$:
$${1 \over 2 \pi} \int_b^a {x(t)y'(t) - y(t)x'(t) \over x^2(t) + y^2(t)} dt$$
To simplify the form of this equation, let $m = x_0 - p_x$ and $n = y_0 - p_y$. Substituting the functions, this turns into:
$${1 \over 2 \pi} \int_b^a {(r * \sin 2 \pi t + m) * (-2 \pi r * \sin 2 \pi t) - (r * \cos 2\pi t + n) * (2 \pi r * \cos 2 \pi t) \over r^2 * \sin^2 2\pi t + 2 r m \sin 2\pi t + m^2 + r^2 * \cos^2 2\pi t + 2 r n \cos 2\pi t + n^2} dt$$
Putting this into Mathematica, I get the equation:
$$- {\pi t + tan^{-1}{m \cos \pi t + (r - n) \sin \pi t \over (n + r)\cos \pi t + m \sin \pi t} \over 2 \pi}$$
However, running this in a pixel shader doesn't give me the result I expected. When running each pixel through a winding number test, I should get an output that looks like a circle. Instead, I get some weird trigonometric thing. Is there a mistake in my math somewhere, or perhaps a hole in my understanding?