3
$\begingroup$

I want to plot a curve starting from its curvature function and some initial conditions. This code generates a 2D curve with a given curvature (fun) and some initial conditions:

curveOfCurvatureK[
    fun_, a_: 0, {c_: 0, d_: 0, e_: 0}, {smin_: - 10, smax_: 10}, optsnd___][t_] :=
  Module[{x, y, θ, s}, 
    eqs = {x'[s] == Cos[θ[s]], 
    y'[s] == Sin[θ[s]], θ'[s] == fun[s], x[a] == c, 
    y[a] == d, θ[a] == e};
    sol = NDSolve[eqs, {x, y, θ}, {s, smin, smax}, optsnd];
    {x[t], y[t]} /. sol[[1]]]

Then executing:

points = {{0, 2}, {1, 3}, {1/2, 1}, {3/2, 4}, {2, 2}, {5/2, 2}, {3,0}};
k := Interpolation[points];
GraphicsGrid[
  {{Plot[k[x], {x, 0, 3}], 
    ParametricPlot[
      Evaluate[curveOfCurvatureK[k, 0, {0, 0, 0}, {0, 3}]][x], {x, 0, 3}]}}]

I get the plot of the curvature next to the corresponding curve obtained. I want to know how to make the same thing but interactive. That is, generate a curvature function on the left that can be moved, like:

DynamicModule[{points = {{0.`, 2}, {0.5`, 3}, {1.`, 1}, {1.5`, 4}, {2.`, 2}, {2.5`, 2}, {3.`, 2}}}, 
  LocatorPane[
     Dynamic[points], 
     Dynamic[
       Plot[Interpolation[points, x], {x, 0, 3}, PlotRange -> {0, 5}]]]]

and then obtain (dynamically) the corresponding 2D curve on the right.

How can I do that? I have already searched related problems and could not find anything to make it work.

$\endgroup$
4
$\begingroup$

one possibility:

DynamicModule[{points = {{0., 2}, {0.5, 3}, {1., 1}, {1.5, 4}, {2., 2}, {2.5, 2}, {3., 2}}, 
  intF = Interpolation[{{0., 2}, {0.5, 3}, {1., 1}, {1.5, 4}, {2., 2}, {2.5, 2}, {3., 2}}]},
 LocatorPane[Dynamic[points, (points = #; intF = Interpolation[#]) &],
   Dynamic @ Row[{ParametricPlot[Evaluate[{x, intF[x]}], {x, 0, Max[points[[All, 1]]]}, 
      PlotRange -> {{0, 8}, {-5, 5}}, Frame -> True, ImageSize -> 1 -> {40, 30}], 
     ParametricPlot[Evaluate[curveOfCurvatureK[intF, 0, {0, 0, 0}, {0, 3}][x]], {x, 0, 3}, 
      Frame -> True, PlotRange -> {{-5, 5}, {-5, 5}}/2, ImageSize -> 1 -> 60]}, Spacer[5]], 
  {{0, -5}, {8, 5}}]]

enter image description here

$\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.