Torus with semi-dashed line in TikZ

1,595

As you may or may not have found out, tori are difficult to code precisely on a 2D surface (because it is a projection from 3D). In that spirit, I drew your picture as it is, just by trial and error, finding the right lengths. It's definitely not a clean way to do it, but I think it works for difficult pictures like this. No extra TikZ packages are needed. Here is the code:

\begin{tikzpicture}[rotate=180]
%Torus
\draw (0,0) ellipse (1.6 and .9);
%Hole
\begin{scope}[scale=.8]
\path[rounded corners=24pt] (-.9,0)--(0,.6)--(.9,0) (-.9,0)--(0,-.56)--(.9,0);
\draw[rounded corners=28pt] (-1.1,.1)--(0,-.6)--(1.1,.1);
\draw[rounded corners=24pt] (-.9,0)--(0,.6)--(.9,0);
\end{scope}
%Cut 1
\draw[densely dashed] (0,-.9) arc (270:90:.2 and .365);
\draw (0,-.9) arc (-90:90:.2 and .365);
%Cut 2
\draw (0,.9) arc (90:270:.2 and .348);
\draw[densely dashed] (0,.9) arc (90:-90:.2 and .348);
\end{tikzpicture}

This is the result:

enter image description here

Some things I am displeased with in my code:

  • I drew the hole with the lips going the other way before I realized you had it your way. So I just put [rotate=180] at the beginning instead of making the code appropriate. Just delete that to flip it back.

  • Initially the hole was too small, but it had kind of the right curvature. So I just scaled the whole hole until it looked better, hence the {scope}[scale=.8] part.

  • I think the two half-solid-half-dashed cuts should both be both going the same way, personal opinion. But it's your picture, so there you go. If you do want to do that, cut and paste [densely dotted] from one to the other lines of the same cut.

Conclusion: I have a bad (but visually OK) solution for a simple (but code-wise difficult) drawing.

Share:
1,595
jj_p
Author by

jj_p

Updated on January 24, 2020

Comments

  • jj_p
    jj_p almost 4 years

    Is there a simple way to produce in TikZ a two-torus rounded by two circles, each with the non-visible half dashed, as in the sketch?enter image description here

    • jub0bs
      jub0bs almost 10 years
      possible duplicate of Drawing the contour of a 3d torus
    • jub0bs
      jub0bs almost 10 years
      Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    • Charles Staats
      Charles Staats almost 10 years
      @Jubobs: I don't think it's a duplicate question. The question you link to has a similar image produced with tikz in the question itself, but the tikz code is not provided.
    • jub0bs
      jub0bs almost 10 years
      @CharlesStaats Well, this question is surely a duplicate of the one I link to, although the latter doesn't have a tikz answer.
    • jj_p
      jj_p almost 10 years
      Thanks. The question you link has an image similar to what I'd like to obtain, possibly using tikz, even though I can't find the code; another thing, the question refers to 2d vs 3d, but I'm not sure whether in my case this matters or not
    • Charles Staats
      Charles Staats almost 10 years
      @Jubobs: The question you link to is specifically about how to draw a contour torus with a 3d package (so that e.g. viewing angle is easy to change). This question is more nearly a duplicate of "How to draw a torus" (tex.stackexchange.com/q/348/484), but with the two circles added as an extra twist. It's also related to, but definitely not a duplicate of, "3D helix torus with hidden lines" (tex.stackexchange.com/q/70090/484).
    • jub0bs
      jub0bs almost 10 years
      @CharlesStaats Alright. I'll retract my close vote.
  • schmendrich
    schmendrich almost 10 years
    shoudn't it be this way: %Cut 2 \draw [densely dashed](0,.9) arc (90:270:.2 and .348); \draw (0,.9) arc (90:-90:.2 and .348); ? I think both circles have to look in the same direction? Correct me if I'm wrong.
  • jj_p
    jj_p almost 10 years
    Thanks for your answer. Yes, I came up with something very similar in the end, and yes, the dashed lines should look as you sugggest.