5

I drawed the following torus using Tikz:

\begin{tikzpicture}
\fill[blue] (7.5,0) ellipse (1 and .75);
\draw (7.5,0) ellipse (1 and .75);
\begin{scope}
  \clip (7.5,-.9) ellipse (1 and 1.25);
  \draw (7.5,1.1) ellipse (1 and 1.25);
\end{scope}
\begin{scope}
  \clip (7.5,1.1) ellipse (1 and 1.25);
  \draw (7.5,-1.1) ellipse (1 and 1.25);
\end{scope}
\end{tikzpicture}

I want to color the middle of it white, so it can really look like a torus. How could I do it?

  • Have you searched this site for tori? – Benjamin McKay Mar 24 at 11:46
  • @BenjaminMcKay Yes, I did. I think I viewed every post about tori here and not a single one solves my problem. – Gabriel Mar 24 at 11:46
  • You can check my (new) answer of the (old) question How to draw a torus. – Kpym Mar 31 at 16:31
4

An answer with some really minimal changes and no additional libraries:

\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\fill[blue] (7.5,0) ellipse (1 and .75);
\draw (7.5,0) ellipse (1 and .75);
\begin{scope}
  \clip (7.5,-.9) ellipse (1 and 1.25);
  \draw(7.5,1.1) ellipse (1 and 1.25);
  \clip (7.5,1.1) ellipse (1 and 1.25);
  \draw (7.5,-1.1) ellipse (1 and 1.25);
  \fill[white] (7.5,-1.1) ellipse (1 and 1.25);
\end{scope}
\end{tikzpicture}
\end{document}

An answer with fillbetweewn library (useful in many other cases):

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\fill[blue] (7.5,0) ellipse (1 and .75);
\draw (7.5,0) ellipse (1 and .75);
\begin{scope}
  \clip (7.5,-.9) ellipse (1 and 1.25);
  \path[draw,name path= A](7.5,1.1) ellipse (1 and 1.25);
  \clip (7.5,1.1) ellipse (1 and 1.25);
  \path[draw,name path=B] (7.5,-1.1) ellipse (1 and 1.25);
\fill [white,
          intersection segments={
            of=A and B,
            sequence={A1--B1}
          }];
\end{scope}
\end{tikzpicture}
\end{document}

Both answers output:

enter image description here

8

With even odd rule it is a two-liner. (I would strongly advise against filling some area white because if you use this on top of any background, you will regret it.)

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[fill=blue,even odd rule] (7.5,0) ellipse (1 and .75) 
 (7,0) arc(120:60:1 and 1.25) arc(-60:-120:1 and 1.25);
\draw (7,0) arc(-120:-130:1 and 1.25) (8,0) arc(-60:-50:1 and 1.25);
\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.