2
$\begingroup$

I'd like to reproduce the 3d surface of the attached image Surface.

What I'm interested in, is the light reflection at the basis of the surface and the rainbowlike color. I use Plot3d and colorfunction in order to color the surface in function of the height. However the specularity does not seem to work, i.e. it works only when one uses just a single color to paint the surface.

I looked for a solution several hours and the only thing I was able to find is this old link for something similar made in M5.2, which I'm not able to run in M9 because of obsolete functions.

I'd really appreciate any help.

Wign

$\endgroup$
  • $\begingroup$ Can you give example code so that we have something to start from? $\endgroup$ – bill s Mar 26 '15 at 14:02
  • $\begingroup$ Sure, here my code: Plot3D[Exp[-x^2 - y^2], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 50, PlotRange -> All, PlotRangePadding -> None, ColorFunction -> Function[{x, y, z}, Hue[.65 (1 - z)]], Mesh -> None, PlotPoints -> 50, Lighting -> "Neutral"] $\endgroup$ – Wign Mar 26 '15 at 14:05
5
$\begingroup$

Starting from this Plot3D:

Plot3D[
  Exp[-x^2 - y^2],
  {x, -3, 3},
  {y, -3, 3},
  PlotPoints -> 100,
  PlotRange -> {0, 1},
  PlotRangePadding -> None,
  Mesh -> None,
  PlotPoints -> 50,
  BoxRatios -> {1, 1, 1},
  Boxed -> False,
  AxesLabel -> Automatic,
  ViewPoint -> 100 {-2, -2, 3}
]

let me address the question of how to use both ColorFunction and Specularity at the same time.

The key to this is the following sentence in the documentation of ColorFunction:

The function specified by ColorFunction must return color directives such as RGBColor and Hue or named colors such as Red and Blue.

Supplying this function to ColorFunction will turn the plot red:

ColorFunction -> (Red &) 

Adding Specularity (White is too harsh so I choose 60% white):

ColorFunction -> ({Specularity[GrayLevel[0.6], 10], Red} &)

Using an actual colour function instead of a single colour:

ColorFunction -> ({Specularity[GrayLevel[0.6], 10], Hue[.65 (1 - #3)]} &)

Plot3D with Hue and Specularity

As we can't just modify the default lighting angle, changing ViewPoint will alter where the reflection is with respect to the plot surface. (For example, try ViewPoint -> {-2, -2, 1}, which is closer to that in the figure you provide, but then the reflection is no longer at the base.) You will have to experiment with Lighting to create from scratch the lighting condition that gives you the reflection where you want for a particular ViewPoint.

$\endgroup$
  • $\begingroup$ Thank, you! I'm going to try this also: I've read that line too but I didn't find the correct way to implement and I wonder why Mathematica people didn't think to put an example. Really thanks again! $\endgroup$ – Wign Mar 28 '15 at 22:07
  • $\begingroup$ How is it possible to add opacity into this instead? $\endgroup$ – Raymond Ghaffarian Shirazi Sep 27 '15 at 22:44
  • $\begingroup$ How about something like ColorFunction -> (Opacity[0.5, Red] &)? $\endgroup$ – Taiki Sep 28 '15 at 9:43
  • $\begingroup$ or replace the Hue[...] above with for example Opacity[1/2, Hue[.65 (1 - #3)]] $\endgroup$ – Taiki Sep 28 '15 at 9:45
5
$\begingroup$

You can add Specularity to the ColorFunction. Here is a Manipulate you can play with to figure out what settings you prefer:

Manipulate[
 Plot3D[Exp[-x^2 - y^2], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 50, 
  PlotRange -> All, PlotRangePadding -> None, Mesh -> None,
  ColorFunction -> (Directive[Specularity[s, 20], 
      Glow @ ColorData["DarkRainbow"][#3]] &),  
  Lighting -> {{"Spot", White, Scaled[{r Cos[ϕ] Sin[θ], r Sin[ϕ] Sin[θ],
        r Cos[θ]}], α}}, PerformanceGoal -> "Quality", 
  BoxRatios -> {1, 1, 1}], 
  {s, 0, 1}, 
 {r, 1, 4}, {ϕ, 0, 2 Pi}, {θ, 0, Pi/2}, {α, 0, Pi}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you so much! I'm playing right now to find the proper combination :) Thank you again! $\endgroup$ – Wign Mar 26 '15 at 20:34
  • $\begingroup$ Does this still work in Mathematica 11.3 and newer? For me the specularity is not visible $\endgroup$ – Mr Puh Aug 10 '18 at 13:56
  • 1
    $\begingroup$ @MrPuh I think you might have to wrap the Plot3D in Style[Plot3D[...], "RenderingOptions" -> {"Graphics3DRenderingEngine" -> "BSPTree"}]. I am not sure what had been changed in 11.3, but I would report it to support@wolfram.com anyway. $\endgroup$ – chuy Aug 10 '18 at 15:08

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.