# Plotting a function with three real arguments using transparency

I would like to plot a real function with three real arguments by assigning a transparency and color to the function values. The smallest value in the plotting range should be fully transparent, the largest value should be intransparent and red.

The purpose is to quickly see the structure and the maxima in the plotting range, which should appear as red nebulous regions. For example,

f[x_,y_,z_]=1/(1+x^2+y^2+z^2)


is maximal at {x=0,y=0,z=0}. The plot command I try to build should produce a spherical nebula which is densest at the center. Ideally, one can adjust the transparency with a slider, or choose a log-scaling for the transparency, to increase the visibility of the maximum.

So far I did not find a method to do this in Mathematica.

Any help is greatly appreciated.

Conclusions:

Below MMA 9.0 it is hard to do, from 9.0 onwards we have Image3D and Raster3D and from MMA 10 onwards we have additionally DensityPlot3D to do this. I have iterated rhermans solution to automatically scale and draw some coordinate indications (i guess the code golf people can put this in two lines or so...):

xmin = -3; xmax = 3; deltax = 0.2;
ymin = -5; ymax = 5; deltay = 0.2;
zmin = -7; zmax = 7; deltaz = 0.2;
f[x_, y_, z_] = z
tmp = Table[
f[x, y, z], {x, xmin, xmax, deltax}, {y, ymin, ymax, deltay}, {z,
zmin, zmax, deltaz}];
min = Min[tmp];
max = Max[tmp];
m = -(1/(-max + min));
n = min/(-max + min);

xmaxint = Length[tmp]
ymaxint = Length[tmp[[1]]]
zmaxint = Length[tmp[[1, 1]]]

Graphics3D[{Raster3D[
Table[{m tmp[[i, j, k]] + n, 0, 0, (m tmp[[i, j, k]] + n)^2}, {i,
1, xmaxint}, {j, 1, ymaxint}, {k, 1, zmaxint}]],
Point[{0, 0, 0}],
Text[{xmax, ymax, zmax}, {0, 0, 0}],
Point[{zmaxint, ymaxint, xmaxint}],
Text[{xmin, ymin, zmin}, {zmaxint, ymaxint, xmaxint}]
}]


-
There are things to do after your question is answered. It's a good idea to stay vigilant for some time, better approaches may come later improving over previous replies. Experienced users may point alternatives, caveats or limitations. New users should test answers before voting and wait 24 hours before accepting the best one. Participation is essential for the site, please come back to do your part tomorrow – rhermans Feb 10 at 12:18
OK, thanks for the hints. I check in tomorrow. I tested your answer and it worked. I voted for your answer since it works also in MMA below version 10. – Christian Schmidt Feb 10 at 15:08

# Image3D

Using Image3D

Image3D[
Table[
{f[x, y, z], 0, 0}
, {x, -3, 3, 0.1}
, {y, -3, 3, 0.1}
, {z, -3, 3, 0.1}
]
]


At a different range

Image3D[
Table[
{f[x, y, z], 0, 0}
, {x, -10, 10, 1}
, {y, -10, 10, 1}
, {z, -10, 10, 1}
]
]


# Raster3D

Or using Raster3D

Here I'm squaring the Alpha channel for a more striking difference.

Graphics3D[{Raster3D[
Table[
{f[x, y, z], 0, 0, f[x, y, z]^2}
, {x, -3, 3, 0.1}
, {y, -3, 3, 0.1}
, {z, -3, 3, 0.1}
]
]}]


-
I'm jealous that you can get Image3D to work. I get crap like this when I try :-( – JasonB Feb 10 at 12:05
@JasonB why do you get that? I'm using Mma 10.3.1 in Win 7 64 with NVIDIA NVS 4200M nothing fancy. – rhermans Feb 10 at 12:20
MMA is buggy in Linux is all I can say. mathematica.stackexchange.com/q/105909/9490 – JasonB Feb 10 at 12:23
I can confirm that. – Christian Schmidt Feb 10 at 15:05

Another option is to use DenistyPlot3D. You can set your own custom OpacityFunction and ColorFunction (by default they take scaled values between 0 and 1)

DensityPlot3D[
1/(1 + x^2 + y^2 + z^2), {x, -5, 5}, {y, -5, 5}, {z, -5, 5},
PlotPoints -> 100,
OpacityFunction -> Function[f, (Exp[4 f] - 1)/(E^4 - 1)],
ColorFunction -> (ColorData["SolarColors"][1 - #] &)
]


-
Thanks! This appears to be new in Mathematica 10. Thats why I couldn't find it. – Christian Schmidt Feb 10 at 12:17
I did look for something like this, but didn't find it. +1 ! – rhermans Feb 10 at 12:18