TITLE: How to determine whether a point is inside a closed region or not?
QUESTION [10 upvotes]: Take the following parametric equation of an implicit curve as an example:
$$
\left\{\quad
\begin{array}{rl}
x=& 9  \sin 2 t+5 \sin 3 t \\
y=& 9 \cos 2 t-5 \cos 3 t \\
\end{array}
\right.
$$

For an arbitrarily given point $P=(x_0,y_0)$, numerically, how to determine whether $P$ is inside the blue region defined by the curve or not?

REPLY [3 votes]: In general, you can determine whether a point lies within a closed curve by computing the winding number of the curve around the point.  For a smooth closed curve $\gamma=(\gamma_x, \gamma_y):[0,1]\rightarrow \mathbb{R}^2$ (where $\gamma(0)=\gamma(1)$), the winding number around a point $(x_0, y_0)$ not on the curve is equal to the line integral
$$
w_\gamma(x_0, y_0)=\frac{1}{2\pi}\oint_{\gamma}d\theta = \frac{1}{2\pi}\oint_{\gamma}\frac{(\gamma_x(t) - x_0) \gamma_y'(t) - (\gamma_y(t) - y_0) \gamma_x'(t)}{(\gamma_x(t) - x_0)^2+(\gamma_y(t)-y_0)^2}dt.
$$
The winding number is an integer, and is zero for a point outside the curve and positive (negative) for a point that is enclosed by the curve in a counterclockwise (clockwise) orientation.