9
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ What is the problem here?, in using Locators or with performing smooth interpolation? $\endgroup$
    – Kuba
    Dec 28 '17 at 13:37
  • $\begingroup$ Performing the interpolation. $\endgroup$
    – B flat
    Dec 28 '17 at 13:39
  • $\begingroup$ 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. $\endgroup$
    – B flat
    Dec 28 '17 at 13:48
13
$\begingroup$

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]]]]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.