I have a catenary curve in Mathematica, and I wanted to add a variator (dimmer) with Manipulate, so that the user can modify the value of the x/y-coordinate of the hanging-points A, B and the point C on the curve. With my current code, I can just modify these values with the locator, but I can't see the current value and cannot set one directly.

Is there a solution, so that I delete the rest of the curve, the part above the hanging-points A and B?

Here is my code till now:

catenary[x_] := a*Cosh[(x - c)/a] + y

m = Manipulate[Module[{root}, 
    (root = FindRoot[catenary[#[[1]]] == #[[2]] & /@ pt, {{y, 0}, {c, 0}, {a, 1}}]; 
        Plot[catenary[x] /. root, {x, -2, 2}, PlotRange -> {-3, 3}, AspectRatio -> 3/2], 
        Graphics[{Red, Point[pt]}]])
    {{pt, {{-1, 1}, {1, 1}, {0, 0}}}, Locator}
  • $\begingroup$ You've seen this and this? $\endgroup$ – J. M.'s ennui Jun 17 '12 at 14:47
  • 4
    $\begingroup$ Welcome to Mathematica.SE! I noted that you directly accepted the first answer, which was given only minutes after your question was posted. It is usually better to wait a bit (a day or so is not uncommon) in order to entice more people to provide an answer. $\endgroup$ – Sjoerd C. de Vries Jun 17 '12 at 15:08
  • $\begingroup$ I completely agree with @SjoerdC.deVries (+1 ;-) ), you should wait some time, no need to rush. $\endgroup$ – Vitaliy Kaurov Jun 17 '12 at 15:30
  • $\begingroup$ Do you need input field to type the coordinate or just the slider to drag around? I just do not see the big difference between dragging a slider vs dragging locator. $\endgroup$ – Vitaliy Kaurov Jun 17 '12 at 15:37
  • $\begingroup$ Please see the update. $\endgroup$ – Vitaliy Kaurov Jun 17 '12 at 19:34

I added:

  • Cut off extra curve
  • Labels A, B, C
  • Show coordinates
  • Enter coordinates manually (via yellow input field)

I think putting extra 2D "sliders" as you asked in comments will abuse interface and will be redundant, because your locators are basically a sort of 2D slider. So I interpreted your request as really asking for input fields.

Note you can easily remove showing coordinates next to A, B, C if it is too much.

catenary[x_] := a*Cosh[(x - c)/a] + y

m = Manipulate[
  Module[{root}, (root = 
      catenary[#[[1]]] == #[[2]] & /@ pt, {{y, 0}, {c, 0}, {a, 1}}];
    Show[Plot[catenary[x] /. root, {x, pt[[1, 1]], pt[[2, 1]]}, 
      AspectRatio -> 3/2],
     Graphics[{{Red, Point[pt]},
       Text[Style["A " <> ToString[pt[[1]]], "Subsection"], .2 + pt[[1]]],
       Text[Style["B " <> ToString[pt[[2]]], "Subsection"], .2 + pt[[2]]],
       Text[Style["C " <> ToString[pt[[3]]], "Subsection"], .2 + pt[[3]]]}], 
       PlotRange -> {{-3, 3}, {-3, 3}}, 
     AspectRatio -> 1, 
     ImageSize -> 350])], {{pt, {{-1, 1}, {1, 1}, {0, 0}}}, 
   Locator}, {{pt, {{-1, 1}, {1, 1}, {0, 0}}, ""}, InputField, 
   Background -> Lighter[Yellow], FrameMargins -> 3, 
   BaseStyle -> {"ControlStyle", 14}, ImageSize -> 360}]

enter image description here

  • $\begingroup$ I think so, and also with a text box for A,B,C where they can both see the current value and enter a value (if I read the question right) $\endgroup$ – rm -rf Jun 17 '12 at 14:54
  • $\begingroup$ Yes perfect! You answered my 2nd question.. Do you have an idea for the first one? Because in this solution, it still like the other one, to modify the position of the point, you have to modify it just with the locator.. It is perfect with the locator, but is there a way, so that i can modify the position of the 3 points, with a dimmer (variator) too? I dont know how we call it, exactly but the typical thing that creates "Manipulate".. It appears normally above the curve, and you can variate the value of some variable in the function.. in our case it will be the x/y-coordinates of the 3 points $\endgroup$ – Zellel B Jun 17 '12 at 14:56
  • $\begingroup$ exactly R.M :-) $\endgroup$ – Zellel B Jun 17 '12 at 15:02
  • $\begingroup$ @ZellelB Could you answer the question I added ant the end of my answer? ;-) $\endgroup$ – Vitaliy Kaurov Jun 17 '12 at 15:18
  • $\begingroup$ lol didnt seen it at the beginning.. sorry. Yeah a 2D-Slider! But i thought that slider is created with manipulate, and you can put (if you dont want to use the mouse) the value that you want to have, and the slider goes directly there.. thanks! $\endgroup$ – Zellel B Jun 17 '12 at 15:26

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.