3

I would like to draw a sphere with one handle as follows:
enter image description here

I have tried with the following code from Draw a sphere with a handle with TikZ, but this is different from my required image.

\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=gray!40,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=gray!80,shading angle=300] 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}

This produces:
enter image description here How can I draw the required figure which I want?

1
  • 2
    This answer contains both the code of which you say it is yours and versions with smaller handles.
    – user121799
    Apr 8 '19 at 14:39
5

This answer comes with three codes, the last of which is the most customizable one. I added two more (looseness) parameters, and playing with them allowed me to draw

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords,rotate=-60]
%\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}
\pgfmathsetmacro{\LooOne}{5.2}
\pgfmathsetmacro{\LooTwo}{4.2}
\coordinate (O) at (0,0,0);
\shadedraw [ball color=gray!40,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=gray!40!white,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=\LooOne] (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=\LooTwo] (P2);
\draw[dashed] plot[variable=\x,domain=\angtop:\angtop-180,samples=91]
({3*sin(\myang)*cos(\x)},{3*sin(\myang)*sin(\x)},{3*cos(\myang)})
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)});
\shadedraw [ball color=gray!50,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=\LooOne] (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=\LooTwo] (P2);
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    A dotted portion at the bottom of the handle is missing in this figure@marmot
    – MKS
    Apr 8 '19 at 15:30
  • 1
    @MKS I added them....
    – user121799
    Apr 8 '19 at 15:49
0

If you don't care much about the accuracy of the perspective, you can use some "hand made" code like this one:

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
  \begin{tikzpicture}[shading=ball, ball color=lightgray]
    % draw the sphere
    \draw[shade] circle(3);
    % draw the (half) ellipses
    \draw [dashed,rotate=70] (2.5,0)  coordinate(a1) {[xscale=.5] arc(-90:90:.4)} coordinate(a2);
    \draw [dashed,rotate=10] (2.5,0)  coordinate(b1) {[xscale=.5] arc(-90:90:.4)} coordinate(b2);
    % draw the handle
    \useasboundingbox (-3,-3) rectangle (5,5); % To keep the image size reasonable
    \draw[fill opacity=.5,shade]
      (a1) to[out=70,in=10,looseness=4.9] (b2)
      {[rotate=10,xscale=.5] arc(90:270:.4)}
      to[out=10,in=70,looseness=4.5] (a2)
      {[rotate=70,xscale=.5] arc(90:270:.4)} -- cycle;
  \end{tikzpicture}
\end{document}

enter image description here

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.