1
$\begingroup$

I need help to control order of evaluations. Here I try to use Manipulate to control n unit vectors. Their positions are initially random but head left. The 2 operations are 1) translation: moving head of each one and then the corresponding tail follows 2) rotation: moving tail of each one and then it's normalised to unit size. (Originally I prefer the subject "helping these lovely, unit sperms".)

Although I've heard a bit about Hold/Release/Evaluation, I don't know how to control the order of evaluation to make it right. Thanks a lot.

n = 5;
Do[p0[i] = {Random[], Random[]};
  q0[i] = p0[i] + {1, 0}, {i, n}];
Manipulate @@ Join[
  {Do[If[p[i] != p0[i], q[i] = p[i] + q0[i] - p0[i]; p0[i] = p[i]; 
     q0[i] = q[i]; Break[],
     If[q[i] != q0[i], q[i] = p[i] + Normalize[q[i] - p[i]]; 
      q0[i] = q[i]; Break[]]], {i, n}];
   Graphics[Table[{Line[{p[i], q[i]}], Circle[p[i], .1]}, {i, n}], 
    PlotRange -> {{-1, 2}, {-1, 2}}]},
  Table[{{p[i], p0[i]}, Locator}, {i, n}], 
  Table[{{q[i], q0[i]}, Locator}, {i, n}]]
$\endgroup$

closed as unclear what you're asking by MarcoB, user9660, Mr.Wizard Feb 28 '16 at 11:08

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.

  • $\begingroup$ This one is a bit different as I have a routine to draw each unit vector. Sorry that the code is packed. n = 5; Do[p0[i] = {Random[], Random[]}; q0[i] = p0[i] + {1, 0}, {i, n}]; sperm[h_, t_] = {Line[{h, t}], Circle[h, .1]}; Manipulate @@ Join[ {... Graphics[Table[sperm[p[i], q[i]], {i, n}], PlotRange -> {{-1, 2}, {-1, 2}}]}, Table[{{p[i], p0[i]}, Locator}, {i, n}], Table[{{q[i], q0[i]}, Locator}, {i, n}]] $\endgroup$ – wacharin wichiramala Jun 14 '15 at 3:13
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Jun 14 '15 at 4:32
  • $\begingroup$ Why do you think this is a problem with the order of evaluation? $\endgroup$ – C. E. Jun 16 '15 at 0:47
  • $\begingroup$ As I tried, it seems the Join evaluate Do[If[...]...] and then translation and rotation fail. Sometimes Graphics fails as the parameters are not yet assigned any values. I have tried Hold/ReleaseHold/Evaluate randomly without sufficient understanding. So failed :( $\endgroup$ – wacharin wichiramala Jun 16 '15 at 5:06
  • $\begingroup$ A friend told me that using p[i] causes strange effect. He finally found a solution using a unified list pq and {{pq,Join[p0,q0]},Locator}. Here Locator acts like the plural "Locators" and I failed to separate p and q (to {{p,p0},Locator},{{q,q0},Locator}). $\endgroup$ – wacharin wichiramala Jun 24 '15 at 14:53