Mathematica简单的三维随机游走及实现
三维随机游走
以下几个比较简单版本
Graphics3D[ FoldList[Normal@GeometricTransformation[#, TranslationTransform[#2]] &, Cuboid[], RandomChoice[Permutations[{1, 0, 0}], 50]], Boxed -> False]
lattice = Table[Take[Join[{0, 0}, IntegerDigits[i, 2]], -3], {i, 1, 8}] /. {0 -> -1};
data = Accumulate[Table[lattice[[RandomInteger[{1, 8}]]], {200}]];
Graphics3D[Tube[data]]
动画
posList = FoldList[Normal@GeometricTransformation[#, TranslationTransform[#2]] &, Cuboid[],RandomChoice[Permutations[{1, 0, 0}], 50]];plot := Graphics3D[#, PlotRange -> {100, 100, 100}] &
graphList = Table[Graphics3D[posList[[1;;i]], PlotRange -> 40, Boxed -> False], {i, 1, 51}];
ListAnimate@graphList
隐藏一些帧,剑拖尾效果
plot := Graphics3D[#, PlotRange -> {100, 100, 100}] &
takeData[data0_, i0_] := Block[{},len = Length@data0;
If[len > i0, data0[[-i0;;-1]], data0]]
graphList = Table[Graphics3D[takeData[posList[[1;;i]], 10], PlotRange -> {0, 20}, Boxed -> False], {i, 1, 51}];
ListAnimate@graphList
这篇是好早前的博文,新函数AngelPath3D等更方便。
<< "/Users/hypergroups/Documents/Wolfram \Mathematica/DeployProjects/MyMarkDown.m"
Notebook2Markdown[EvaluationNotebook[], "random_walk"]
喜欢的多多表示,点个赞加个星,后面有空分享更多有趣的小例子。