Skip to content

Instantly share code, notes, and snippets.

@nufeng1999
Last active September 5, 2021 14:09
Show Gist options
  • Save nufeng1999/1d24c317a55e869a59dab010dcb4b7f6 to your computer and use it in GitHub Desktop.
Save nufeng1999/1d24c317a55e869a59dab010dcb4b7f6 to your computer and use it in GitHub Desktop.
[Creating Movies and Animations in Mathematica] #Mathematica

Step 1: Generate Data

x[t_] = 5 Cos[t];
y[t_] = 2 Sin[t];
z[t_] = t;
ParametricPlot3D[{x[t], y[t], z[t]}, {t, 0, 2 \[Pi]}]
tRange = Range[0, 2 \[Pi], (2 \[Pi])/99];   (*创建100个时间步,保存为列表*)
movieVector = ConstantArray[0, Length[tRange]]; 

Step 2: Draw/Render the Scenario

Step 3: Take a Snapshot

Step 4: Advance Time Forward

For[k = 1, k <= Length[tRange], k++,
 (*提取单个点的数据*)
 tk = tRange[[k]];
 xk = x[tk];
 yk = y[tk];
 zk = z[tk];
 
 (*Render the scenario*)
 movieVector[[k]] = Show[
   (*仅将点绘制为绿点*)
   Graphics3D[
    {
     AbsolutePointSize[15], Green, Point[{xk, yk, zk}]
     }
    ],
   
   (*绘制整个轨迹/曲线*)
   ParametricPlot3D[{x[t], y[t], z[t]}, {t, 0, 2 \[Pi]}],
   
   (*布置场地*)
   AxesLabel -> {"x", "y", "z"},
   PlotLabel -> StringJoin["t = ", ToString[N[tk]]]
   ]
 ]

Step 5: Save Movie

fileName = "curveMathematica.avi";
Export[fileName, movieVector];
Video[fileName]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment