Mathematica除了让学习更有趣之外,还使我们的生活变得更有意义.
下面小编从Mathematica中给大家变出一个多彩的盒子.
首先要找六张你喜欢的图片,把这些图片赋值给一个变量 pics 现在让我们取出第一张图片来做一点测试, 也就是将该照片作为纹理应用在 3 D 的多边形之中.
Graphics3D[{Texture[pics[[1]]], Polygon[{{-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},
Lighting -> "Neutral"]
好的, 刚才是一张多边形的例子, 那现在我们想要将这张图片的纹理映射在盒子的 6 个面上, coords 就是这 6 个面的坐标..
vtc = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
coords = {{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}}, {{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1} }, {{1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1}}, {{1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1, 1}}, {{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}};
Graphics3D[{Texture[pics[[1]]], Polygon[coords, VertexTextureCoordinates -> Table[vtc, {6}]]}, Lighting -> "Neutral", Boxed -> False]
再更复杂一点, 刚才是一张纹理的例子, 那现在我们想要将 6 张图片的纹理映射在盒子的 6 个面上.原理其实都是一样的,但在这里我们加入一点点的透明度..
sides = pics[[;; 6]];
v = {{-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}, {-1, -1, 1}, {1, -1, 1}, {1, 1, 1}, {-1, 1, 1}};
idx = {{1, 2, 3, 4}, {1, 2, 6, 5}, {2, 3, 7, 6}, {3, 4, 8, 7}, {4, 1, 5, 8}, {5, 6, 7, 8}};
vtc = {{0.01, 0.01}, {0.99, 0.01}, {0.99, 0.99}, {0.01, 0.99}};
Graphics3D[{Opacity[.8], EdgeForm[Directive[Thick, White]], Table[{Texture[sides[[i]]], GraphicsComplex[v, Polygon[idx[[i]], VertexTextureCoordinates -> vtc]]}, {i, 6}]}, Boxed -> False, Method -> {"RotationContor" -> "Globe"}, Lighting -> "Neutral"]
现在让我们钻到盒子的里面去看一下,
当然需要指定我们的观察点了 ViewVector -> {{.8, .8, 0}, {0, 0, 0}}.
Graphics3D[{Black, EdgeForm[None], Table[{Texture[sides[[i]]], GraphicsComplex[v, Polygon[idx[[i]], VertexTextureCoordinates -> vtc]]}, {i, 6}]},
ViewVector -> {{.8, .8, 0}, {0, 0, 0}}, ViewAngle -> 2, Boxed -> False, Method -> {"RotationContor" -> "Globe"}]