虽然matlab远多于mathematica。工程系本科会有matlab课,但没注意到有mathematica的课。研究生基本都会matlab,但会mathematica的很少。这这并不代表mathematica不好用,接下来给大家分享一下如何利用 Mathematica 来模拟乒乓球滚动。因为Mathematica相关的练手项目实在太少,所以笔者故作此分享。
先定义变量
R=1;v0=4;w0=10;mu=0.2;g=9.8;\[Delta]=(2(v0+w0R))/(5mug);
然后定义
location[t_] :=
Piecewise[{{If[t <= \[Delta],
v0 t - 1/2*mu*g*t^2 + R, (3 v0 - 2 w0 R)/5 (t - \[Delta]) +
v0 \[Delta] - 1/2*mu*g*\[Delta]^2 + R], 3 v0 - 2 w0 R < 0},(*<
0 roll back*){If[t <= \[Delta], v0 t - 1/2*mu*g*t^2 + R,
v0 \[Delta] - 1/2*mu*g*\[Delta]^2 + R],
3 v0 - 2 w0 R == 0}, {If[t <= \[Delta],
v0 t - 1/2*mu*g*t^2 + R, (3 v0 - 2 w0 R)/5 (t - \[Delta]) +
v0 \[Delta] - 1/2*mu*g*\[Delta]^2 + R], 3 v0 - 2 w0 R > 0}}]
定义旋转角
zhuanjiao[t_] :=
If[t <= \[Delta], w0 t - (3 mu g)/(4 R) t^2,
w0 \[Delta] - (3 mu g)/(4 R) \[Delta]^2 - (3 v0 -
2 w0 R)/(5 R) (t - \[Delta])]
绘出图形
Manipulate[
Graphics3D[
Rotate[Translate[{Sphere[], Point[SpherePoints[100]]}, {location[t],
R, R}], -zhuanjiao[t], {0, 1,
0},(*changed to get rolling to look right*){location[t], R, R}],
Axes -> True, AxesOrigin -> {0, 0, 0},
PlotRange -> {{0, 10}, {0, 2 R}, {0, 2 R}},
AxesLabel -> {x, y, z}], {t, 0, 5, .01}]
效果如下图
仅为练手作品。