# How to make simple closed curve that can be smoothly morphed using locators

Given a simple closed curve in 2D with some locators on it, I would like to have be able to stretch and squish parts of the curve by moving the locators to morph the curve into another simple closed curve. I'd also like the locators to stretch the curve smoothly (no sharp corners) as in this example...

DynamicModule[{pts = {{0, 0}, {1, 1}, {2, 0}, {3, 2}}},
LocatorPane[Dynamic[pts],
Dynamic[Plot[InterpolatingPolynomial[pts, x], {x, 0, 3},
PlotRange -> 3]]]]


The code above will not work for my problem as I'm not working with polynomial functions, but Its the same idea. I'm not sure where to start. Ideas?

• What is the problem here?, in using Locators or with performing smooth interpolation?
– Kuba
Commented Dec 28, 2017 at 13:37
• Performing the interpolation. Commented Dec 28, 2017 at 13:39
• I'd like to take a crack at it, I'm just not sure how interpolating works. If I can get a hint in the right direction, I'll work on it and post a solution. Commented Dec 28, 2017 at 13:48

Interpolate the x and y values separately and use PeriodicInterpolation by appending the first value of each list at the end:

plot[pts_] := Module[{xs, ys},
{xs, ys} = Append[#, #[[1]]] & /@ Transpose[pts];
With[{ip =
ListInterpolation[#, {{0, 1}}, InterpolationOrder -> 3,
PeriodicInterpolation -> True] & /@ {xs, ys}},
ParametricPlot[Through[ip[t]], {t, 0, 1},
PlotRange -> {{-1, 2}, {-1, 2}}]
]
]

DynamicModule[{pts = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}},
LocatorPane[Dynamic[pts], Dynamic[plot[pts]]]]