繁体   English   中英

填写Graphics3D对象

[英]Filling in a Graphics3D object

这是一个我不知道是否可以在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]

现在这将返回像这样的酷图片。 在此输入图像描述

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

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

它应该是可能的。 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"
]

在此输入图像描述

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

主要问题是具有模糊颜色梯度的3D半透明物体不能很好地可视化。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM