2
$\begingroup$

In previous versions of Mathematica the answer in this question has worked

How can I independently move vector components (in 2D)?

But it no longer works in version 11. Does anyone have a solution that works?

$\endgroup$

closed as unclear what you're asking by m_goldberg, MarcoB, Yves Klett, rhermans, eyorble Aug 31 '18 at 23:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Do you mean the Manipulate by István Zachar? It seems to work for me in V 11. Can you be more explicit about what the problem is? $\endgroup$ – bill s Aug 28 '18 at 21:32
  • $\begingroup$ On my machine the Manipulate version behaves quite differently: When moving a1, a2 stays the same, when it was supposed to follow the end point of the dashed arrow. $\endgroup$ – Sofic Aug 29 '18 at 12:08
  • $\begingroup$ Hi Sofic and welcome to Mma.SE. Start by taking the tour now and learning about asking and what's on-topic. Always edit if improvable, show due diligence, give brief context, include minimal working example of code and data in formatted form. By doing all this you help us to help you and likely you will inspire great answers. The site depends on participation, as you receive give back: vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$ – rhermans Aug 31 '18 at 8:16
  • $\begingroup$ To clarify and provide new information please edit the question itself, and leave the comments section only for comments. As it stand now, your question may be put on-hold because it's not clear what you need. To avoid or revert the Hold you can edit your question to improve it and make it specific, well-structured and easy to understand.You should share your code, to allow us to see the problem you describe. Please don't be discouraged by that cleaning-up policy. Learn about good questions here $\endgroup$ – rhermans Aug 31 '18 at 8:19
1
$\begingroup$

This isn't a locator, but you can move components independently. Will this work for your application?

Manipulate[
  Graphics[
           Arrow[{{0, 0}, {x, y}}],
  PlotRange -> {{-3, 3}, {-3, 3}}], 
  {x, -2, 2}, {y, -2, 2}]
$\endgroup$
  • $\begingroup$ Thank you, but no. I need to be able to move the endpoints using locators, so that the user can manipulate them directly. $\endgroup$ – Sofic Aug 29 '18 at 12:10
1
$\begingroup$

Here is a method that uses the 2nd argument of Dynamic. Basically, if you move the first point, it will displace the 2nd one by the same amount as the first one:

DynamicModule[{pt = {{-1, 1}, {2, 1}}},
 LocatorPane[
  Dynamic[
   pt,
   Function[
    pt[[2]] = #[[2]] + (#[[1]] - pt[[1]]);
    pt[[1]] = #[[1]]
    ]
   ],
  Graphics[
   {
    Red,
    Dynamic[Arrow[{{0, 0}, pt[[1]]}]],
    Blue,
    Dynamic[Arrow[pt]]
    },
   PlotRange -> {{-2, 2}, {-2, 2}},
   Axes -> True
   ]
  ]
 ]

It has the drawback that the tip of the 2nd arrow can leave the plotting area. If you want to prevent that, you could use the following as the 2nd argument to Dynamic to clip to point inside of the plot range:

Function[
 pt[[2]] = Clip[#[[2]] + (#[[1]] - pt[[1]]), {-2, 2}];
 pt[[1]] = #[[1]]
 ]

It seems like the alignment of the 2nd vector can get thrown off a bit if you go a bit too crazy with dragging the first arrow around. I suspect that this is some form or rounding error. Setting the option ContinuousAction -> False to the LocatorPane will solve that problem, but it makes the arrows less dynamic.

edit

I found a better way to make sure the second arrow retains its length and direction, even when you drag the first one around a lot. It seems like this works better by just putting the locators into the graphics directly:

DynamicModule[{pt = {{-1, 1}, {1, 1}}},
 Deploy @ Graphics[{
    Locator[Dynamic[pt[[2]]]],
    Locator[
     Dynamic[
      pt[[1]],
      Function[
       pt[[2]] += # - pt[[1]];
       pt[[1]] = #
       ]
      ]
     ],
    Red, Dynamic[Arrow[{{0, 0}, pt[[1]]}]], 
    Blue, Dynamic[Arrow[pt]]
    },
   PlotRange -> {{-2, 2}, {-2, 2}}, Axes -> True
   ]
 ]
$\endgroup$

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