简体   繁体   English

填写Graphics3D对象

[英]Filling in a Graphics3D object

Here is a problem that I don't know if can be solved in Mathematica. 这是一个我不知道是否可以在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]

Now this returns a cool picture like this one. 现在这将返回像这样的酷图片。 在此输入图像描述

Here my question is if it is possible to create a filling for this 2D layers using the same color functions as are used with in the contour plots for example? 这里我的问题是,是否可以使用与轮廓图中使用的相同颜色函数为这个2D图层创建填充? Target is to fill the hollow between these 2D layers with some light or color that continuously changes according to the neighboring layer color-function. 目标是填充这些2D层之间的空洞,其中一些颜色根据相邻层颜色函数连续变化。

I hope this can be done in Mathematica but my limited knowledge in Mathematica graphics is making it a difficult hurdle for me. 我希望这可以在Mathematica中完成,但我对Mathematica图形的有限知识使我成为一个困难的障碍。

It should be possible. 它应该是可能的。 Texture can be used to generate a 3D texture. Texture可用于生成3D纹理。 The example given in the documentation: 文档中给出的示例:

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"
]

在此输入图像描述

This simulates a volume by using a large set of planes. 这通过使用大量平面来模拟体积。 You can do the same. 你也可以做到的。 All you have to do is describe the 3D texture, which should interpolate between the planes you already have. 您所要做的就是描述3D纹理,它应该在您已经拥有的平面之间进行插值。 Blend would be the function to be used here. Blend将是这里使用的功能。 For each pixel column in your cube the color varies as Blend[{col1,col2,col3,...},x] with x going from 0 to 1 and coli the color of the pixel in the ith plane given by the contour plots. 对于立方体中的每个像素列,颜色随Blend[{col1,col2,col3,...},x]变化而变化Blend[{col1,col2,col3,...},x]从0变为1,而大肠杆菌则是由等高线图给出的第i个平面中像素的颜色。

The main problem will be that a 3D semi-transparant object with fuzzy color gradients is not something that visualizes very well. 主要问题是具有模糊颜色梯度的3D半透明物体不能很好地可视化。

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

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