3

I want to build an epicyclic graph and found a useful trigonometric function on the web (URL is in comment in my MWE). My personal issue is that I can't write a complex function as a "plot" argument. I made several tries, mixing curved brackets, parenthesis and dollar, in various combinations (paying attention to pairs), it failed. The uncommented "plot" integrates sinus and cosinus and it works (indeed, it's just a small circle in the middle of the drawing). More complex - in comments - syntaxes fail and I don't understand why. I suspect that the function is handled by the PGF engine - not by TikZ - and that I'd mix the two syntaxes?

Any hint to have this working in a TikZ+LuaLaTeX environment? What are the parenthesis, curved brackets and dollar sign used for and in which combination?

\documentclass{article}
\usepackage{fontenc}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
% epicycle+deferent/epitrochoid - algorithm
% see http://www.malinc.se/math/trigonometry/spirographen.php
\def\ri{4}\def\re{1}\def\m{2} %radius internal-external, multiplicator
\draw [thick] (0,0) circle (\ri);
\foreach \a in {0,10,...,350} \draw (0,0)++(\a:\ri) circle (\re);
\draw[domain=0:360,smooth,samples=200,variable=\a] plot ({cos(\m*\a)},{sin(\m*\a)});
% \draw[domain=0:360,smooth,samples=200,variable=\a] plot ({$\ri*cos(\a)+\re*cos(\m*\a)$},{$\ri*sin(\a)+\re*sin(\m*\a)$});
% \draw[domain=0:360,smooth,samples=200,variable=\a] plot function {\ri*cos(\a)+\re*cos(\m*\a),\ri*sin(\a)+\re*sin(\m*\a)};
\end{tikzpicture} 
\end{document}
  • Very interesting :-) in Physics your question. – Sebastiano Feb 4 at 15:20
3

Remove the $ pair and it should work

\documentclass{article}
\usepackage{fontenc}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
% epicycle+deferent/epitrochoid - algorithm
% see http://www.malinc.se/math/trigonometry/spirographen.php
\def\ri{4}\def\re{1}\def\m{2} %radius internal-external, multiplicator
\draw [thick] (0,0) circle (\ri);
\foreach \a in {0,10,...,350} \draw (0,0)++(\a:\ri) circle (\re);
%\draw[domain=0:360,smooth,samples=200,variable=\a] plot ({cos(\m*\a)},{sin(\m*\a)});
\draw[domain=0:360,smooth,samples=200,variable=\a] plot ({\ri*cos(\a)+\re*cos(\m*\a)},{\ri*sin(\a)+\re*sin(\m*\a)});
%\draw[domain=0:360,smooth,samples=200,variable=\a] plot function {\ri*cos(\a)+\re*cos(\m*\a),\ri*sin(\a)+\re*sin(\m*\a)};
\end{tikzpicture} 
\end{document}
  • Indeed, you're right it works. It seems that my key issue here is that I still use TikzEdt to test my drawings and the software reports an error. To get the results I wanted, I adapted (the example is easily parametrable) the parameters to :\def \ri{4} \def \re{.5} \def \m{20} and this is what I was looking for. Thanks. – Eric Detienne Feb 4 at 14:08

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.