# Fourier Series of Curves: Background
This notebook introduces Fourier series of (closed) curves and shows how to compute them.

The goal is take a continuous line drawing (i.e. something drawn with a single line) and to recreate the drawing process using circles rotating around each others. An example can be seen below:

Start: A Line Drawing | Goal: Circles drawing the line
- | - 



```python
%matplotlib inline

# Initial imports
import numpy as np
import matplotlib.pyplot as plt
```

Enabling equation numbering


```javascript
%%javascript
MathJax.Hub.Config({
    TeX: { equationNumbers: { autoNumber: "AMS" } }
});

MathJax.Hub.Queue(
  ["resetEquationNumbers", MathJax.InputJax.TeX],
  ["PreProcess", MathJax.Hub],
  ["Reprocess", MathJax.Hub]
);
```


    <IPython.core.display.Javascript object>


## Prerequisites
For the following, you should be familiar with:
- __Complex numbers.__ This notebook represents points as complex numbers and uses also a complex form of Fourier Series. For this reason, an understanding of complex numbers is required.  


## Representing Line Drawings
Starting with an image as shown above is not sufficient enough to recreate the drawing process. We need the information at which point in time which part of the image was drawn. For this reason, we represent the line drawing as a closed curve. 

Such a curve is given by a continuous function $f:[a,b]\to\mathbb{C}$ over the time-interval $[a,b]$ with $f(a) = f(b)$. Often, we will just set $a=0$ and $b=1$, but we will also allow for more general definitions.

### Concatenating Lines
It is possible to concatenate curves to get a longer, piecewise defined curve. Examples for such piecewise defined curves are polygons (as concatenations of straight lines), splines or paths in an svg-image.

