# 2D convolution of two circles

Imagine if two circles exist with definitions of $$f_1(r) = circ(\frac{r}{R_1})$$ and $$f_2(r) = circ(\frac{r}{R_2})$$ where circ is defined in a 2d dimension as:

$$circ(\frac{r}{R}) = \begin{cases} 1, & r \leq R \\ 0, & oth. \end{cases}$$

Where $$r = \sqrt{x^2+y^2}$$ in the 2d dimension. How is the convolution $$f_1(x,y) ** f_2(x,y)$$ or $$f_1(r) ** f_2(r)$$ calculated? Notably, I'm very curious about the visual representation of the convolution.

For circularly symmetric functions $$f(r)$$ and $$g(r)$$ we have

\begin{align*}(f**g)(x,y) &= \int_{-\infty}^\infty\int_{-\infty}^\infty f(x',y')g(x-x',y-y')dx' dy'\\ \\ &= \int_{-\infty}^\infty\int_{-\infty}^\infty f\left(\sqrt{x'^2+y'^2}\right)g\left(\sqrt{\left[x-x'\right]^2+\left[y-y'\right]^2}\right)dx' dy'\\ \\ &= \int_0^{2\pi}\int_0^\infty f\left(r'\right)g\left(\sqrt{\left[r\cos\theta-r'\cos\theta'\right]^2+\left[r\sin\theta-r'\sin\theta'\right]^2}\right)r'dr' d\theta'\\ \\ &= \int_0^{2\pi}\int_0^\infty f\left(r'\right)g\left(\sqrt{r^2+r'^2-2rr'\cos\theta\cos\theta'-2rr'\sin\theta\sin\theta'}\right)r'dr' d\theta'\\ \\ & (\text{pick }\theta=0 \text{, since the functions are circularly symmetric})\\ \\ &= \int_0^{2\pi}\int_0^\infty f\left(r'\right)g\left(\sqrt{r^2+r'^2-2rr'\cos\theta'}\right)r'dr' d\theta'\\ \\ &= (f**g)(r) \end{align*}

which hopefully makes some sense, in that the convolution is multiplying and summing contributions from $$g(r)$$ with a law of cosines hypotenuse type of displacement.

I cannot provide you with any alternative visual representation for the 2D polar convolution. I can say the operation is exactly equivalent to the 2D cartesian convolution of the two functions.

So let's assign $$f(r) = \mathrm{circ}(r/a)$$ and $$g(r)=\mathrm{circ}(r/b)$$, with $$a without loss of generality since convolution is commutative.

In the $$(r',\theta')$$ plane, $$f(r')$$ has boundary $$r'=a$$, which is a circle of radius $$a$$, centered at $$r'=0.$$

In the $$(r',\theta')$$ plane, $$g\left(\sqrt{r'^2+r^2-2rr'\cos\theta'}\right)$$ has a boundary given by $$b=\sqrt{r'^2+r^2-2rr'\cos\theta'}$$, which is a circle of radius $$b$$, centered at $$(r'=r, \theta' =0)$$.

This convolution now depends on $$4$$ separate intervals for $$r$$, since we're looking at how two disks of different size overlap in the $$(r',\theta')$$ plane, as the center, $$(r'=r, \theta'=0)$$, of one disk is varied in $$r'$$ along the $$\theta'=0$$ line.

The four intervals are

\begin{align*}0 \le &r \le b-a\\ b-a \le &r \le b\\ b \le &r \le b+a \\ b+a \le &r < \infty\\ \end{align*}

I. Interval $$0 \le r \le b-a$$

This one is easy. The larger disk completely overlaps the smaller disk, so the smaller disk dictates the bounds of the integrals. Hence, convolution in this interval is

$$(f**g)(r) = 2\int_0^\pi \int_0^a r'dr'd\theta' = a^2\pi$$

II. Interval $$b+a \le r < \infty$$

This one is easy. The larger disk has no overlap with the smaller disk. Hence the convolution in this interval is

$$(f**g)(r) = 0$$

III. Interval $$b-a \le r \le b$$

This one gets messy, but something that makes it slightly simpler is that the origin, $$r'=0$$, is still included in the region of overlap of the disks.

We have to break this convolution up into at least two double integrals, to capture the area of the overlap of the disk. (It's probably smarter/cleaner to break it up into 3 simpler integrals, but I'll go with the following 2 for now.)

To find the two regions, we need to find the angles $$\pm \theta'_c$$ where the boundaries of the 2 disks intersect. So substituting the equation for the one boundary, $$r'=a$$, into the equation for the other boundary:

$$b = \sqrt{a^2 +r^2 -2ar\cos\theta'_c}$$

we end up with

$$\theta'_c = \cos^{-1}\left[\dfrac{r}{2a}\left(1-\dfrac{(b+a)(b-a)}{r^2}\right)\right]$$

The first region, bounded by $$f(r')$$ on the right, is simple to set integral bounds for and compute the integral.

The second region, bounded by $$g\left(\sqrt{r'^2+r^2-2rr'\cos\theta'}\right)$$ on the left, requires us to use the quadratic formula to find the upper bound of integration on $$r'$$.

Starting from

$$b= \sqrt{r'^2 +r^2 -2rr'\cos\theta'}$$

followed by some algebra and the quadratic formula we get

$$r' =r\left[\cos\theta' \pm \sqrt{\left(\dfrac{b}{r}\right)^2-\sin^2\theta'}\right]$$

of which we take the $$+$$ branch to get radii $$r' > 0$$.

So the convolution in this interval is

\begin{align*}(f**g)(r) &= 2\int_0^{\theta'_c}\int_0^a r'dr'd\theta'\\ &\quad + 2\int_{\theta'_c}^\pi \int_0^{r\left[\cos\theta' + \sqrt{\left(\frac{b}{r}\right)^2-\sin^2\theta'}\right]} r'dr'd\theta'\\ \\ &= a^2 \cos^{-1}\left[\dfrac{r}{2a}\left(1-\dfrac{(b+a)(b-a)}{r^2}\right)\right]\\ &\quad + r^2\int_{\theta'_c}^\pi \left[\cos\theta' + \sqrt{\left(\frac{b}{r}\right)^2-\sin^2\theta'}\right]^2 d\theta'\\ \\ &= a^2 \cos^{-1}\left[\dfrac{r}{2a}\left(1-\dfrac{(b+a)(b-a)}{r^2}\right)\right]\\ &\quad + r^2\left.\left[\sin\theta'\left(\cos\theta' + \sqrt{\left(\frac{b}{r}\right)^2-\sin^2\theta'}\right) \\ \quad + \left(\dfrac{b}{r}\right)^2\left(\theta'+\tan^{-1}\left[\dfrac{\sin\theta'}{\sqrt{\left(\frac{b}{r}\right)^2-\sin^2\theta'}}\right]\right)\right] \right\rvert_{\theta'_c}^\pi \\ \\ &= \left(a^2-b^2\right) \cos^{-1}\left[\dfrac{r}{2a}\left(1-\dfrac{(b+a)(b-a)}{r^2}\right)\right]\\ &\quad+b^2\left[\pi-\tan^{-1}\left(\dfrac{r\sin\theta'_c}{\sqrt{b^2-r^2\sin^2\theta'_c}}\right)\right] \\ &\quad - r\sin\theta'_c\left(r\cos\theta_c' + \sqrt{b^2-r^2\sin^2\theta'_c}\right) \\ \end{align*}

which is pretty messy.

There is a way to compute the convolution in this interval using two circular sectors and then subtracting off the area of a triangle, which should yield a nicer expression.

IV. Interval $$b \le r \le b+a$$

This one is also messy. What makes it worse then the previous is that the origin is not included in the overlap of the disks, and the equation for the arc on the left hand side of the the region of overlap is not defined for all $$\theta'$$, since $$\dfrac{b}{r} < 1$$. It's still computable, but care must be taken to use intervals where $$\sin\theta' \le \dfrac{b}{r}$$.

I'll leave this interval as an exercise for the reader. :)