wolfram-mathematicabounding-boxgraphics3d

Maintain consistent plot region for Graphics3D in mathematica


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!


Solution

  • 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.