# Animating a 3-D arrow given the vector's x, y, and z components as a function of time

I am trying to show how a vector M varies over time. I have the following code:

Mx={4.74124,13.1038,33.0248,19.7323,24.5952,30.1253,27.9521,29.4089,28.0574,29.277};
My={-18.2975,-7.42215,-4.23518,-9.88457,-8.96098,-8.22531,-9.6019,-9.18352,-9.06551,-9.29939};
Mz={-0.12887,-7.57926,-1.4561,-1.59703,-4.53247,-2.09772,-2.91711,-3.56798,-2.6221,-3.48453};

Animate[

Graphics3D[{
Blue,Arrow[Tube[{{0,0,0},{Mx[[i]],My[[i]],Mz[[i]]}}]]
},Axes->True,AxesLabel->{"x","y","z"},Axes],

{i,1,Length[Mx],1}]


(In actuality, my lists Mx, My, and Mz are much longer, but the shorter lists above reproduce the error behavior.)

I get the following error:

An improperly formatted option was encountered while reading a Graphics3DBox. The option was not in the form of a rule.

Do you know how I can fix this? I do not understand which option "was not in the form of a rule."

-

You have a stray argument in the Graphics3D function (Axes).
Also, you probably want a fixed PlotRange. Try:

Animate[
Graphics3D[{Blue,
Arrow[Tube[{{0, 0, 0}, {Mx[[i]], My[[i]], Mz[[i]]}}]]},
Axes -> True, AxesLabel -> {"x", "y", "z"},
PlotRange -> ({Min@# - 5, Max@# + 5} & /@ {Mx, My, Mz})],
{i, 1, Length[Mx], 1}
]


In the future try to debug your own code. You would have seen the same problem without the Animate function if you tried that. Also, the error code suggests that something is wrong with the graphics options, which should have directed your attention to the arguments of Graphics3D.

-
Thanks. I have voted to close my question as being too localized. (I missed my silly mistake.) –  Andrew May 26 '12 at 22:41
Or maybe I should delete the question? What do you think? –  Andrew May 26 '12 at 22:52
@Andrew I'd rather have the points but I'm OK with it. :-) –  Mr.Wizard May 26 '12 at 23:33
I think the fixed plot range is a reasonable question. The stray Axes that was causing the error can just be edited out of the question. –  Brett Champion May 27 '12 at 1:55
@Andrew see Brett's comment above. –  Mr.Wizard May 27 '12 at 2:05

You may also play some tricks:

h = Transpose[Table[{Cos@t, Sin@t, t^.1}, {t, 0, 8 Pi, .1}]];
d = Interpolation[#, InterpolationOrder -> 1] & /@ h;

Manipulate[
Show[
Graphics3D[{Blue, Arrow[Tube[{{0, 0, 0}, Through@d@t}]]}, Axes -> True,
AxesLabel -> {x,y,z}, PlotRange -> ({1.1 Min@#, 1.1 Max@#} & /@ h)],

ParametricPlot3D[Through@d@v, {v, 1, t}, ColorFunction -> Function[{x, y, z, u}, Hue[z]]]],
{t, 1.001, Length@First@h}
]


Edit

Fancier, by using InterpolatingFunctio[] properties:

<< DifferentialEquationsInterpolatingFunctionAnatomy

pltIntFun[d:{_InterpolatingFunction ..}]:=Module[{pRange,manipDomain,k = (Max@# - Min@#) 10^-4 &},

pRange      = { Min@# - k@#, Max@# + k@#} & /@ Through@d@"ValuesOnGrid";
manipDomain = Join[{t}, ({ Min@# + k@#, Max@#} & /@ Through@d@"Domain")[[1]]];

Manipulate[Show[
Graphics3D[
{Blue, Arrow[Tube[{{0, 0, 0}, Through@d@t}]]},
Axes -> True, AxesLabel -> {x, y, z}, PlotRange -> pRange],

ParametricPlot3D[Through@d@v, {v, 1, t}, ColorFunction -> Function[{x, y, z, u}, Hue[z]]]],
Evaluate@manipDomain]];

d = Interpolation[#,InterpolationOrder->1] &/@ Transpose[Table[{Cos@t,Sin@t,t^.1}, {t,0,8 Pi,.1}]];
pltIntFun[d]

-