# What function could describe this GIF animation?

I found this image on Beautiful Mathematical GIFs Will Mesmerize You and this GIF really caught my attention. From what I see, it's a 2D circle morphing into the 3D sphere. What function could describe this GIF animation? All comments are appreciated.

z < 0 -> red
z > 0 -> green
z = 0 -> blue


• I'm really not sure if math.SE is the right place for this kind of questions. Pardon me if the question does not belong here and I will delete it. – user117071 Feb 15 '15 at 20:39
• Imagine a sphere and a "meridian" circle that connects two poles of the sphere. Now imagine that upper half of sphere is rotated clockwise, and other half -- counterclockwise. Also imagine that the amount of rotation depends on "latitude". Now the choice of concrete functions is up to you :) – Evgeny Feb 15 '15 at 20:41
• To guess its parametrization ? arclength increases and decreases like some $L\, sin^2 (\omega t)$ function of time parameter. – Narasimham Feb 15 '15 at 20:59
• Original source: Bees & Bombs – twisting circle (processing source code). Via twitter. – horchler Feb 15 '15 at 21:19

Here's a pretty direct translation to Mathematica of the processing code pointed out by horchler. It's littered with spherical coordinates and I've placed the path on a sphere so that we can clearly see its 3D origin.

pics = Table[
tw = 0.5 (1 - Cos[2 Pi*t]);
tw = 3 Pi (0.5*tw + 1.5*tw*tw - tw*tw*tw);
n = 720;
r = 220;
pts = Table[
th = 2 Pi*i/n;
ph = tw*Cos[th];
x = r*Cos[th];
y = r*Sin[th] Cos[ph];
z = r*Sin[th]*Sin[ph];
xx = x*Cos[Pi*t] - z*Sin[Pi*t];
zz = -x*Sin[Pi*t] - z*Cos[Pi*t];
{xx, y, zz},
{i, 0, n - 1}];
Rasterize[
Graphics3D[{{Opacity[0.2], Sphere[{0, 0, 0}, r]}, Tube[pts]},
ViewPoint -> {1, 0, 10},
ViewVertical -> {0, 1, 0}, Boxed -> False], RasterSize -> 800,
ImageSize -> 400],
{t, 0, 1, 0.02}];
ListAnimate[pics]


Here's my original answer that I obtained by just looking at the image.

We can get something like the middle phase as follows. First, define $r_1$ and $r_2$ by \begin{align} r_1(t) &= \sqrt[3]{|\cos(t/m)|} \\ r_2(t) &= \sqrt{|\cos((t-m\pi)/n)}, \end{align} where $m=3$ and $n=9$. Then, $$p(t) = \left\{ \begin{array}{cc} r_1(t) \, \langle \cos(t), \text{sgn}(r_1(t)) \sin(t) \rangle & 0 \leq t \leq m\pi \\ r_2(t) \, \langle \cos((t-(m-1)\pi)), -\text{sgn}(r_2(t)) \sin((t-(m-1)\pi)) \rangle & m\pi < t \leq (m+n)\pi. \end{array} \right.$$ We can plot it in Mathematica:

{m, n} = {3, 9};
p[t_] := Piecewise[{
{CubeRoot[Abs[Cos[t/m]]] {Cos[t], Sign[Cos[t/m]] Sin[t]}, 0<=t<=m*Pi},
{Sqrt[Abs[Cos[(t - m*Pi)/n]]]*
{Cos[(t-(m-1)*Pi)], -Sign[Cos[(t-m*Pi)/n]]*Sin[(t-(m-1)*Pi)]},
m*Pi <= t <= (m + n) Pi}
}];
ParametricPlot[p[t], {t, 0, (m + n)*Pi},
ColorFunction -> (Darker[ColorData["GrayYellowTones"][Sin[Pi #3]]] &),
PlotStyle -> Directive[Opacity[0.8], Thickness[0.015]],
Exclusions -> None, Axes -> None]


I can't quite seem to get the animation, though.

The source code shows it: in spherical coordinates, $\phi=t_w\cos(\theta)$ where $t_w$ changes periodically over time between $0$ and $1$ (as a third degree polynomial of the cosine). The "sphere" also rotates uniformly and is displayed with perspective.

• @Henry: quite right. – Yves Daoust Feb 16 '15 at 11:30

$$\begin{cases} x=\sin(t)\cos(\lambda t) \\ y=\cos(t)\cos(\lambda t) \\ z=\sin(\lambda t) \\ \end{cases}$$

• Note that this is a closed sperical curve. – LCFactorization Apr 20 '15 at 7:09