6

I am trying to draw a sphere with a handle similar to the one I have attached below with the package TikZ. Unfortunately, while I know how to draw a sphere or a torus, I don't know how to put them together without making a mess. Any kind of help or suggestion is very welcome, thanks.

enter image description here

So, for instance a sphere would be generated by a simple code as the one below, how to attach to this picture handle is however beyond my capacity at the moment

\documentclass[a4paper,11pt]{article}

\usepackage[T1]{fontenc} % if needed
\usepackage[english]{babel}
\usepackage{graphicx}                   
\usepackage{tikz} 

\begin{document}
    \begin{tikzpicture}[baseline]
    \shade[ball color = gray!40, opacity = 0.4] (0,0) circle (2cm);
    \draw (0,0) circle (2cm);
    \draw[dashed] (-2,0) arc (180:0:2 and 0.2);
    \draw[dashed] (-2,0) arc (180:0:2 and -0.2);

    \end{tikzpicture}

\end{document}

this code produces

enter image description here

5
  • 2
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – albert
    Nov 4, 2018 at 13:52
  • How spherical does the sphere have to be? You could draw a topologically equivalent picture fairly easily using the tqft package. Nov 4, 2018 at 13:57
  • I, unfortunately , need it to be quite spherical or else I would have drawn a torus.
    – Fra
    Nov 4, 2018 at 13:59
  • I have added the base code to generate a sphere, how to add a handle is not something I know how to do and is what I am asking about
    – Fra
    Nov 4, 2018 at 14:29
  • It would be simpler is the torus intersected the sphere perpendicularly. You can use a pgfplots version of a torus with a reduced domain, Then all you have to do is place the center of the torus on the surface of the sphere. Nov 4, 2018 at 14:32

1 Answer 1

7

This is a TikZ (and not asymptote) question. With TikZ one can certainly get some aspects of this right, but getting all of it right is arguably very hard. So this is a compromise.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\path[tdplot_screen_coords,use as bounding box] (-3.2,-3.2) rectangle (6,6);
\pgfmathsetmacro{\R}{3}
\pgfmathsetmacro{\myang}{20}
\pgfmathsetmacro{\angtop}{-80}
\pgfmathsetmacro{\angright}{95}
\coordinate (O) at (0,0,0);
\shadedraw [ball color=red,tdplot_screen_coords] (0,0,0) circle(\R);
\path 
({3*sin(\myang)*cos(\angright)},{3*cos(\myang)},{3*sin(\myang)*sin(\angright)}) coordinate (P1)
({3*sin(\myang)*cos(\angtop)},{3*sin(\myang)*sin(\angtop)},{3*cos(\myang)}) coordinate (P2);
\draw[right color=white,left color=red!80!black,shading angle=-225] plot[variable=\x,domain=\angtop:\angtop+180,samples=91]
({3*sin(\myang)*cos(\x)},{3*sin(\myang)*sin(\x)},{3*cos(\myang)})
to[out=90,in=0,looseness=2] (P1)
plot[variable=\x,domain=\angright:\angright-180,samples=91]
({3*sin(\myang)*cos(\x)},{3*cos(\myang)},{3*sin(\myang)*sin(\x)})
to[out=0,in=90,looseness=4] (P2);
\end{tikzpicture}
\end{document}

enter image description here

