2

I want to use an angle (say a) in tikzpicture, which is calculated from other parameters:

\def\d{1}
\def\D{2}
\def\H{5}

a=90+0.5*asin(2(\D-\d)/\H)

This angle a I then use in a tikzpicture environment.

\begin{tikzpicture}

  \coordinate (c1) at (0,0);

  \coordinate (c2) at ($(c1)+(\H,0)$);

  \draw (c1) circle (\d/2);

  \draw (c2) circle (\D/2);

  \draw ($(c1)+(\d/2:a)$) to ($(c2)+(\D/2:a)$);

\end{tikzpicture}

How do I define this a?

2
  • (1) welcome, (2) as is custom on this site, you are much much more likely to get help if you take the time to create a full minimal example others can copy and test as is, instead of posting sniplets like this where others have to guess 50% before they can test your code. – daleif Feb 15 '19 at 12:52
  • Using \def is discouraged. You will realize why when your paper cites Erdős and you'll get a weird output. – egreg Feb 15 '19 at 14:38
4
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{calc}
\begin{document}

\def\d{1}
\def\D{2}
\def\H{5}

\begin{tikzpicture}
  \pgfmathsetmacro{\a}{90+0.5*asin(2*(\D-\d)/\H)}
  \coordinate (c1) at (0,0);
  \coordinate (c2) at ($(c1)+(\H,0)$);
  \draw (c1) circle (\d/2);
  \draw (c2) circle (\D/2);
  \draw ($(c1)+(\d/2:\a)$) to ($(c2)+(\D/2:\a)$);
\end{tikzpicture}

\end{document}

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.