how to animate 3d plot given a rotation axis in ma

2019-03-16 19:33发布

If given a rotation axis normalized, such as {1/Sqrt[3],1/Sqrt[3],1/Sqrt[3]}, and a 3d plot, for example,

z[x_, y_] := Exp[-(Sqrt[x^2 + y^2]/Power[4, (3)^-1]) + Power[4, (3)^-1]*Sqrt[1/2*(Sqrt[x^2 + y^2] + x)]];

Plot3D[2*z[x, y], {x, -5, 5}, {y, -5, 5}]

I want to create an animation for this plot about the axis {1/Sqrt[3],1/Sqrt[3],1/Sqrt[3]} (could be any other arbitary one), and then export it as an animated gif. Would anyone please help? Many thanks.

Edit

I also left out one degree of freedom in specifying the rotation. Could any one please help, if also given the coordinate of a point which the rotational axis must pass, how to do the visualization/animation? Thanks again.

2条回答
Explosion°爆炸
2楼-- · 2019-03-16 20:12

Could do as below.

axis = {1, 1, 1};

Animate[
  Plot3D[2*z[x, y], {x, -5, 5}, {y, -5, 5}] /. 
    gg : GraphicsComplex[___] :> Rotate[gg, theta, axis],
  {theta, 0., 2.*Pi}]

enter image description here

Daniel Lichtblau Wolfram Research

查看更多
Animai°情兽
3楼-- · 2019-03-16 20:26

Copying what Daniel did, just prepared for exporting.

axis = {1, 1, 1};
l = {-7, 7};

s = Table[

      Plot3D[2*z[x, y], {x, -5, 5}, {y, -5, 5}, PlotRange -> {l, l, l}] /. 

      gg : GraphicsComplex[___] :> Rotate[gg, theta, axis], {theta, 0., 2. Pi}];

Export["c:\\test.gif", s]

enter image description here

The following parameters are available for the gif export (as per the docs):

"AnimationRepetitions" how many times the animation is played before stopping
"Background"           background color shown in transparent image regions 
"BitDepth"             bits used to represent each color channel in the file
"ColorMap"             color reduction palette, given as a list of color values
"GlobalColorMap"       default color palette for individual animation frames
"DisplayDurations"     display durations of animation frames, given in seconds
"ImageCount"           number of frames in an animated GIF
"ImageSize"            overall image size
"RawData"              array of color map indices
"Comments"             user comments stored in the file

I used "DisplayDurations" in the past, and it worked.

查看更多
登录 后发表回答