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.

I'm trying to create a dynamic environment where I specify, using two locators, the initial condition (position (x,y) and velocity angle (alpha)) of a 2D particle.

To simplify, I'm assuming the initial position is restricted to a circle, and the velocity angle is always in respect to an angle in relation to the normal vector, perpendicular to the tangent vector.

This means that in the end, I would like to have 3 parameters: x,y initial position of the positional locator, and an initial angle, defined as the angle between the vector (positional locator - angle locator) and the normal vector.

The main problem resides on the coupling between the positional locator, and the angle locator: when I move the positional locator, I would like to have the angle locator moved in such a way that the initial angle is preserved.

To manipulate those, I'm using two Locators: one for position (initialPoint), one for initial angle (pt2)

DynamicModule[{initialPoint = {0, 0}, pt2 = {0, 0}},
 Style[Graphics[{
    Dashed,
    Circle[{0, 0}, 1],
    Locator[
     Dynamic[pt2, (pt2 = 
         initialPoint + 0.5 Normalize[# - initialPoint]) &]], 
    Locator[Dynamic[initialPoint, (initialPoint = Normalize[#]) &]]}, 
   PlotRange -> {{-3.3, 3.3}, {-3.3, 3.3}}, AspectRatio -> 1], 
  Selectable -> False]]

however, when I dynamically pick the initialPoint, the second locator does not follow it. What can I do it in order to keep pt2 always such that the initial angle is preserved?

share|improve this question
    
I'm not sure this is exactly what you want, but try: DynamicModule[{initialPoint = {0, 0}, pt2 = {0, 0}}, Style[Graphics[{Dashed, Circle[{0, 0}, 1], Locator[Dynamic[ initialPoint + 0.5 Normalize[pt2 - initialPoint], (pt2 = initialPoint + 0.5 Normalize[# - initialPoint]) &]], Locator[Dynamic[initialPoint, (initialPoint = Normalize[#]) &]]}, PlotRange -> {{-3.3, 3.3}, {-3.3, 3.3}}, AspectRatio -> 1], Selectable -> False]]. Does that look right? –  Jonathan Shock Jun 12 '13 at 16:25
    
Since several people who try to answer said the problem was not well posed (which I agree), I edited it. Sorry for the previous formulation –  J. C. Leitão Jun 13 '13 at 10:24
    
    
J.C.Leitao, are you satisfied with the answers? If not, maybe you can explain some more? –  Jacob Akkerboom Aug 15 '13 at 21:35

2 Answers 2

If by "normal" you mean normal to the circle, then you were almost there. You need to update the angle point when initialPoint is changed.

DynamicModule[{initialPoint = {1, 0}, anglePoint = {0.5, 0}}, 
 Style[Graphics[{Dashed, Circle[{0, 0}, 1], 
    Locator[Dynamic[
      anglePoint, (anglePoint = 
         initialPoint + 0.5 Normalize[# - initialPoint]) &]], 
    Locator[Dynamic[initialPoint, 
      Module[{angle = ArcTan @@ (anglePoint - initialPoint) - ArcTan @@ initialPoint},
        initialPoint = Normalize[#];
        angle += ArcTan @@ initialPoint;
        anglePoint = initialPoint + 0.5 {Cos[angle], Sin[angle]}] &]]}, 
   PlotRange -> {{-3.3, 3.3}, {-3.3, 3.3}}, AspectRatio -> 1], 
  Selectable -> False]]
share|improve this answer

I"m not sure exactly what motion you are looking for, but here is a way to make the second locator follow the first around. As in your code, I locked the first locator to the unit circle and the second locator to a smaller orbit about the first.

pt1Old = {0, 0}; pt2Old = {0, 0};
Manipulate[If[pt1Old != pt1, pt1Old = pt1; pt1 = Normalize[pt1];
              pt2 = pt1 + Normalize[pt2 - pt1]/2; pt2Old = pt2;];
           If[pt2Old != pt2, pt2 = pt1 + Normalize[pt2 - pt1]/2; pt2Old = pt2;];
           Graphics[{Dashed, Circle[{0, 0}, 1]}, 
              PlotRange -> {{-2.3, 2.3}, {-2.3, 2.3}}], 
           {{pt1, {1, 0}}, Locator}, {{pt2, {0, 1}}, Locator}]

enter image description here

The way this works is to maintain a set of "old" locations for the locators and to only update the positions when they are dragged around. That's what the two Ifs are for. Note that the second locator can be changed independent of the first, but that whenever the first is moved, the second follows. Accordingly, when you want to change the motion of the second (to whatever angle you wish) you will need to update it in both places.

share|improve this answer

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.