# How to make this optical illusion in 3D with Tube instead of Line?

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]


• Define "nice and realistic." Nov 11, 2023 at 23:51
• 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. Nov 11, 2023 at 23:54
• try MeshStyle -> {{MaterialShading[{"Glazed", Black}], Tube[.07]}, {MaterialShading[{"Glazed", Black}], Tube[.07]}} and Lighting -> "ThreePoint"?
– kglr
Nov 12, 2023 at 1:12
• @kglr: It made my Mathematica frozen. Nov 12, 2023 at 12:11
• @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. Nov 12, 2023 at 13:07

\$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,
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}]


• 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. Nov 12, 2023 at 17:02

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.