Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Here's what may well be a simple problem that I have been having difficulty with:

There are two connected vectors, v1 and v2, such that:

  • v1 begins at the origin and and ends at point a1
  • v2 begins at point a1 and ends at point a2

The default constraints are such that moving point a1 (via the locator at the arrowhead):

  • Affects the length and direction of both v1 and v2,
  • Does not affect the position of a2. In other words, the resultant, v1+v2 remains unchanged.

Under other circumstances, this would be fine. However I want to implement the composition of vectors such that displacing a1 will affect neither the length nor direction or v2. To do so, moving a1 must move a2 so that a1-a2 remains invariant.

I want to maintain the effect of "my" moving of a2 (It has no effect on v1 and should not have any effect on v1). In other words, changing v1 should not change v2, and vice-versa. That's what I mean by "independent" components.

The figure on the left is a "before" scenario. Notice that a1 is located at {3,-1}; a2 is located at {4,1}.

The figure on the right shows the situation after a1 is displaced to {6,-1}. Notice that v2 has stretched and rotated slightly in a clockwise direction.

I would prefer that the v2 would have been displayed like the dashed black arrow is displayed. That would correspond to the idea that we changed v1 without changing v2.

Any ideas about how this can be done?

vectors

Here is the code:

Manipulate[
 Graphics[{PointSize[Large], Point[{0, 0}],
 {Red, Arrow[{{0, 0}, a1}]}, Text["a1", Offset[{0, 15}, a1]],
 {Dashed, Arrow[{a1, a1 + {5, -2}}](*,Text["a3",Offset[{0,-15},a2]]*)},
 Blue, Arrow[{a1, a2}], Black, Text["a2", Offset[{0, 15}, a2]]}, 
PlotRange -> {{-8, 8}, {-8, 8}},
BaseStyle -> 16, Axes -> {True, True}],
{{a1, {-1, 3}}, {-4, -4}, {8, 8}, Locator},
{{a2, {4, 1}}, {-3, -3}, {6, 6}, Locator}]
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Does it do what you are looking for? I calculate the displacement of a1 as d inside the first Locator's Dynamic, and add this d to a2 whenever a1 is moved.

DynamicModule[{a1, a2, d, inita1 = {-1, 3}, inita2 = {4, 1}},
 {a1, a2} = {inita1, inita2};
 Panel@Graphics[{
    PointSize[Large], Point[{0, 0}],
    {Red, Dynamic@Arrow[{{0, 0}, a1}]},
    Dynamic@Text["a1", Offset[{0, 15}, a1]],
    {Dashed, Dynamic@Arrow[{a1, a1 + {5, -2}}](*,Text["a3",
     Offset[{0,-15},a2]]*)},
    {Blue, Dynamic@Arrow[{a1, a2}]},
    {Black, Dynamic@Text["a2", Offset[{0, 15}, a2]]},
    Locator[Dynamic[a1, (d = # - a1; a1 = #; a2 = a2 + d) &]],
    Locator[Dynamic[a2]]
    }, PlotRange -> {{-8, 8}, {-8, 8}}, BaseStyle -> 16, 
   Axes -> {True, True}]
 ]

The same in Manipulate (I'm not sure that this is the way to do it, perhaps someone cares to correct me):

Manipulate[
 d = a1 - olda1;
 a2 = a2 + d;
 olda1 = a1;
 Graphics[{
   PointSize[Large], Point[{0, 0}],
   {Red, Arrow[{{0, 0}, a1}]}, Text["a1", Offset[{0, 15}, a1]],
   {Dashed, Arrow[{a1, a1 + {5, -2}}](*,Text["a3",Offset[{0,-15},a2]]*)},
   Blue, Arrow[{a1, a2}],
   Black, Text["a2", Offset[{0, 15}, a2]]
   },
  PlotRange -> {{-8, 8}, {-8, 8}}, BaseStyle -> 16, 
  Axes -> {True, True}],
 {{a1, {-1, 3}}, {-4, -4}, {8, 8}, Locator},
 {{a2, {4, 1}}, {-3, -3}, {6, 6}, Locator},
 {d, None},
 {{olda1, a1}, None}
 ]

The important point is to make the assignment to d before the assignment to olda1.

share|improve this answer
    
At first glance, it's looking very good! I'll play around with the code and see if I can easily port it to Manipulate. –  David Carraher Oct 26 '12 at 16:56
    
@David Yes, sorry about that, I'm pretty bad with Manipulate. –  István Zachar Oct 26 '12 at 17:04
    
I'm still struggling to implement your ideas in Manipulate. I can't figure out the counterpart of Locator[Dynamic[a1, (d = # - a1; a1 = #; a2 = a2 + d) &]] for use in Manipulate. –  David Carraher Oct 26 '12 at 17:16
    
@David I've tried my best, see edit! –  István Zachar Oct 26 '12 at 17:37
    
It works really well. Just what I needed. Thanks. –  David Carraher Oct 26 '12 at 22:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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