Homotopy

Textbook example

Our textbook says that this function defines a homotopy between the unit circle and a square.

h[s_,t_] = (1-s)Exp[2Pi*I*t] +3s*(Piecewise[{{1+8I*t, 0≤t≤1/8}, {2-8t+I, 1/8≤t≤3/8}, {-1+4I(1-2t), 3/8≤t≤5/8}, {8t-6-I, 5/8≤t≤7/8}, {1+8*I(t-1), 7/8≤t≤1}}]);

Let’s check it out.

Manipulate[
ParametricPlot[{Re[h[s,t]],Im[h[s,t]]},{t,0,1},
PlotRange -> {{-3.2,3.2},{-3.2,3.2}},
PerformanceGoal->"Quality"],
{s,0,1}]

A somewhat more complicated example

hilbertStep[pts_] := Flatten[{
-I*Reverse[pts]/2+I/2,
pts/2+I/2,
pts/2+1/2+I/2,
I*Reverse[pts]/2+1
}];
mooreStep[pts_] := Flatten[{
I*pts/2+1/2,
I*pts/2+1/2+I/2,
-I*pts/2+1/2+I,
-I*pts/2+1/2+I/2
}];
init = {1/4+I/4,1/4+3I/4,3/4+3I/4,3/4+I/4};
moorePts[0] = Join[{1/2+I/4},init,{1/2+I/4}];
moorePts[k_] := Join[
{1/2+I/(2^(k+2))},
mooreStep[Nest[hilbertStep,init,k-1]],
{1/2+I/(2^(k+2))}
];
n = 4;
Do[
mooreCurveFunction[k] = BSplineFunction[complexToPoint/@(2moorePts[k]-(1+I))],
{k,0,n}];
hom[s_,t_] := (Piecewise[{{(1-s)mooreCurveFunction[0][t]+s*mooreCurveFunction[1][t], 0≤s<1}, {(2-s)mooreCurveFunction[1][t]+(s-1)mooreCurveFunction[2][t], 1≤s<2}, {(3-s)mooreCurveFunction[2][t]+(s-2)mooreCurveFunction[3][t], 2≤s<3}, {(4-s)mooreCurveFunction[3][t]+(s-3)mooreCurveFunction[4][t], 3≤s≤4}}]);
complexToPoint[z_] := {Re[z],Im[z]};
Manipulate[
ParametricPlot[hom[s,t],{t,0,1},
Axes->False,PerformanceGoal->"Quality",
PlotStyle -> Thick,
PlotRange->{{-1.1,1.1},{-1.1,1.1}}],
{s,0,4},
SaveDefinitions -> True]