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?

Gabriel
  • 867

2 Answers2

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

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

koleygr
  • 20,105