-1
$\begingroup$
RegionPlot3D[
 x^2 + y^2 + z^2 < 1.2 && 0 < z, {x, -1.2, 1.2}, {y, -1.2, 
  1.2}, {z, -1.2, 1.2}, BoxRatios -> Automatic, Mesh -> None, 
 ColorFunction -> (If[#^2 + #2^2 + #3^2 < 1, Blue, 
     Opacity[.2, Red]] &), Axes -> True, AxesOrigin -> {0, 0, 0}, 
 Boxed -> False]

Actually this code want to render the range x^2 + y^2 + z^2 from 0 to 1 with blue and the outer sphere with Opacity[.2, Red] .But why do I get this? Is it a bug of ColorFunction?

Update(by Simon Woods's comment)

RegionPlot3D[
 x^2 + y^2 + z^2 < 1.2 && 0 < z, {x, -1.2, 1.2}, {y, -1.2, 
  1.2}, {z, -1.2, 1.2}, BoxRatios -> Automatic, Mesh -> None, 
 ColorFunction -> (If[#^2 + #2^2 + #3^2 < 1, Blue, 
     Opacity[.1, Red]] &), Axes -> True, AxesOrigin -> {0, 0, 0}, 
 Boxed -> False, ColorFunctionScaling -> False, PlotPoints -> 150]

The remaining questions is why we cannot see the inside blue through the transparent red?

$\endgroup$
  • $\begingroup$ It's not a bug - the parameters fed to ColorFunction are scaled to run from 0 to 1 unless you specify ColorFunctionScaling -> False $\endgroup$ – Simon Woods Nov 27 '16 at 9:38
  • $\begingroup$ You are not making it clear what you find wrong with the result you are getting. It is obvious to you, of course, but not to me. Please give details about what is bother you. Is the coarseness of the boundary mesh? The ugly colors? Or something else? $\endgroup$ – m_goldberg Nov 27 '16 at 9:47
  • $\begingroup$ @SimonWoods Wow,I cannot realize this option.You comment solve this question almost,but why we cannot see the inside blue through the red? $\endgroup$ – yode Nov 27 '16 at 9:59
  • $\begingroup$ @m_goldberg Sorry I made some typo,but I have updated for that. $\endgroup$ – yode Nov 27 '16 at 10:03
  • $\begingroup$ Of course you can see the blue through the translucent red. But with your color function, the only part of hemisphere that gets colored blue is the base. $\endgroup$ – m_goldberg Nov 27 '16 at 10:25
1
$\begingroup$

RegionPlot3D only draws the surface of the region - there is no inner hemisphere to paint blue. ColorFunction can only color the polygons that are there, it cannot create additional interior surfaces. You could instead create the red and blue hemispheres with separate plots and combine them using Show:

rp[r_, col_] := RegionPlot3D[x^2 + y^2 + z^2 < r && 0 < z,
  {x, -1.2, 1.2}, {y, -1.2, 1.2}, {z, -1.2, 1.2},
  PlotStyle -> col,
  BoxRatios -> Automatic, Mesh -> None, Boxed -> False,
  Axes -> True, AxesOrigin -> {0, 0, 0}, PlotPoints -> 50]

Show[rp[1.2, Opacity[.2, Red]], rp[1.0, Blue]]

enter image description here

$\endgroup$
1
$\begingroup$

To get a better understanding of what happens when you try to use a color function to divide a surface into opaque and translucent parts, you might want to experiment with a color function that divides your hemisphere into sectors.

RegionPlot3D[
  x^2 + y^2 + z^2 < 1. && 0 < z, {x, -1.2, 1.2}, {y, -1.2, 1.2}, {z, -.2, 1.2},
  PlotPoints -> 150,
  MaxRecursion -> 7,
  BoxRatios -> Automatic,
  Boxed -> False,
  Mesh -> None,
  ColorFunction -> 
    (If[0. < ArcTan[Abs[#1], Abs[#2]] < N[π/4], Lighter[Blue], Opacity[.2, Yellow]] &),
  Axes -> True,
  AxesOrigin -> {0, 0, 0},
  ImageSize -> 500]

plot

$\endgroup$

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.