填写Graphics3D对象

时间:2011-07-28 07:07:25

标签: graphics wolfram-mathematica 3d

这是一个我不知道是否可以在Mathematica中解决的问题。

(* Courtesy to Lunchtime Playground Blog *)
to3d[plot_, height_, opacity_] :=
Module[{newplot}, newplot = First@Graphics[plot];
newplot = N@newplot /. {x_?AtomQ, y_?AtomQ} -> {x, y, height} /. 
Arrowheads[List[List[x_, y_, notz_]]] -> 
 Arrowheads[List[List[x, y]]];newplot /.GraphicsComplex[xx__] -> {Opacity[opacity], GraphicsComplex[xx]}];
(* A function to combine 2D Graphics object in Mathematica *)
test[list_]:=VectorQ[list,SameQ[Head[#],Graphics]&];
My3DPlot[list_?(test[#]&),height_?(VectorQ[#,NumberQ]&),opacity_?(VectorQ[#,NumberQ]&),opts:OptionsPattern[]]:=Block[{a},a=MapThread[Graphics3D[to3d[#1,#2,#3]]&,{list,height,opacity}];
Show[a,opts]
]
(* List of 2D graphics *)
list=Table[ContourPlot[y+Sin[x^i+i y],{x,-3,3},{y,-3,3},Contours->15,ContourLines->False,ColorFunction->RandomChoice[ColorData["Gradients"]]],{i,{1,2,3,4}}];
(* List of heights where you want to place the images *)
height={-.5,0,.5,1};
(* List of opacities you want to apply to your 2D layers *)
opacity={1,.8,.7,.5};
(* The function inherits all the options of standard Graphics3D as they are passed through the Show command *)
My3DPlot[Reverse@list,height,opacity,Lighting->"Neutral",BoxRatios->{1,1,.9},Axes->True]

现在这会返回一张像这样的酷图片。enter image description here

这里我的问题是,是否可以使用与轮廓图中使用的颜色函数相同的颜色函数为这个2D图层创建填充?目标是用一些颜色填充这些2D图层之间的空洞,这些颜色根据相邻图层颜色函数不断变化。

我希望这可以在Mathematica中完成,但我对Mathematica图形的有限知识使我成为一个困难的障碍。

1 个答案:

答案 0 :(得分:0)

应该可以。 Texture可用于生成3D纹理。文档中给出的示例:

data = Table[{r, g, b}, {r, 0, 1, 1/20}, {g, 0, 1, 1/20}, {b, 0, 1, 1/20}];

Graphics3D[
  {
   Opacity[1/3], 
   Texture[data], 
   EdgeForm[], 
   Polygon[Table[{{0, 0, z}, {1, 0, z}, {1, 1, z}, {0, 1, z}}, {z, 0, 1, 1/20}], 
   VertexTextureCoordinates -> 
    Table[{{0, 0, s}, {1, 0, s}, {1, 1, s}, {0, 1, s}}, {s, 0, 1, 1/20}]]
  },
  Lighting -> "Neutral"
]

enter image description here

这通过使用大量平面来模拟音量。你也可以做到的。您所要做的就是描述3D纹理,它应该在您已经拥有的平面之间进行插值。Blend将是此处使用的函数。对于立方体中的每个像素列,颜色变化为Blend[{col1,col2,col3,...},x],x从0变为1,而大肠杆菌变为第i个平面中由等高线图给出的像素颜色。

主要问题是具有模糊颜色渐变的3D半透明物体不是可视化的东西。