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

妖精的绣舞 提交于 2019-12-03 13:50:42

问题


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.


回答1:


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}]

Daniel Lichtblau Wolfram Research




回答2:


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]

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.



来源:https://stackoverflow.com/questions/5148491/how-to-animate-3d-plot-given-a-rotation-axis-in-mathematics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!