2

I'm trying to make this picture in TikZ:

Target image.

I wrote

\documentclass{standalone}
\usepackage{tikz}

\newcommand*{\rinn}{2}
\newcommand*{\rout}{3.8}
\newcommand*{\tangle}{37}
\newcommand*{\sangle}{-30}

\begin{document}
\begin{tikzpicture}
\coordinate [label=above:$T_1$]        (T1) at (\tangle:\rinn);
\coordinate [label=above right:$T_2$]  (T2) at (\tangle:\rout);
\coordinate [label=below right:$S_1$]  (S1) at (\sangle:\rinn);
\coordinate [label=below right:$S_2$]  (S2) at (\sangle:\rout);

\draw (0,0) circle [radius=\rinn];
\draw (0,0) circle [radius=\rout];

\draw (0,0) -- (T2);
\draw (0,0) -- (S2);

\end{tikzpicture}
\end{document}

that looks like

Output.

The image is automatic but the label position needs adjustment every time something is changed, and even then they're not well placed.

  • Is \newcommand the best way to define a variable for TikZ?
  • Is there a way to adjust the label position so that it always stays clear of the other lines?
9
  • Also, the images are somewhat massive. How to resize them?
    – Kurzd
    Jan 9, 2017 at 21:42
  • 1
  • 1
    If you put the labels into separate nodes you will have more flexibility in placement, but automating the placement would require some non-trivial logic. Jan 9, 2017 at 22:05
  • What are the domains of variability of your four parameters? Jan 9, 2017 at 22:52
  • @PaulGaborit The radii are big enough as they are. I thought it would be easy to have the angles take any value but they shouldn't have to go past 90 or -90.
    – Kurzd
    Jan 9, 2017 at 23:04

2 Answers 2

7

Here is a possible solution:

\documentclass[tikz]{standalone}
\begin{document}
\foreach {\tangle} in {80,79,...,10}{
  \pgfmathsetmacro{\sangle}{-\tangle}
  \begin{tikzpicture}[auto]
    % constants
    \def\rinn{2}
    \def\rout{3.8}

    % just to fix the global bounding box
    \path circle[radius=\rout cm+5mm+2em];

    \draw (0,0) circle [radius=\rinn];
    \draw (0,0) circle [radius=\rout];

    \coordinate (T1) at (\tangle:\rinn);
    \coordinate (T2) at (\tangle:\rout);
    \coordinate (S1) at (\sangle:\rinn);
    \coordinate (S2) at (\sangle:\rout);

    \draw (0,0) -- (T1) -- (T2);
    \draw (0,0) -- (S1) -- (S2);

    \path (T1) ++(\tangle+45:5mm) node{T1};
    \path (T2) ++(\tangle+45:5mm) node{T2};
    \path (S1) ++(\sangle-45:5mm) node{S1};
    \path (S2) ++(\sangle-45:5mm) node{S2};

  \end{tikzpicture}
}
\end{document}

enter image description here

3
  • That's way better than I originally expected. I compiled that, and got a 71-page document in qpdfview. How did you get that gif? You got a white border with \path circle[radius=\rout cm+5mm+2em]; instead of \documentclass[tikz,border=5mm+2em]{standalone}, and defined the radii with \def instead of \newcommand*. Are these personal preferences?
    – Kurzd
    Jan 9, 2017 at 23:58
  • 1
    @Kurzd My fake circle adds a constant bounding box (the border option enlarges the bounding box). With \def, I can define a local macro event if it is always defined. With \newcommand, you may use \renewcommand... Jan 10, 2017 at 0:45
  • 1
    @Kurzd To make the gif, I use convert (from ImageMagick): convert -delay 0 -density 120 doc.pdf doc.gif Jan 10, 2017 at 0:47
1

Not perfect solution ...

enter image description here

\documentclass[tikz,border=3mm]{standalone}
\usepackage{}

\newcommand*{\rinn}{2}
\newcommand*{\rout}{3.8}
\newcommand*{\tangle}{37}
\newcommand*{\sangle}{-30}

\begin{document}
\begin{tikzpicture}[auto]
\coordinate (T1) at (\tangle:\rinn);
\coordinate [label=\tangle:$T_2$]  (T2) at (\tangle:\rout);
\coordinate (S1) at (\sangle:\rinn);
\coordinate [label=\sangle:$S_2$]  (S2) at (\sangle:\rout);

\draw (0,0) circle [radius=\rinn];
\draw (0,0) circle [radius=\rout];

\draw (0,0) -- (T1) -- node[near start] {T1}  (T2);
\draw (0,0) -- (S1) -- node[near start] {S1}   (S2);

\end{tikzpicture}
\end{document}
1
  • Had no idea the border and tikz options existed.
    – Kurzd
    Jan 9, 2017 at 23:36

You must log in to answer this question.

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