Thanks for your patience! Here is a version with a smaller handle. Happy bowling! ;-)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\path[tdplot_screen_coords,use as bounding box] (-3.2,-3.2) rectangle (4,4.5);
\pgfmathsetmacro{\R}{3}
\pgfmathsetmacro{\myang}{10} % controls the diameter of the handle
\pgfmathsetmacro{\angtop}{-80}
\pgfmathsetmacro{\angright}{95}
\pgfmathsetmacro{\out}{55}
\coordinate (O) at (0,0,0);
\shadedraw [ball color=red,tdplot_screen_coords] (0,0,0) circle(\R);
\path 
({\R*sin(\myang)*cos(\angtop)},{\R*sin(\myang)*sin(\angtop)},{\R*cos(\myang)}) 
coordinate (P2)
({\R*sin(\myang)*cos(\angright)},{-\R*sin(\myang)*sin(\angright)*cos(\out)+\R*cos(\myang)*sin(\out)},
{\R*cos(\myang)*cos(\out)+\R*sin(\myang)*sin(\angright)*sin(\out)}) 
coordinate (P1);
\draw[right color=white,left color=red!80!black,shading angle={-225+(90-\out)/2}] plot[variable=\x,domain=\angtop:\angtop+180,samples=91]
({3*sin(\myang)*cos(\x)},{3*sin(\myang)*sin(\x)},{3*cos(\myang)})
to[out=90,in=90-\out,looseness=1.5] (P1)
plot[variable=\x,domain=\angright:\angright-180,samples=91]
({\R*sin(\myang)*cos(\x)},{-\R*sin(\myang)*sin(\x)*cos(\out)+\R*cos(\myang)*sin(\out)},
{\R*cos(\myang)*cos(\out)+\R*sin(\myang)*sin(\x)*sin(\out)}) 
to[out=90-\out,in=90,looseness=2.2] (P2);
\end{tikzpicture}
\end{document}

enter image description here

One could make things a bit more funky...

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords,rotate=-45]
\path[tdplot_screen_coords,use as bounding box] (-3.2,-3.2) rectangle (4,4.5);
\pgfmathsetmacro{\R}{3}
\pgfmathsetmacro{\myang}{10} % controls the diameter of the handle
\pgfmathsetmacro{\angtop}{-80}
\pgfmathsetmacro{\angright}{95}
\pgfmathsetmacro{\out}{55}
\coordinate (O) at (0,0,0);
\shadedraw [ball color=red,tdplot_screen_coords] (0,0,0) circle(\R);
\path 
({\R*sin(\myang)*cos(\angtop)},{\R*sin(\myang)*sin(\angtop)},{\R*cos(\myang)}) 
coordinate (P2)
({\R*sin(\myang)*cos(\angright)},{-\R*sin(\myang)*sin(\angright)*cos(\out)+\R*cos(\myang)*sin(\out)},
{\R*cos(\myang)*cos(\out)+\R*sin(\myang)*sin(\angright)*sin(\out)}) 
coordinate (P1);
\draw[opacity=0.5,
right color=white,left color=red!80!black,shading angle={-225+(90-\out)/2}] 
plot[variable=\x,domain=\angtop:\angtop+180,samples=91]
({3*sin(\myang)*cos(\x)},{3*sin(\myang)*sin(\x)},{3*cos(\myang)})
to[out=90,in=90-\out,looseness=1.5] (P1)
plot[variable=\x,domain=\angright:\angright-180,samples=91]
({\R*sin(\myang)*cos(\x)},{-\R*sin(\myang)*sin(\x)*cos(\out)+\R*cos(\myang)*sin(\out)},
{\R*cos(\myang)*cos(\out)+\R*sin(\myang)*sin(\x)*sin(\out)}) 
to[out=90-\out,in=90,looseness=2.2] (P2);
\shadedraw [ball color=red,opacity=0.5]
plot[variable=\x,domain=\angtop:\angtop+180,samples=91]
({3*sin(\myang)*cos(\x)},{3*sin(\myang)*sin(\x)},{3*cos(\myang)})
to[out=90,in=90-\out,looseness=1.5] (P1)
plot[variable=\x,domain=\angright:\angright-180,samples=91]
({\R*sin(\myang)*cos(\x)},{-\R*sin(\myang)*sin(\x)*cos(\out)+\R*cos(\myang)*sin(\out)},
{\R*cos(\myang)*cos(\out)+\R*sin(\myang)*sin(\x)*sin(\out)}) 
to[out=90-\out,in=90,looseness=2.2] (P2);
\end{tikzpicture}
\end{document}

enter image description here

1
  • this is an awesome solution, thanky you. Do you think there is a way to shrink the handle a little?
    – Fra
    Nov 4, 2018 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .