[英]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.