I am putting together a Manipulate on vector addition for my intro physics class and everything works well except when I include a Graphics that has a Table within. The code is below. There are three controls for each vector; two sliders x1, and y1 for the vector components and a Locator p1 at the head of the vector. In the code you'll see second arguments of Dynamics that link the Locator coordinates p1 and the vector components x1 and y1. There is a second vector that starts at the head of the first and has similar controls associated with it. There are several Graphics that I've left out that don't matter. What I left in here are curved arrows to show the standard angle for each vector. The Arrows are created using Table as you can see.
If you Show just the two vectors, as I have in the code below, everything works perfectly. As you move the Locator or the Sliders for one vector the other vector does not change magnitude or direction.
If I include the angle arrow for vector 1, angleArrow1, in the Show command it still works perfectly. However, if I include the angle arrow for vector 2, angleArrow2, in Show the Locator at the head of vector 2 acts as if it is the Locator for vector 1. In other words, when I move the Locator at the head of vector 2 only vector 1 changes. However, moving the sliders for vector 2 works as do the sliders and Locator for vector 1.
What is weird is that if I use the commented out version of angleArrow2 that doesn't use Table, but uses an explicit list, it works! I need Table to generate the list because I need an arc that grows as the angle grows and remains fairly smooth looking.
So what is it about Table (and only in the angleArrow for vector 2) that is causing it to in effect link the two Locators? I've tried putting the angleArrow creation function into an Initialization at the end of the Manipulate and calling it when needed, but it still doesn't work. I've tried wrapping Evaluate around Table, or around Arrow, but still no help. I'll keep tinkering, but this has really got me stumped.
Thanks!
Manipulate[(*The second argument of the Dymanics below allows us to \
link the Locator with variable p (={x,y}) to the two sliders with \
variables x and y.*)
theta1 =
Which[y1 >= 0, ArcCos[x1/Sqrt[p1.p1]], y1 < 0,
2 Pi - ArcCos[x1/Sqrt[p1.p1]]];
vector1 =
Graphics[{Green, Arrow[{{0, 0}, p1}],
Locator[Dynamic[
p1, (p1 = #; {x1 = p1[[1]], y1 = p1[[2]],
p2[[1]] = p1[[1]] + x2, p2[[2]] = p1[[2]] + y2}; #) &]]}];
angleArrow1 =
Graphics[Arrow[
Table[Min[0.5 Sqrt[p1.p1], 0.5] {Cos[j], Sin[j]}, {j, 0, theta1,
1/100}]]];
(*Stuff for vector 2*)
theta2 = Which[y2 >= 0, ArcCos[x2/Sqrt[x2^2 + y2^2]], y2 < 0,
2 Pi - ArcCos[x2/Sqrt[x2^2 + y2^2]]];
vector2 =
Graphics[{Green, Arrow[{p1, p2}],
Locator[Dynamic[
p2, (p2 = #; {x2 = p2[[1]] - p1[[1]],
y2 = p2[[2]] - p1[[2]]}; #) &]]}];
(*angleArrow2=Graphics[Arrow[{{x1+Min[0.5 Sqrt[x2^2+y2^2],0.5]
Cos[0],y1 +Min[0.5 Sqrt[x2^2+y2^2],0.5] Sin[0]},{x1+Min[0.5
Sqrt[x2^2+y2^2],0.5] Cos[theta2/2],y1 +Min[0.5 Sqrt[x2^2+y2^2],0.5]
Sin[theta2/2]},{x1+Min[0.5 Sqrt[x2^2+y2^2],0.5] Cos[theta2],y1
+Min[0.5 Sqrt[x2^2+y2^2],0.5] Sin[theta2]}}]];*)
angleArrow2 =
Graphics[Arrow[
Table[{x1 + Min[0.5 Sqrt[x2^2 + y2^2], 0.5] Cos[j],
y1 + Min[0.5 Sqrt[x2^2 + y2^2], 0.5] Sin[j]}, {j, 0, theta2,
1/100}]]];
(*Combine All The Graphics*)
Show[{vector1, vector2},
PlotRange -> {{-4.1, 4.1}, {-4.1, 4.1}}, ImageSize -> 500],
(*Controls*)
Row[{"Ax",
Manipulator[
Dynamic[x1, (x1 = #; {p1[[1]] = x1, p2[[1]] = x1 + x2}; #) &], {-4, 4}],
Spacer[4],
Dynamic[Style[Round[x1, 0.001], 14]]}],
Row[{"Ay",
Manipulator[
Dynamic[y1, (y1 = #; {p1[[2]] = y1, p2[[2]] = y1 + y2}; #) &], {-4, 4}],
Spacer[4],
Dynamic[Style[Round[y1, 0.001], 14]]}],
Row[{"Bx",
Manipulator[
Dynamic[x2, (x2 = #; p2[[1]] = x1 + x2; #) &], {-4, 4}],
Spacer[4], Dynamic[Style[Round[x2, 0.001], 14]]}],
Row[{"By",
Manipulator[
Dynamic[y2, (y2 = #; p2[[2]] = y1 + y2; #) &], {-4, 4}],
Spacer[4],
Dynamic[Style[Round[y2, 0.001], 14]]}],
{{p1, {1.5, 1.5}},None},
{{p2, {1.5 + Cos[Pi/6], 1.5 + Sin[Pi/6]}}, None},
{{x1, 1.5},None},
{{y1, 1.5}, None},
{{x2, Cos[Pi/6]},None},
{{y2, Sin[Pi/6]}, None},
{{theta1, Pi/4}, None},
{{theta2, Pi/6}, None}, TrackedSymbols -> {x1, y1, p1, x2, y2, p2}]
angleArrow2
methods after I have added the missing}
toangleArrow1
. $\endgroup$