用Mathematica绘制四维空间的物体
我们无法想像
四维空间是什么样子,就像
二维生物不知道三维一样!可是,听说有人用Mathematica画出了
四维立方体,所以我拿来学了一下,这里介绍一下这些代码。
操作方法
- 01
打开Mathematica,新建笔记本,输入如下代码: Animate[Graphics3D[ GraphicsComplex[ proj[t], {Blue, Specularity[0.75, 10], Sphere[Range[16], 0.05], Tube[e, 0.03], Opacity[0.3], Polygon@f}], Boxed -> False, Background -> Orange, ImageSize -> 390, PlotRange -> 1], {t, 0.0, Pi/2.0, 0.075}] 运行以后,就会得到一个“四维立方体”,呵呵,其实就是动态图。
- 02
导出动态图的代码如下: Export["C:\\Users\\Administrator\\Desktop\\超立方体0.gif", Table[Graphics3D[ GraphicsComplex[ proj[t], {Blue, Specularity[0.75, 10], Sphere[Range[16], 0.05], Tube[e, 0.03], Opacity[0.3], Polygon@f}], Boxed -> False, Background -> White, ImageSize -> {500, 500}, PlotRange -> 1], {t, 0.0, Pi/2.0, 0.075}]]
- 03
再来一个互动效果: Manipulate[ Graphics3D[{Darker@Red, CapForm["Round"], Specularity[White, 20], Tube[Perspective[ Trans5[RotFigure4[Tes, 0, 0, 0, a], 0, 0, 0, -3], -1], 0.04]}, PlotRange -> {{-.7, .7}, {-.7, .7}, {-.7, .7}}, Boxed -> False, Lighting -> "Neutral", ImageSize -> 1.1 {400, 400}, SphericalRegion -> True], {{a, 0, "动起来"}, 0, 2*3.1416, .0001, Appearance -> "Labeled"}, SaveDefinitions -> True 呵呵,这个动态图的自定义很多,而且我也不会导出动态图!自己慢慢理解吧!
- 04
这里画一个 克莱因瓶,这是个四维空间的物体,来源于 莫比乌斯带的类比。 Manipulate[ With[{bsc = Take[{{0, 0, 0}, {0, 0, 14}, {0, 0, 20}, {0, 0, 25}, {1.7, 0, 30}, {7, 0, 32}, {10, 0, 31.5}, {13, 0, 30}, {15, 0, 26}, {13, 0, 20}, {10, 0, 17.5}, {4, 0, 13.5}, {2.5, 0, 11}, {0.33, 0, 7}, {0.2, 0, 2.5}, {0, 0, 0}}, t + 2], sizes = Take[{6.5, 14, 4, 2.3, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.6, 3.3, 3.6, 4.3, 6.5}, t + 2]}, Graphics3D[{color, CapForm[None], Opacity[opacity], Tube[BSplineCurve[bsc], sizes]}, Boxed -> False, PlotRange -> {{-15, 17}, {-15, 15}, {0, 35}}, ViewPoint -> {0, -5, 0}, SphericalRegion -> True, ImageSize -> {500, 500}]], {{t, 1, "times"}, 1, 14, 1}, {{opacity, 0.7}, 0.1, 1}, {{color, Blue}, ColorSlider}
- 05
把克莱因瓶涂成彩色格子。 Manipulate[ KleinBottle[u, v, a, b], {{u, 2. Pi, "draw"}, 1, 2. Pi, ImageSize -> Tiny}, {{v, Pi, "cutaway"}, Pi, 2. Pi, ImageSize -> Tiny}, {{a, 1, "mesh A"}, 1, 8, 1, ImageSize -> Tiny}, {{b, 1, "mesh B"}, 1, 4, 1, ImageSize -> Tiny}, ControlPlacement -> Left, SaveDefinitions -> True