2

I am trying to use Animate in conjunction with Graphics3D to make a list of vectors that have oscillating lengths. Basically, a list of random 3D vectors are plotted originating from the origin. Then the length of the vector is controlled with a cosine function with a random phase.

For example,

randomVec[r_] := r*Normalize@RandomVariate[NormalDistribution[], 3]
vecs = Table[randomVec[i], {i, 10^2}];
hues = Table[RandomReal[], {i, 10^2}];
rans = Table[RandomReal[], {i, 10^2}];

Animate[
    Graphics3D[
        Table[{Hue[hues[[i]]], 
              Arrow[Tube[{{0, 0, 0}, 
              vecs[[i]] + Cos[\[Eta] + rans[[i]]*Pi]*vecs[[i]]}, 
              Scaled[0.007]]]}, {i, 10^2}],
     Boxed -> False, AxesOrigin -> {0, 0, 0}, 
     ViewPoint -> {Pi, Pi, Pi}],
{\[Eta], 0, 2*Pi}]

However, when I run this code, the origin of the animation seems to bounce around within the viewing frame. How can I force Graphics3D to use the exact same viewing box for every time that it is called within Animate?

Also this code is probably inefficient so any tips about how to make it animate more smoothly would be appreciated!

compmatsci
  • 153
  • 3

1 Answers1

2

I think the first thing to try in your case is to add a

 PlotRange->{{xmin, xmax},{ymin, ymax},{zmin, zmax}}

option.

It will control the size of the cube independently of the computed data.

You may also want to look at options BoxRatios and SphericalRegion for nice scaling of the result.

ogerard
  • 735
  • 9
  • 15
  • 1
    Great, together ,`PlotRange` and `SphericalRegion` make it look great. Now I just want to try to smooth out the animation... – compmatsci Mar 20 '15 at 21:43
  • 1
    Animate is great to quickly build an interactive animation. The trouble is that it reduces the computation resolution for speed among other things. If you want to produce a final, smooth animation, you might need to precalculate it, and there are several ways. It is worth another question, and I suggest you ask it at mathematica.stackexchange where many experts are available. – ogerard Mar 22 '15 at 14:46