Skip to main content

visualization - Graphics3D: Opacity limitations


Trying to make a better-looking globe model, I start off with something like this


enter image description here


To enhance the 3D effect, I want the lines further from the eye to be "grayer" than the lines closer to the eye, as if there were a little fog inside the sphere. I thought I might get there by replacing the great-circles with semi-transparent wafers, but it didn't work. It seems as though I hit some kind of internal limit on the number of semi-transparent objects I can create before they become opaque.



Here is the original code with polygonal great circles (minus the RGB-XYZ axes):


ClearAll[e, o, g, ϵ];
e[1] = {1, 0, 0}; e[2] = {0, 1, 0}; e[3] = {0, 0, 1};
o = {0, 0, 0}; g = 1.25; ϵ = 1/10000;
ClearAll[polycircle];
polycircle[n_: 360] :=
Line@Table[{Cos[2 π i/n], Sin[2 π i/n], 0}, {i, n + 1}];
ClearAll[globeGrid];
globeGrid[bands_: 6, figure_: polycircle[]] :=
{Table[

Scale[Translate[figure, Sin[(k π)/2] e[3]],
Cos[(k π)/2]]
, {k, -((bands - 1)/bands), (bands - 1)/bands, 1/bands}]
, Table[Rotate[Rotate[figure, π/2, e[1]], k π, e[3]]
, {k, 0, (bands - 1)/bands, 1/bands}]};
ClearAll[showFrames];
showFrames[figure_:polycircle[]] := Show[{
Graphics3D[{
Opacity[0.05], Sphere[], Opacity[1.0]
, globeGrid[6, figure]

}] }
, Axes -> True
, PlotRange -> {{-g, g}, {-g, g}, {-g, g}}
, ImageSize -> Large];
showFrames[]

To improve it, I replace the polycircles with partially transparent wafers, which are very thin cylinders at low opacity:


ClearAll[wafer];
wafer[opacity_: 1/24] :=
{RGBColor[1, 0.71, 0]

, Opacity[opacity]
, Cylinder[ϵ {-e[3], e[3]}]
, Opacity[1]};

The results were disappointing


showFrames[wafer[]]

enter image description here


EDIT: I tried a tube


polytorus[n_: 100] := Tube[polycircle[n], 0.01];

showFrames[polytorus[48]]

it's too slow to be interactive, but it has a better 3D effect. Still looking for a better answer.


enter image description here



Answer



How about something Image3D-based?


grid = First@
ParametricPlot3D[{Cos[u] Cos[v], Sin[u] Cos[v], Sin[v]}, {u, 0,
2 Pi}, {v, -Pi/2, Pi/2}, PlotStyle -> None];


Graphics3D[
{grid,
{Red, Thick, Line[1.2 {{-1, 0, 0}, {1, 0, 0}}]},
{Blue, Thick, Line[1.2 {{0, -1, 0}, {0, 1, 0}}]}, {Green, Thick,
Line[1.2 {{0, 0, -1}, {0, 0, 1}}]},
Raster3D[Array[
UnitStep[1 - Norm[{##}]] &, {100, 100,
100}, {{-1., 1.}, {-1., 1.}, {-1., 1.}}], {{-1, -1, -1}, {1, 1,
1}}, ColorFunction -> (GrayLevel[0.8, .03 #] &)]
},

Boxed -> False]

Mathematica graphics


Edit by halirutan


Let me point out some flaws and probably improve the quality a bit. Therefore, blame me for everything that follows, not Szabolcs.


First of all, fog is usually a global thing which means that the impact on the visibility really depends on the distance to the viewer. If the fog is only visible inside the sphere, then we have things like the top of wireframe which is crystal clear (and an eye catcher because lines meet there) while it is farther away from the camera than the front wire.


Therefore, we might improve the effect by making a foggy cube that is larger than the wireframe so that at least it looks like fog is everywhere from the camera viewpoint.


Another detail seems to be that the gradient with which view is degrading doesn't seem to be enough. Therefore, one could make a cube that has not a constant visual density, but a density that is getting larger in one direction. If we then view the wireframe from the correct viewpoint, it might increase the fog-effect.


Last point, I think fog looks better when it is white, not gray. If we combine all these points and make the wireframe thicker then I get something like the following (I'll append the code at the end):


enter image description here



There are some points left: Most importantly, I don't think it is appropriate to try to achieve something like this in the Mathematica front end. If you need high quality, then create your model and render it with Blender (or whatever renderer you prefer).


Finally, I could not get antialiasing working when I combined a Raster3D with a normal 3d graphics in Mathematica. It seems that this is not working with Raster3D or Image3D.


grid = First@
ParametricPlot3D[{Cos[u] Cos[v], Sin[u] Cos[v], Sin[v]}, {u, 0,
2 Pi}, {v, -Pi/2, Pi/2}, PlotStyle -> None,
MeshStyle ->
Directive[Thickness[0.005], RGBColor[0, 43/255, 18/85]]];

Graphics3D[{grid, RGBColor[44/51, 10/51, 47/255], Thickness[.01],
Line[1.2 {{-1, 0, 0}, {1, 0, 0}}], {RGBColor[38/255, 139/255,

14/17], Line[1.2 {{0, -1, 0}, {0, 1, 0}}]}, {RGBColor[133/255,
3/5, 0], Line[1.2 {{0, 0, -1}, {0, 0, 1}}]},
White,
Raster3D[
Array[#3 &, {100, 100,
100}, {{0, 1}, {0, 1}, {0, 1}}], {{-1, -2, -2}, {1, 2, 2}},
ColorFunction -> (GrayLevel[1, .05 #] &)]}, Boxed -> False,
ViewPoint -> {-3.15, -0.89, 0.84}, ViewAngle -> 0.175]

Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.