Formally, a piecewise defined curve $f:[a,b]\to\mathbb{C}$ is given by a sequence $a=t_0 < t_1 < \ldots < t_n=b$ of border-points of the pieces and a corresponding number of curves $f_i:[t_i,t_{i+1}]\to\mathbb{C}$ ($i=0,\ldots,n-1$) with $f(t) = f_i(t)$ for $t\in[t_i,t_{i+1}[$ and $f(b) = f_{n-1}(b)$.

In our case, we also want $f$ to fulfill the following conditions:
- __Continuity__ of $f$: all $f_i$ need to be continuous and connected, i.e. $f_i(t_{i+1}) = f_{i+1}(t_{i+1})$
- A __Closed Curve__ $f$, i.e. $f(a) = f(b)$

## Representing Circles
Looking at the target animation, we see a center circle and a second circle rotating on the first circle. A third circle rotates on the second one and so on. This is depicted in the following figure:


Mathematically, each circle $k$ ($k=1,\ldots n$) is given by 
- a center point $p_k$ and 
- a radius $r_k$.

The position of a point $q_k$ rotating on the circle can be determined by 
- a starting angle $\alpha_k$ and 
- the speed of this point $\beta_k$.

On a non-moving circle $k$, the coordinates of $q_k$ at time $t$ are then given by
$$
\begin{equation}
    q_k(t) = p_k + r_k\left(\cos(\alpha_k+t\cdot\beta_k)\atop \sin(\alpha_k+t\cdot\beta_k)\right)
    \label{eqn:circle_vec}
\end{equation}
$$

Using complex numbers (\ref{eqn:circle_vec}) can be written as:
$$
\begin{equation}
    q_k(t) = p_k + r_ke^{i(\alpha_k+t\cdot\beta_k)} = p_k + \underbrace{r_ke^{i\alpha_k}}_{=:c_k}e^{i\beta_kt}
    \label{eqn:circle_complex}
\end{equation}
$$

Since the centers of our circles are rotating on other circles, we get for $k > 1$ a time-dependent center of $p_k(t) = q_{k-1}(t)$. This allows us to rewrite (\ref{eqn:circle_complex}) as:

$$
\begin{equation}
    q_k(t) = p_k(t) + c_ke^{i\beta_kt}
           = p_{k-1}(t) + c_{k-1}e^{i\beta_{k-1}t} + c_ke^{i\beta_kt} = \ldots = p_1 + \sum_{j=1}^kc_je^{i\beta_jt}
    \label{eqn:circle_as_sum}
\end{equation}
$$

### Drawing closed curves
When looking at the introductory example, we see that the point $q_n$ in the last (i.e. the $n$-th) circle draws the line. 
for each interval $[a,b]$, the function $f:[a,b]\to\mathbb{C}$ with $f(t) := q_n(t)$ defines a curve.

This way of formulating the rotating circles, and especially the last, line-drawing dot $q_{n}$ strongly resembles the complex formulation of a Fourier series, which we will briefly review in the following.

## Fourier series of a closed curve
Fourier series and Fourier transformation are a well-known concept to approximate periodic functions.
Given a integrable T-periodic $f:\mathbb{R}\to\mathbb{R}$ or $f:\mathbb{R}\to\mathbb{C}$, with $f(t+T) = f(t)$, the Fourier series of $f$ is defined by its finite subsequences:

$$
\begin{equation}
    \hat{f}_n(t) = \sum_{k=-n}^n c_ke^{i\frac{2\pi kt}{T}}
    \label{eqn:fourier_series}
\end{equation}
$$

with Fourier coefficients

$$
\begin{equation}
    c_k := \frac{1}{T}\int_0^{T}f(t)e^{-i\frac{2\pi kt}{T}}dt
    \label{eqn:fourier_coefficients}
\end{equation}
$$

#### Redrawing closed curves
A closed curve $f$ over the interval $[a,b]$ can easily be extended to an $(b-a)$-periodic function over $\mathbb{R}$, which iterates over and over again over the original curve. Thus, we can compute the Fourier coefficients using (\ref{eqn:fourier_coefficients}). In the following, we assume that $f$ is defined over an interval $[0,T]$.

The Fourier approximation (\ref{eqn:fourier_series}) of the curve $f$ resembles equation (\ref{eqn:circle_as_sum}) with a different range of indices, $p_1 = c_0$ and $\beta_k = \frac{2\pi k}{T}$. This means, that the Fourier series contains all required parameters for the circles that can redraw $f$.


#### Convergence
There is not guarantee, that $\hat{f}_n$ converges in the general case and if it converges, it does not necessarily converge against $f$. 
Luckily, (pointwise) convergence is guaranteed for continuous almost always differentiable functions. Since our main focus is on continuous piecewise curves with differential pieces, this condition is met.

### Piecewise defined functions
As mentioned above, a curve can be given as a concatenation of smaller curves. In that case, the interval $[0,T]$ is split into $0=t_0 < t_1 < \ldots < t_n=T$ with $f(t) = f_j(t)$ for $t\in[t_j,t_{j+1}[$ and $f(T) = f_{n-1}(T)$.

This means, that we can rewrite (\ref{eqn:fourier_coefficients}) as:

$$
\begin{equation}
    c_k := \frac{1}{T}\int_0^{T}f(t)e^{-i\frac{2\pi kt}{T}}dt = \frac{1}{T}\sum_{j=0}^{n-1}\int_{t_j}^{t_{j+1}}f_j(t)e^{-i\frac{2\pi kt}{T}}dt
    \label{eqn:fourier_piecewise_coefficients}
\end{equation}
$$

Thus, if we can compute for some classes of curves the arbitrary integral
$$
\begin{equation}
    \int_{a}^{b}g(t)e^{-i\lambda t}dt
    \label{eqn:fourier_piece_integral}
\end{equation}
$$

for all instances $g$ of these curves, we can also compute the Fourier series of all concatenations of such curves.

#### Examples
Examples for the computation of integral (\ref{eqn:fourier_piece_integral}) can be found in extra notebooks. These are:
- [Straight Lines](Fourier-Series-of-Curves-Example-1-Polygones.ipynb)
- [Ellipse Arcs](Fourier-Series-of-Curves-Example-2-Arcs.ipynb)
- [Bézier Curves](Fourier-Series-of-Curves-Example-3-Bezier.ipynb)

00b60c5abdaf548a8fee10cc20783d81e4d036b5
ipynb
Jupyter Notebook
Fourier-Series-of-Curves-Background.ipynb
Broele/Math-is-awesome-fourier
67639c0dca13590fcbeb7b20e0baad90bd459fa8
MIT
2020-02-09T11:56:47.000Z
2020-05-07T21:20:18.000Z
Fourier-Series-of-Curves-Background.ipynb
Broele/Math-is-awesome-fourier
67639c0dca13590fcbeb7b20e0baad90bd459fa8
MIT
Fourier-Series-of-Curves-Background.ipynb
Broele/Math-is-awesome-fourier
67639c0dca13590fcbeb7b20e0baad90bd459fa8
MIT
Qwen/Qwen-72B
1. YES
2. YES