7
$\begingroup$

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

Gradient plot of a 3-variant function with transparency, large values are more transparent.

$\endgroup$
  • 2
    $\begingroup$ 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. $\endgroup$ – Rainer Glüge Feb 10 '16 at 15:08
5
$\begingroup$

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

Mathematica graphics

At a different range

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

Mathematica graphics


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

enter image description here

$\endgroup$
  • $\begingroup$ I'm jealous that you can get Image3D to work. I get crap like this when I try :-( $\endgroup$ – Jason B. Feb 10 '16 at 12:05
  • $\begingroup$ @JasonB why do you get that? I'm using Mma 10.3.1 in Win 7 64 with NVIDIA NVS 4200M nothing fancy. $\endgroup$ – rhermans Feb 10 '16 at 12:20
  • 1
    $\begingroup$ MMA is buggy in Linux is all I can say. mathematica.stackexchange.com/q/105909/9490 $\endgroup$ – Jason B. Feb 10 '16 at 12:23
  • $\begingroup$ I can confirm that. $\endgroup$ – Rainer Glüge Feb 10 '16 at 15:05
8
$\begingroup$

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 - #] &)
 ]

3D density plot

$\endgroup$
  • 1
    $\begingroup$ Thanks! This appears to be new in Mathematica 10. Thats why I couldn't find it. $\endgroup$ – Rainer Glüge Feb 10 '16 at 12:17
  • $\begingroup$ I did look for something like this, but didn't find it. +1 ! $\endgroup$ – rhermans Feb 10 '16 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.