6

I'm trying to recreate this picture, but unfortunately I don't know how to make the transparent spheres. Has anybody an idea? Thanks David

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x={(-10:1cm)},y={(90:1cm)},z={(210:1cm)}, scale=.75]
\foreach \i in {-5,...,-1}{
    \filldraw [fill=red, nearly transparent] (\i,2,3) -- (\i,-2,3) -- (\i,-2,-3) -- (\i,2,-3) -- cycle;
    \draw [] (\i,2,3) -- (\i,-2,3) -- (\i,-2,-3) -- (\i,2,-3) -- cycle;
}             
\filldraw [fill=white] (0,3,-4) -- (0,3,4) -- (0,-3,4);
\filldraw [fill=white] (.5,3,4) -- (.5,-3,4) -- (.5,-3,-4) -- (.5,3,-4) -- cycle;
\draw (0,3,4) -- (.5,3,4);
\draw (0,-3,4) -- (.5,-3,4);
\draw (0,3,-4) -- (.5,3,-4);
\draw [fill=black] (.5,0,0) [x={(0,0,1)}] circle (.1);
\foreach \i in {0.5,2,3.5}{
    \draw (.5,0,0) [x={(0,0,1)}] circle (\i);
}
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    (1) use high school math to draw the counter(s); (2) use multiple \clip and \fill to fill in colors; (3) use opacity=.5 to set transparency freely. – Symbol 1 Jun 20 '17 at 15:27
  • \begin{dirty self-promotion} You could probably adapt from here tex.stackexchange.com/a/375604/132800 \end{dirty self-promotion} If you want to avoid that, use something along the lines of \draw arc (start angle: end angle: major and minor axis) – Huang_d Jun 20 '17 at 16:45
2

As a starter, study the following code; It should give you a good idea of how to draw the spheres in properly faked 3D, adopted from here.

\documentclass[tikz,border=10pt]{standalone}
\begin{document}

%spherical coordinate system around y axis
\makeatletter
\define@key{y sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{y sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{y sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around y
    \setkeys{y sphericalkeys}{#1}%
    \pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*sin(\myphi)}}

%spherical coordinate system around z axis
\makeatletter
\define@key{z sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{z sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{z sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around z
    \setkeys{z sphericalkeys}{#1}%
    \pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}{\myradius*cos(\mytheta)}}

\begin{tikzpicture}%[z={(0.5cm,-0.3cm)}]
%Pinhole
\draw (0,0,0) circle (1pt);
%Innermost sphere
\foreach \aangle in {-90,-80,...,80}{
    \foreach \bangle in {-90,-80,...,80}{
    \fill[blue!20, fill opacity = 0.5] (z spherical cs: radius = 1, phi=\aangle, theta=\bangle) -- (z spherical cs: radius = 1, phi=\aangle+10, theta=\bangle) -- (z spherical cs: radius = 1, phi=\aangle+10, theta=\bangle+10) -- (z spherical cs: radius = 1, phi=\aangle, theta=\bangle+10)--cycle;
    }}
%second sphere
\foreach \aangle in {-90,-80,...,80}{
    \foreach \bangle in {-90,-80,...,80}{
    \fill[blue!20, fill opacity = 0.5] (z spherical cs: radius = 2, phi=\aangle, theta=\bangle) -- (z spherical cs: radius = 2, phi=\aangle+10, theta=\bangle) -- (z spherical cs: radius = 2, phi=\aangle+10, theta=\bangle+10) -- (z spherical cs: radius = 2, phi=\aangle, theta=\bangle+10)--cycle;
    }}
%sphere with ends
\foreach \aangle in {0,10,...,170}{
    \foreach \bangle in {30,40,...,140}{
    \fill[blue!20, fill opacity = 0.5] (y spherical cs: radius = 3, phi=\aangle, theta=\bangle) -- (y spherical cs: radius = 3, phi=\aangle+10, theta=\bangle) -- (y spherical cs: radius = 3, phi=\aangle+10, theta=\bangle+10) -- (y spherical cs: radius = 3, phi=\aangle, theta=\bangle+10)--cycle;
    }}
\end{tikzpicture}
\end{document}

This should push you in the right direction. Note that the code is brazenly slow and exceeds TeX capacity quickly if drawn with finer iterations. Each sphere is made up from flat planes 10°x10° in size, iterated with two foreach loops. Picture below; Note how the opacity neatly takes care of the self-overlap. You can "rotate" the spheres a little bit via the [z={(coordinate, coordinate)}] key to the tikzpicture environment, where (coordinate, coordinate) relate to the x,y coordinate on the canvas.

Overlapping spheres

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.