# Make a TikZ picture automatic

I'm trying to make this picture in TikZ:

.

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) -- (T2);
\draw (0,0) -- (S2);

\end{tikzpicture}
\end{document}


that looks like

.

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?
• Also, the images are somewhat massive. How to resize them? – Kurzd Jan 9 '17 at 21:42
• 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. – John Kormylo Jan 9 '17 at 22:05
• What are the domains of variability of your four parameters? – Paul Gaborit Jan 9 '17 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 '17 at 23:04

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

\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}


• 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 '17 at 23:58
• @Kurzd To make the gif, I use convert (from ImageMagick): convert -delay 0 -density 120 doc.pdf doc.gif – Paul Gaborit Jan 10 '17 at 0:47

Not perfect solution ...

\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);


• Had no idea the border and tikz options existed. – Kurzd Jan 9 '17 at 23:36