1

I have found related questions but none of them is exactly what I want.

With tikz I can plot a shaded sphere as follows

\documentclass[crop,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}

\begin{document} \tdplotsetmaincoords{110}{-30} \begin{tikzpicture}[tdplot_main_coords]

\pgfmathsetmacro{\myradius}{3}

\path[tdplot_screen_coords] (0,0) circle (\myradius);
\shade[tdplot_screen_coords,ball color=gray!50,opacity=1] (0,0) circle (\myradius);

\end{tikzpicture} \end{document}

This is the result:

sphere

How can I modify the above code, maybe with a suitable clip, such that only the back half of the sphere shows?

MathMax
  • 113
  • Welcome to TeX.SE! – Mensch Oct 05 '21 at 22:54
  • @Mensch Thank you very much. Any hints on showing the back half of a sphere, shaded from the inside? – MathMax Oct 05 '21 at 23:02
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – hpekristiansen Oct 06 '21 at 01:26
  • @hpekristiansen Fixed, thank you. – MathMax Oct 06 '21 at 14:30

4 Answers4

7

Another TikZ 3d solution, slightly different.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d}          % 'canvas is...' options
\usetikzlibrary{perspective} % isometric view

\begin{document} \begin{tikzpicture}[isometric view] % top half \draw[ball color=gray!50] {[canvas is xy plane at z=0] (135:2) arc (135:315:2)} arc (0:180:2cm); % bottom half \begin{scope}[yshift=-3cm] \draw[ball color=gray!70,shading angle=180] (0,0) circle (2); \draw[ball color=gray!50] {[canvas is xy plane at z=0] (315:2) arc (315:135:2)} arc (180:360:2cm); \end{scope} \end{tikzpicture} \end{document}

enter image description here

Edit: better light effects (but more code) using clips:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d}          % 'canvas is...' options
\usetikzlibrary{perspective} % isometric view

\newcommand\contour {% {[canvas is xy plane at z=0] (135:2) arc (135:315:2)} arc (0:180:2cm) } \newcommand\half {% \begin{scope} \clip \contour; \fill[ball color=gray!50] (0,0,0) circle (2cm); \end{scope} \draw \contour; }

\begin{document} \begin{tikzpicture}[isometric view] % top half \begin{scope} \half \end{scope} % bottom half \begin{scope}[yshift=-3cm,rotate=180] \half \draw[ball color=gray!70,shading angle=180] (0,0) circle (2); \end{scope} \end{tikzpicture} \end{document}

enter image description here

Juan Castaño
  • 28,426
  • Thank you for your detailed answer. My question was about the back half, not top and bottom half, as in hpekristiansen's answer. Upvoted for your kind effort anyways and for the nice solution. – MathMax Oct 06 '21 at 12:22
6

One possible and simple solution with arc.

\documentclass[border=1cm]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\shade[ball color=gray!50,opacity=1] (0,0) arc (0:-180:1cm and 4mm) arc (180:0:1cm and 1cm);

\end{tikzpicture}

\end{document}

enter image description here

EDIT: Since OP clarified what he wants I just want to add one correct solution:

\documentclass[border=1cm]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\shadedraw [ball color=gray!50,shading=ball,opacity=1] (0,-1) arc (-90:90:1cm and 10mm);

\shadedraw [ball color=gray!50,shading=ball,opacity=1] (0,0) ellipse (0.5cm and 1cm);

\end{tikzpicture}

\end{document}

enter image description here

Roland
  • 6,655
  • Thank you for your answer. My question was about the back half, not the top half. The solution by hpekristiansen is the correct one. Upvoted for you kind effort anyways. – MathMax Oct 06 '21 at 12:21
4
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\shade[ball color=gray!50] (0,0) circle[radius=2 cm] node {Front half};
\shade[ball color=gray!50, shading angle=180] (5,0) circle[radius=2 cm] node {Back half};
\end{tikzpicture}
\end{document}

Two shaded balls with text

  • Ah this was the actual question. Got it – Roland Oct 06 '21 at 03:17
  • @Roland: I am not sure at all. Your solution might be the correct one - hard to tell. – hpekristiansen Oct 06 '21 at 03:19
  • Thank you hpekristiansen, this is the correct answer. My bad for not clearing out enough that I wanted the back half, not the top or bottom one. And for not providing a MWE. So the trick is basically to draw a circle with a suitably oriented light... – MathMax Oct 06 '21 at 12:26
  • This is why craters look like mounds when lit from the south. But I digress... – John Kormylo Oct 06 '21 at 14:06
  • @MathMax Note that this solution is actually an optical illusion. As John Kormylo already mentioned. It works here because we see the front half and the back half next to each other (assuming the light source comes from above). Once you remove one your brain may make a sphere out of it again. – Roland Oct 06 '21 at 23:33
  • @Roland After all, every 3D object we see on the screen is an optical illusion, right? – MathMax Oct 07 '21 at 11:56
3

In case you are interested in Asymptote, there is available unithemisphere from the 3D module three. Just paste the following codes to http://asymptote.ualberta.ca/ and click Run. Note that both code use the same projection (same point of view). You may want to change opacity(.5) to see the hidden things.

The front half hemisphere is the sphere part with x > 0:

enter image description here

import three;
size(6cm);
currentprojection=orthographic((1,1,.6),zoom=.9);
draw(Label("$x$",EndPoint),O--2X,red);
draw(Label("$y$",EndPoint),O--2Y,green);
draw(Label("$z$",EndPoint),O--2Z,blue);

// the front half x>0 draw(rotate(90,Y)*unithemisphere,yellow+opacity(1));

and the back half hemisphere is the sphere part with x < 0:

enter image description here

import three;
size(6cm);
currentprojection=orthographic((1,1,.6),zoom=.9);
draw(Label("$x$",EndPoint),O--2X,red);
draw(Label("$y$",EndPoint),O--2Y,green);
draw(Label("$z$",EndPoint),O--2Z,blue);

// the back half x<0 draw(rotate(-90,Y)*unithemisphere,yellow+opacity(1));

Black Mild
  • 17,569
  • I didn't know Asymptote, thank you for your answer. My question, however, was about the back half, not top and bottom half. Upvoted anyways for the nice solution and kind effort – MathMax Oct 06 '21 at 12:34
  • @MathMax how about the back and front hemispheres in my answer now? – Black Mild Oct 06 '21 at 16:04
  • Yup, you nailed it! Thank you once again. I really need to add Asymptote to my graphics arsenal. – MathMax Oct 06 '21 at 22:46
  • We can construct (closed, with base) hemisphere as in this answer https://tex.stackexchange.com/a/559027/140722 – Black Mild Oct 10 '21 at 15:23