4
$\begingroup$

I made this optical illusion so that the half spheres disappear at some point and another illusion is that you may switch from perceiving spheres from convex to concave and vice versa.

How to do the same output but with Tube-s instead of Line-s and with MaterialShading and Lighting?

Lines can be replaced afterwards with /.Line->Tube but how to add MaterialShading and Lighting?

Plot3D[{Piecewise[{{Sqrt[
     2 - (x + 2)^2 - (y - 2)^2], (x + 2)^2 + (y - 2)^2 < 2}, {-Sqrt[
      2 - (x - 2)^2 - (y - 2)^2], (x - 2)^2 + (y - 2)^2 < 2}, {-Sqrt[
      2 - (x + 2)^2 - (y + 2)^2], (x + 2)^2 + (y + 2)^2 < 2}, {Sqrt[
     2 - (x - 2)^2 - (y + 2)^2], (x - 2)^2 + (y + 2)^2 < 2}}, 
   0]}, {x, -4, 4}, {y, -4, 4}, AspectRatio -> 1, 
 PlotStyle -> Transparent, Mesh -> {18, 18}, BoundaryStyle -> None, 
 Boxed -> False, Axes -> False, ViewProjection -> "Orthographic", 
 SphericalRegion -> Sphere[{0, 0, 0}, 4.2], ImageSize -> 500, 
 ImagePadding -> None, ImageMargins -> 0, 
 Method -> {"RotationControl" -> "ArcBall"}, BoxRatios -> Automatic, 
 MeshStyle -> {Directive[{Opacity[0.5], Thick, Black}], 
   Directive[{Opacity[0.5], Thick, Black}]}, ViewPoint -> {0, 0, 2}, 
 ViewVertical -> {0, 1, 0}, PerformanceGoal -> "Quality", 
 PlotPoints -> 200]

enter image description here

enter image description here

$\endgroup$
5
  • $\begingroup$ Define "nice and realistic." $\endgroup$ Nov 11, 2023 at 23:51
  • $\begingroup$ Like when you make some 3D graphics with predefined settings and then you use MaterialShading and Lighting which makes it looking more realistic and more nice. $\endgroup$ Nov 11, 2023 at 23:54
  • $\begingroup$ try MeshStyle -> {{MaterialShading[{"Glazed", Black}], Tube[.07]}, {MaterialShading[{"Glazed", Black}], Tube[.07]}} and Lighting -> "ThreePoint"? $\endgroup$
    – kglr
    Nov 12, 2023 at 1:12
  • $\begingroup$ @kglr: It made my Mathematica frozen. $\endgroup$ Nov 12, 2023 at 12:11
  • $\begingroup$ @kglr: It does not work, the tubes are ugly black. But with MeshStyle -> {MaterialShading[{"Glazed", Black}], Tube[.07]} Tubes look good but they are only in x direction but not y. $\endgroup$ Nov 12, 2023 at 13:07

2 Answers 2

2
$\begingroup$
$Version
"13.3.1 for Linux x86 (64-bit) (July 24, 2023)"
pw[x_, y_] := Piecewise[
    {{Sqrt[2 - (x + 2)^2 - (y - 2)^2], (x + 2)^2 + (y - 2)^2 < 2}, 
     {-Sqrt[2 - (x - 2)^2 - (y - 2)^2], (x - 2)^2 + (y - 2)^2 < 2}, 
     {-Sqrt[2 - (x + 2)^2 - (y + 2)^2], (x + 2)^2 + (y + 2)^2 < 2}, 
     {Sqrt[2 - (x - 2)^2 - (y + 2)^2], (x - 2)^2 + (y + 2)^2 < 2}}, 
    0]

options = {
    AspectRatio -> 1, 
    Mesh -> {18, 18}, 
    BoundaryStyle -> None, 
    Boxed -> False, 
    PlotStyle -> None,
    Axes -> False, 
    ViewProjection -> "Orthographic", 
    SphericalRegion -> Sphere[{0, 0, 0}, 4.2], 
    ImageSize -> 500, 
    ImagePadding -> None, 
    ImageMargins -> 0, 
    Method -> {"RotationControl" -> "ArcBall"}, 
    BoxRatios -> Automatic,
    ViewPoint -> {0, 0, 2}, 
    ViewVertical -> {0, 1, 0},  
    PerformanceGoal -> "Quality", 
    PlotPoints -> 200, 
    Lighting -> "ThreePoint", 
    Exclusions -> None};

We can use Tube as MeshStyle directive:

meshStyle = {MaterialShading[{"Glazed", Red}], JoinForm["Round"],   Tube[.09]};

Plot3D[pw[x, y], {x, -4, 4}, {y, -4, 4}, 
  Evaluate @ options, MeshStyle -> {meshStyle, meshStyle}]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ So the problem was PlotStyle -> Transparent. Try the same code replacing PlotStyle -> None with PlotStyle -> Transparent and it will freeze Mathematica. Which really it should not happen. And I consider it to be a bug. $\endgroup$ Nov 12, 2023 at 17:02
1
$\begingroup$

While I have not figured out how to use tubes with MaterialShading I found out that using PlotStyle -> None instead of PlotStyle -> Transparent and completely removing MeshStyle -> {Directive[{Opacity[0.5], Thick, Black}] improves the final quality of graphics considerably.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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